I am trying to make a game where you avoid lazer beams and collect gems, but once the player collects the second gem, the gem doesn't disappear. I don't know what does this so could someone please help me.
Here is the code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Gem here.
*
* @author (h123n)
* @version (0.1 BETA)
*/
public class Gem extends Actor
{
private int gems = 0;
/**
* Act - do whatever the Gem wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
//See if our gem has been stolen ;(
Actor penguinDave;
penguinDave = getOneObjectAtOffset(0,0, PenguinDave.class);
if (penguinDave != null)
{
World world;
world = getWorld();
world.removeObject(this);
gems++;
if (gems == 1)
{
world.addObject(new Lazer(), 100,400);
world.addObject(new Gem(), 50,200);
}
if (gems == 2)
{
world.addObject(new Lazer(), 350,400);
}
}
}
}