Hey i am making a game that you are a spaceship and enemys are falling on you so far i have made the spaceship shoot and the
enemy falling fron the top of the screen (i have already made that if the bullet hits the enemy you get points)
but i have one problem that im stuck on for 2 days already the problem is to detect spaceship and enemy hit (they hit each other)
when they hitting each other it works but also when they far away from each other..
the code of the hit check is
it checks if enemy 0 hitted the spaceship
iwidth is the enemy bitmap width
iheight is enemy bitmap height
pwidth is spaceship bitmap width
pheight is spaceship bitmap height
this.x and this.y is spaceship x and y
invaders.getx0 and invaders.gety0 is the enemy x and y
and invaders.setbitmap() is to set the life
please help me thanks
enemy falling fron the top of the screen (i have already made that if the bullet hits the enemy you get points)
but i have one problem that im stuck on for 2 days already the problem is to detect spaceship and enemy hit (they hit each other)
when they hitting each other it works but also when they far away from each other..
the code of the hit check is
Code:
if(invaders.getx0()-(iwidth/2)>=this.x-(pwidth/2)&&invaders.getx0()+iwidth<=this.x+pwidth&&invaders.gety0()+iheight>this.y&&invaders.gety0()<=this.y)
{
invaders.setbitmap(1);
}
iwidth is the enemy bitmap width
iheight is enemy bitmap height
pwidth is spaceship bitmap width
pheight is spaceship bitmap height
this.x and this.y is spaceship x and y
invaders.getx0 and invaders.gety0 is the enemy x and y
and invaders.setbitmap() is to set the life
please help me thanks