Message-ID: <005c01bf59b1$2d4763c0$1ac76ac6@almorgan> From: "Al Morgan" To: References: <001001bf599a$cefd36c0$11bab0c7 AT oemcomputer> Subject: Re: newbie simple collision help!!! Date: Sat, 8 Jan 2000 00:20:05 -0800 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0059_01BF596E.1CF29DC0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Reply-To: djgpp AT delorie DOT com This is a multi-part message in MIME format. ------=_NextPart_000_0059_01BF596E.1CF29DC0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable if(x1 - x2 < 64 || y1 - y2 < 64) // stop moving. x1 - x2 figures out the distance between the objects, and if it's less = than 64, than stop moving. Some notes: You should be using classes to store things. Make sure that the objects don't get stuck. If you're not careful about = your code, the objects will touch, then the code will stop letting them = move (even away from eachother), here's how I solve that problem: int dx =3D 0; int dy =3D 0; if(KEY_UP) dy =3D -1; if(KEY_DOWN) dy =3D 1; if(KEY_LEFT) dx =3D -1; if(KEY_RIGHT) dx =3D 1; if(legal_move(x + dx, y + dy)) { x +=3D dx; y +=3D dy; =20 } ----- Original Message -----=20 From: Gosack=20 Newsgroups: comp.os.msdos.djgpp To: djgpp AT delorie DOT com=20 Sent: Friday, January 07, 2000 9:39 PM Subject: newbie simple collision help!!! Howdy, I'm a newbie game programmer. I was wondering if I could have some help with sprite collisions... basically x and y are positions for sprite one and naturally x2 and y2 are positions for sprite 2 could somebody help me with the whole bounding box thing like just a little code or append to this code. I just want it so when the two sprites bump into each=20 other they stop. The sprites I have are 64X64...pretty standard. I KNOW this is really simple I just don't know where to start..... any help would be GREATLY appreciated!!!!! THANKS!!!!!!!!!! // Control for Player 1 if(key[KEY_LEFT]&& x!=3D0) x++; if(key[KEY_RIGHT] && x!=3D -575) x--; if(key[KEY_UP] && y!=3D0) y++; if(key[KEY_DOWN] && y!=3D-330) y--; =20 =20 // Control for Player 2 if(key[KEY_A] && x2!=3D 0) x2++; if(key[KEY_D] && x2 !=3D -575) x2--; if(key[KEY_W] && y2 !=3D 0) y2++; if(key[KEY_S] && y2 !=3D -330) y2--; THANKS AGAIN!!! Gosack ------=_NextPart_000_0059_01BF596E.1CF29DC0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
if(x1 - x2 < 64 || y1 - y2 < = 64)
    // stop = moving.
 
x1 - x2 figures out the distance = between the=20 objects, and if it's less than 64, than stop moving.
 
Some notes:
You should be using classes to store=20 things.
 
Make sure that the objects don't get = stuck. =20 If you're not careful about your code, the objects will touch, then the = code=20 will stop letting them move (even away from eachother), here's how I = solve that=20 problem:
 
int dx =3D 0;
int dy =3D 0;
 
if(KEY_UP)
    dy =3D = -1;
if(KEY_DOWN)
    dy =3D = 1;
if(KEY_LEFT)
    dx =3D = -1;
if(KEY_RIGHT)
    dx =3D = 1;
 
if(legal_move(x + dx, y + = dy))
    {
    x +=3D = dx;
    y +=3D dy;   
    }
----- Original Message -----
From:=20 Gosack
Newsgroups: = comp.os.msdos.djgpp
To: djgpp AT delorie DOT com
Sent: Friday, January 07, 2000 = 9:39=20 PM
Subject: newbie simple = collision=20 help!!!

Howdy,
I'm a newbie game = programmer. I was=20 wondering if I could
have some help with sprite = collisions...
basically=20 x and y are positions for sprite one
and naturally x2 and y2 are = positions=20 for sprite 2
could somebody help me with the whole bounding box=20 thing
like just a little code or append to this code.
I just = want it so=20 when the two sprites bump into each
other they stop.  The = sprites I=20 have are 64X64...pretty
standard. I KNOW this is really simple I = just don't=20 know
where to start.....
any help would be GREATLY=20 appreciated!!!!!
THANKS!!!!!!!!!!
// Control for Player = 1
 =20 if(key[KEY_LEFT]&& x!=3D0)
   x++;
 =20 if(key[KEY_RIGHT] && x!=3D -575)
   = x--;
 =20 if(key[KEY_UP] && y!=3D0)
   y++;
 =20 if(key[KEY_DOWN] && y!=3D-330)
   = y--;
  =20
 
// Control for Player 2
 =20 if(key[KEY_A] && x2!=3D 0)
   x2++;
  = if(key[KEY_D]=20 && x2 !=3D -575)
   x2--;
  if(key[KEY_W] = && y2 !=3D 0)
   y2++;
  if(key[KEY_S] = &&=20 y2 !=3D -330)
   y2--;
THANKS=20 AGAIN!!!
Gosack
------=_NextPart_000_0059_01BF596E.1CF29DC0--