http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 2d game problem




     You'd use bounding boxes for the character.  Basically, it's a box that 
encompasses the whole character.  Then when it comes time to check the 
collisions against the other players, you'd do something like this:

X1,Y1 is the first box's lower left and upper right corners.
X2,Y2 is the second box's lower left and upper right corners.

if(X1 >= X2 && X1 <= X2)
{
     if(Y1 >= Y2 && Y1 <= Y2
     {
        We have a collision if we're here.
     }
}

    Also, we need to check the boxes against each other in the other way... 
to make sure we didn't miss anything like this

else if(X2 >= X1 && X2 <= X1)
{
     if(Y2 >= Y1 && Y2 <= Y1
     {
        We have a collision if we're here.
     }
}

     This works for the character to character collisions, but you probably 
also want to do collisions against the ground with all kinds of hills and 
everything.  That would take quite awhile, though, so I'm not going to do it 
here.  Anyways, there's lots of tutorials on collision detection on the web, 
I just wrote one the other day even 
(http://shockonline.homestead.com/openglgameprogramming.html).  Also check 
out Flipcode and GameDev.






>From: "Frank Cleynen" <frankcleynen@freegates.be>
>Reply-To: gameprogrammer@gameprogrammer.com
>To: <gameprogrammer@gameprogrammer.com>
>Subject: 2d game problem
>Date: Fri, 14 Jul 2000 19:35:52 +0200
>
>Default Outlook Express Briefpapier.Hey!!
>My problem: I'm still working on a 2D game and my question is: how can I 
>program that my maincharackter doesn't walk trough houses, trees, other 
>charackters and objects???
>
>Bye and thanks!!

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCꫨ please visit:
http://gameprogrammer.com/mailinglist.html