delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/08/07:08:45

Message-ID: <005c01bf59b1$2d4763c0$1ac76ac6@almorgan>
From: "Al Morgan" <muaddib AT proaxis DOT com>
To: <djgpp AT delorie DOT com>
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
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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>if(x1 - x2 &lt;&nbsp;64 || y1 - y2 &lt; =

64)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; // stop =
moving.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>x1 - x2 figures out the distance =
between the=20
objects, and if it's less than 64, than stop moving.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Some notes:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>You should be using classes to store=20
things.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Make sure that the objects don't get =
stuck.&nbsp;=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:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>int dx =3D 0;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>int dy =3D 0;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>if(KEY_UP)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; dy =3D =
-1;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>if(KEY_DOWN)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; dy =3D =
1;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>if(KEY_LEFT)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; dx =3D =
-1;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>if(KEY_RIGHT)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; dx =3D =
1;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>if(legal_move(x + dx, y + =
dy))</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; {</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; x +=3D =
dx;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;</FONT><FONT =
face=3DArial=20
size=3D2>y +=3D dy;&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A href=3D"mailto:dannyg AT manistee-isd DOT k12 DOT mi DOT us"=20
  title=3Ddannyg AT manistee-isd DOT k12 DOT mi DOT us>Gosack</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Newsgroups:</B> =
comp.os.msdos.djgpp</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:djgpp AT delorie DOT com"=20
  title=3Ddjgpp AT delorie DOT com>djgpp AT delorie DOT com</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, January 07, 2000 =
9:39=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> newbie simple =
collision=20
  help!!!</DIV>
  <DIV><BR></DIV>
  <DIV><FONT color=3D#000000 size=3D2>Howdy,<BR>I'm a newbie game =
programmer. I was=20
  wondering if I could<BR>have some help with sprite =
collisions...<BR>basically=20
  x and y are positions for sprite one<BR>and naturally x2 and y2 are =
positions=20
  for sprite 2<BR>could somebody help me with the whole bounding box=20
  thing<BR>like just a little code or append to this code.<BR>I just =
want it so=20
  when the two sprites bump into each <BR>other they stop.&nbsp; The =
sprites I=20
  have are 64X64...pretty<BR>standard. I KNOW this is really simple I =
just don't=20
  know<BR>where to start.....<BR>any help would be GREATLY=20
  appreciated!!!!!<BR>THANKS!!!!!!!!!!<BR>// Control for Player =
1<BR>&nbsp;=20
  if(key[KEY_LEFT]&amp;&amp; x!=3D0)<BR>&nbsp;&nbsp; x++;<BR>&nbsp;=20
  if(key[KEY_RIGHT] &amp;&amp; x!=3D -575)<BR>&nbsp;&nbsp; =
x--;<BR>&nbsp;=20
  if(key[KEY_UP] &amp;&amp; y!=3D0)<BR>&nbsp;&nbsp; y++;<BR>&nbsp;=20
  if(key[KEY_DOWN] &amp;&amp; y!=3D-330)<BR>&nbsp;&nbsp; =
y--;<BR>&nbsp;&nbsp;=20
  </FONT></DIV>
  <DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT color=3D#000000 size=3D2>// Control for Player 2<BR>&nbsp;=20
  if(key[KEY_A] &amp;&amp; x2!=3D 0)<BR>&nbsp;&nbsp; x2++;<BR>&nbsp; =
if(key[KEY_D]=20
  &amp;&amp; x2 !=3D -575)<BR>&nbsp;&nbsp; x2--;<BR>&nbsp; if(key[KEY_W] =

  &amp;&amp; y2 !=3D 0)<BR>&nbsp;&nbsp; y2++;<BR>&nbsp; if(key[KEY_S] =
&amp;&amp;=20
  y2 !=3D -330)<BR>&nbsp;&nbsp; y2--;<BR>THANKS=20
AGAIN!!!<BR>Gosack</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0059_01BF596E.1CF29DC0--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019