Hi all,
I'm learning how to program Java Applet games at the moment, and I'm currently making a simple Space-Invaders type game. I'm having trouble with finding help for how to program collision detection, though, as most tutorials just instruct you to use a pre-made library (which I don't really want to do).
The routine I have at the moment is as follows:
//Position of ship
int x_pos;
int y_pos;
//Stats of ship
private int height = 40;
private int width = 40;
public boolean collision(int posX, int posY){
if (posX >= x_pos && posX <= x_pos + width && posY >= y_pos && posY <= y_pos + height){
return true;
}
else{
return false;
}
}
This works by taking an X,Y point (posX, posY) and testing whether or not it falls into the ships 'collision range', however it only works for a single pixel and seems like it will get clumsy and hard to use if I wanted to test, for example, one ship colliding with another.
Any ideas?
Thanks.