I am currently using this code for 2D Collision Detection in my Space Invaders like game :
for(byte k = 0; k < enemies.length; k++) {
if(shot.x < enemies[k].getTexture().getImageWidth() && shot.x > enemies[k].pos.x) {
if(shot.y - 1.2f * frameCount < enemies[k].pos.y && shot.y - 1.2f * frameCount > Main.enemies[k].pos.y - enemies[k].getTexture().getTextureHeight()) {
Main.enemies[k].hit = true;
}
}
}
However, there is one major flaw in this type of collision detection; I can only detect collisions coming form below. Why is this?