my player (motny) shoots to the right and it could either hit a rock/an alien but if it doesn't hit anything, it would get stuck at the right side of the screen. Could anyone help me solve this problem? What do I need to add/do?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* A bullet to be shot at rocks and aliens
*/
public class Shot extends Actor
{
private motny myShip;
/**
* Constructor for a Shot. You must specify the ship the shot comes from.
*/
public Shot(motny myShip)
{
this.myShip = myShip;
}
/**
* Act - do whatever the Shot wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
int ypos = getY();
int xpos=getX();
if (xpos > 0){
xpos = xpos + 5;
setLocation(xpos, ypos);
Actor rock = getOneIntersectingObject(rock.class);
Actor alien = getOneIntersectingObject(alien.class);
if (rock != null) {
// hits a rock
getWorld().removeObject(rock);
getWorld().removeObject(this);
}
if (alien != null) {
//hits an alien
getWorld().removeObject(alien);
getWorld().removeObject(this);
}
}
}
}