Hi,
I am not good at programming and I have problem when I insert code with kill method, then when bullet reach the edge of the map error views.
Msg error is here and code too.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Bullet here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bullet extends Mover
{
/**
* Act - do whatever the Bullet wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(10);
remove();
kill();
}
public void remove() {
if(getX() >= getWorld().getWidth() -1)
getWorld().removeObject(this);
else if(getX() <= 1)
getWorld().removeObject(this);
else if(getY() >= getWorld().getWidth() -1)
getWorld().removeObject(this);
else if(getY() <= 1)
getWorld().removeObject(this);
}
public void kill()
{
Actor p2 = getOneIntersectingObject(Player2.class);
if (p2 != null) {
getWorld().removeObject(p2);
}
}
}
