DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   java 2d games problem (collision, well prevention) (http://www.daniweb.com/forums/thread26273.html)

ultimate_fusion Jun 21st, 2005 12:04 pm
java 2d games problem (collision, well prevention)
 
I am starting to make some java games and I think i have sorted out the collision side of things ( i have made a space invaders game) so i know how to shoot and kill enemies. I am now wanting to stop players/monsters going through walls etc?

p.s. what is the best way to do walls? (just paint() them)

thanks for you help

Phaelax Jun 21st, 2005 6:18 pm
Re: java 2d games problem (collision, well prevention)
 
If you just have simple, axis-aligned walls, then just compare the distance between the enemy and wall with the size of the enemy. If the distance becomes less, then it has hit the wall. After that, just reverse the direction of the enemy. That's the most simple of collision methods. Others involve swept collisions, which work regardless of an object's speed.

ultimate_fusion Jun 22nd, 2005 5:54 am
Re: java 2d games problem (collision, well prevention)
 
problem solved
just stored the values like
GTC[0]=x;
GTC[1]=y;
before the collsion and where it collides
if (a instanceof Monster ) {
x = GTC[0];
y = GTC[1];
}


All times are GMT -4. The time now is 4:03 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC