Hello again, I was finally able to fix the issue with my bullet only firing to the right! but now I am having trouble with the checkinng boundaries. I added code to make the bullet disappears once it gets to the edge of the map, but when it reaches the end of the map the game freezes and gives me an error... Does sommebody know what I can do to fix this?
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.0);
checkBoundaries();
destroyEnemies();
}
//we add a method "checkBoundaries()" that destroys bullets that are off screen.
public void checkBoundaries()
{
if(getY()>555||getX()>555 ||getY()<5||getX()<5 ) {
getWorld().removeObject(this);
}
}
//"destroyEnemies()" destroys enemies.
public void destroyEnemies()
{
//"Enemy" can be any class that you want the bullet to destroy.
Actor enemy = getOneIntersectingObject(Vijand .class);
if(enemy != null) {
getWorld().removeObject(enemy);
getWorld().removeObject(this);
}
}
}
