I already only have the counter on the background, but I don't know how to create my game where the shooter only shoots out one bullet at a time to hit an enemy where the Counter goes up by one. I also want where if the enemy gets passed the actual shooter the game ends. How do I do this?
This is the bullet code:
This is the background code:
Ask me if you need anymore class codes. Thanks
import greenfoot.*;
/**
* Write a description of class bullet here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class bullet extends Actor
{
/**
* 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()
{
destroyEnemies ();
}
public void hitanenemy()
{
background backgroundWorld = (background) getWorld(); // get a reference to the world
Counter counter = backgroundWorld.getCounter(); // get a reference to the counter counter.bumpCount(5);
}
public void destroyEnemies()
{
Actor enemy = getOneIntersectingObject(enemy.class);
if(enemy != null)
{
World myWorld = getWorld();
getWorld().removeObject(enemy);
Counter.addScore();
if (this.atWorldEdge()) {
getWorld().removeObject(this);
}
}
}
public void kill()
{
Actor enemy = getOneIntersectingObject(enemy.class);
if(enemy != null)
{
getWorld().removeObject(enemy);
}
}
}import greenfoot.*;
/**
* Write a description of class background here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class background extends World
{
private int score;
private int bulletInPlay;
private Counter theCounter;
public background()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
score=0;
prepare();
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void prepare()
{
shooter shooter = new shooter();
addObject(shooter, 310, 349);
theCounter = new Counter();
addObject(theCounter, 540, 20);
}
public Counter getCounter()
{
return theCounter;
}
}


