This site requires JavaScript, please enable it in your browser!
Greenfoot back
Leenza
Leenza wrote ...

2015/4/1

HELP

Leenza Leenza

2015/4/1

#
I have powerups in my game (they increase the speed of the player). I have the following code to remove them after the first 10 seconds.
if (GameWorld1.PowerUpTimer.millisElapsed() > 10000)
        {
           getWorld().removeObject(this);
           PowerUpTimer.mark();
        }
However, I want the powerups to reappear in level 2. I have the following code in GameWorld2 (level 2) to put the powerups on the screen, but it won't work
for (int x = 0; x < numPowerUps; x++)
        {
            xPos = Greenfoot.getRandomNumber(getWidth());
            yPos = Greenfoot.getRandomNumber(getHeight());
            addObject(new PowerUp(), xPos, yPos);
        }
I do have all the variables and other things defined elsewhere (like above i have public static int numPowerUps = 4; for example)
danpost danpost

2015/4/1

#
What does the rest of the PowerUp class look like?
Leenza Leenza

2015/4/1

#
That is all that is in the powerup class. If you are looking for the code that increases the speed and where the hero collects them, that is is the hero class and it looks like this:
 public void lookForPowerUp()
    {
        if (canSee(PowerUp.class))
        {
            eat(PowerUp.class);
            PlayerSpeed++;
        }
    }
danpost danpost

2015/4/2

#
Leenza wrote...
That is all that is in the powerup class.
Then that is your problem. The code that times it and removes it should be in that class.
You need to login to post a reply.