Hello..
I am fairly new with Greenfoot, and after some hours of trying to make a zombie survival game two problems occured.
First my world stops when a bullet leaves the edge of the world.
Second problem is that nothing seems to happen, when my bullet hits zombie?
I hope someone can help me out there..
Here's my coding:
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 Actor
{
private boolean getAngle = true;
private int shootingCounter = 150;
/**
* 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()
{
angleSelect();
move(10);
shootingCounter--;
remove();
killZombie();
}
public void remove()
{
if(getX() >= getWorld().getWidth() -10)
getWorld().removeObject(this);
else if(getX() <= 5)
getWorld().removeObject(this);
else if(getX() >= getWorld().getWidth() -10)
getWorld().removeObject(this);
else if(getX() <= 10)
getWorld().removeObject(this);
}
public void angleSelect()
{
if(getAngle == true)
{
setRotation(Sniperguy.currentRot);
getAngle = false;
}
}
public boolean amIshot(Class clss)
{
Actor actor = getOneObjectAtOffset(0,0, clss);
return actor !=null;
}
public void kill (Class clss)
{
Actor actor = getOneObjectAtOffset(0,0, clss);
if(actor !=null)
{
getWorld().removeObject(actor);
}
}
public void killZombie()
{
if(amIshot(zombie.class))
{
kill(zombie.class);
getWorld().removeObject(this);
}
else
{
remove();
}
}
}

