So, I have a game and when you shoot an object it gets eliminated and adds 1 to the Counter but how do I add more Objects when said Counter reaches let's say 12.
import greenfoot.*;
// (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Space here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Space extends World
{
/**
* Constructor for objects of class Space.
*
*/
private int timer=3600;
Texto timerTexto;
public static int i = 0;
public static int counter = 0;
private Counter theCounter;
public static Spaceship x = new Spaceship(20.0, new Vector(0, 2.0));
private GreenfootSound bkgMusic;
/**
* Creates your Spaceship and 10 enemy ships (5 at each edge of the screen). A counter is placed in the bottom left-hand corner to show your score.
* The ship counter in the ship class is set to zero so that ships will be added when shot even after the scenario is reset (otherwise you would have
* to restart th e game from its file location to get more ships to appear on screen after they are shot).
*/
public Space()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(900, 580, 1);
timerTexto=new Texto("Tiempo:"+timer/60);
addObject(timerTexto,115,10);
theCounter = new Counter();
addObject(theCounter, 5, 5);
i = 0;
x.lives = 3;
x.setRotation(0);
addObject(x, 50, getHeight()/2);
int pos [][] = {{486,30},{557,70},{490,135},{554,161},{473,227},{575,255},{501,308},{566,359},{500,400},{566,450},{500,500},{566,550}};
for(int i=0;i<12;i++)
{
addObject(new Ship(),pos[i][0],pos[i][1]);
}
setActOrder(Fireball.class, Ship.class);
Ship.counter = 0;
bkgMusic=new GreenfootSound("sounds/Last summer.mp3");
bkgMusic.playLoop();
}
/**
* Constantly checks the ship class for whether the score should be incremented or not. Also checks to see if the game is over.
*/
public void act()
{
if(counter==12)
{
remakeShips();
}
timer--;
if(timer%60==0)
timerTexto.setTexto("Tiempo: "+timer/60);
if (timer==0)
{
timerTexto.setTexto("Se acabó el tiempo");
bkgMusic.stop();
GameOver go=new GameOver();
Greenfoot.setWorld(go);
}
}
/**
* Adds a number of points to the score counter.
*/
public static Spaceship returnShip()
{
return x;
}
public void remakeShips()
{
int pos [][] = {{486,30},{557,70},{490,135},{554,161},{473,227},{575,255},{501,308},{566,359}};
for(int i=0;i<8;i++)
{
addObject(new Ship2(),pos[i][0],pos[i][1]);
}
}
public Counter getCounter()
{
return theCounter;
}
public int getValue()
{
return counter;
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Counter here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Counter extends Actor
{
private int totalCount = 0;
public Counter()
{
setImage(new GreenfootImage("0", 20, Color.WHITE, Color.BLACK));
}
/**
* Increase the total amount displayed on the counter, by a given amount.
*/
public void bumpCount(int amount)
{
totalCount += amount;
setImage(new GreenfootImage("" + totalCount, 20, Color.WHITE, Color.BLACK));
}
}