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

Recommended Answers

All 2 Replies

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.

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];
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.