I've only started programming a week ago so I'm still pretty much a noob. rn I'm making a game similar to galaxy attack, where you shoot alien ships (how simple). I'm trying to make the aliens die after 3 shots of the laser, but I can't really figure how to do it. I've tried all the ideas that might work but they never did. Whenever the laser hits the alien, the laser disappears like I programmed it to but the aliens don't take damage. This is my code for the laser.
and this is my code for the aliens.
public void act()
{
setLocation(getX(), getY()-10);
Actor monster;
monster = getOneObjectAtOffset(0,-20, monsters.class);
if (isAtEdge()|| monster!=null)
{
getWorld().removeObject(this);
}
}public void collisionWithLaser()
{
hp = hp - 50;
Greenfoot.delay(1);
}
public void act()
{
Actor laser;
if (getOneObjectAtOffset(0,25,laser.class)!=null)
{
collisionWithLaser();
}
if (hp <= 0)
{
getWorld().removeObject(this);
}
}
