944,171 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3861
  • Java RSS
Jun 21st, 2005
0

java 2d games problem (collision, well prevention)

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
ultimate_fusion is offline Offline
44 posts
since Oct 2004
Jun 21st, 2005
0

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.
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
Jun 22nd, 2005
0

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];
}
Reputation Points: 10
Solved Threads: 0
Light Poster
ultimate_fusion is offline Offline
44 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Arrays
Next Thread in Java Forum Timeline: help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC