Hello, I've changed my code slightly and now it dosen't work again.
I've done as you said however changed the totalCount to 4, as I want it only to show the picture when 4 'invaders' have been shot. This dosen't happen however, and the game just continues playing without showing the image.
Here is the code for my counter:
And here is my code for the bullet:
Thanks all for your help so far :)
public class Counter extends Actor
{
/**
* Act - do whatever the Counter wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
int totalCount = 0;
public void bumpCount()
{
totalCount = totalCount+ 1;
}
public void act()
{
World world;
world = getWorld();
if (totalCount == 4 && world.getObjects(GameWon.class).isEmpty())
{
GameWon gw;
gw = new GameWon();
world.addObject(gw, 450, 300);
}
}
}public class Bullet extends Rocket
{
/**
* 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()
{
// Add your action code here.
setLocation(getX() + 30, getY() );
Actor Creepinginvader;
Creepinginvader = getOneObjectAtOffset(0,0,Invader.class);
if (Creepinginvader!=null)
{
World world;
world = getWorld();
world.removeObject(Creepinginvader);
world.removeObject(this);
return;
}
//this is the part I'm using to trigger the counter:
if (Creepinginvader!=null)
{
spaceinvaders spaceWorld = (spaceinvaders) getWorld();
Counter counter = spaceWorld.getCounter();
counter.bumpCount();
}
Actor spasmInvader;
spasmInvader = getOneObjectAtOffset(0,0,Invader.class);
if (spasmInvader!=null)
{
World world;
world = getWorld();
world.removeObject(spasmInvader);
world.removeObject(this);
return;
}
if (spasmInvader!=null)
{
spaceinvaders spaceWorld = (spaceinvaders) getWorld();
Counter counter = spaceWorld.getCounter();
counter.bumpCount();
}
Actor ZigZagInvader;
ZigZagInvader = getOneObjectAtOffset(0,0,Invader.class);
if (ZigZagInvader!=null)
{
World world;
world = getWorld();
world.removeObject(spasmInvader);
world.removeObject(this);
return;
}
if (ZigZagInvader!=null)
{
spaceinvaders spaceWorld = (spaceinvaders) getWorld();
Counter counter = spaceWorld.getCounter();
counter.bumpCount();
}
Actor CustomInvader;
CustomInvader = getOneObjectAtOffset(0,0,Invader.class);
if (CustomInvader!=null)
{
World world;
world = getWorld();
world.removeObject(CustomInvader);
world.removeObject(this);
return;
}
if (CustomInvader!=null)
{
spaceinvaders spaceWorld = (spaceinvaders) getWorld();
Counter counter = spaceWorld.getCounter();
counter.bumpCount();
}
if (this.atWorldEdge()==true)
{
World world;
world = getWorld();
world.removeObject(this);
return;
}
}
public boolean atWorldEdge()
{
if (getX() > getWorld().getWidth() - getImage().getWidth() || getY() > getWorld().getHeight() - getImage().getHeight())
{
return true;
}
else
{
return false;
}
}
}


