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

2019/2/21

This piece of code does not work.

1
2
Notted Notted

2019/2/21

#
private void difficultyRising()
    {
       int numOfBombsRefB = ((MyWorld)getWorld()).getABucket().getNumOfBombs();
       GreenfootSound newDifficultySound = new GreenfootSound ("newlevel.wav"); 
        if (numOfBombsRefB == 25) // Mediuim
        {
           bomberSpeed = (int)Math.signum(bomberSpeed)*(3+numOfBombsRefB/25);
           bombSpawnTimer = (int)Math.signum(bombSpawnTimer)*(4+numOfBombsRefB/25);
           //newDifficultySound.play();
        }
        if (numOfBombsRefB == 50) // Hard
        {
           bomberSpeed = (int)Math.signum(bomberSpeed)*(4+numOfBombsRefB/25); 
           bombSpawnTimer = (int)Math.signum(bombSpawnTimer)*(4+numOfBombsRefB/25);
           //newDifficultySound.play();
        }
        if (numOfBombsRefB == 75) // Very Hard
        { 
            bombSpawnTimer = (int)Math.signum(bombSpawnTimer)*(4+numOfBombsRefB/25);
           //newDifficultySound.play();
        }
    }
Specifically it's this:
 bombSpawnTimer = (int)Math.signum(bombSpawnTimer)*(4+numOfBombsRefB/25);
Any variation of it causes the same problem. The bombSpawnTimer does not decrease anymore; it is stuck. While the bombers speed is increased, the bombSpawnTimer does not. It's static insted of dynamic. Is there anyway to fix this?
danpost danpost

2019/2/21

#
Notted wrote...
<< Code Omitted >> Specifically it's this: << Code Omitted >> Any variation of it causes the same problem. The bombSpawnTimer does not decrease anymore; it is stuck. While the bombers speed is increased, the bombSpawnTimer does not. It's static insted of dynamic. Is there anyway to fix this?
From what I can tell, the following should be sufficiently equivalent:
private void difficultyRising()
{
    int numOfBombsRefB = ((MyWorld)getWorld()).getABucket().getNumOfBombs();
    GreenfootSound newDifficultySound = new GreenfootSound ("newlevel.wav"); 
    bomberSpeed = (int)Math.signum(bomberSpeed)*(3+numOfBombsRefB/25);
    bombSpawnTimer = (int)Math.signum(bombSpawnTimer)*(4+numOfBombsRefB/25);
}
I get the feeling that the maximum timer value field should not be dependent on its sign and just should be subtracted from (to increase spawn rate).
Notted Notted

2019/2/22

#
bomberSpeed should not increase beyond a point; it causes bugs where the bomber man gets stuck on one edge of the screen (goToX is bigger than MyWorld's width) or will fidget around and get stuck (goToX changes schizophrenically)
danpost danpost

2019/2/22

#
if (Math.abs(bomberSpeed) < SOME_VALUE) bomberSpeed = (int)...
-- limiting the speed (adjust value as needed).
Notted Notted

2019/2/22

#
Still not working. bombSpawnTimer does not decrease. It's static.
danpost danpost

2019/2/22

#
Notted wrote...
Still not working. bombSpawnTimer does not decrease. It's static.
What is its initial value?
Notted Notted

2019/2/22

#
private int bombSpawnTimer = 80;
This is at the top of the bombSpawner class. it gets reset in the spawnBomb(); method.
danpost danpost

2019/2/22

#
Notted wrote...
private int bombSpawnTimer = 80;
This is at the top of the bombSpawner class. it gets reset in the spawnBomb(); method.
Show method.
Notted Notted

2019/2/22

#
Gladly:
private void spawnBomb()
    {
        bombSpawnTimer = bombSpawnTimer - 1;
        if (bombSpawnTimer < 0)
        {
        getWorld().addObject(new Bomb(), getX(), getY());
        bombSpawnTimer = 80;
        }
    }
danpost danpost

2019/2/22

#
Notted wrote...
Gladly: << Code Omitted >>
If you want to make the bombs spawn more quickly, you will need to make variable what you set bombSpawnTimer to.
Notted Notted

2019/2/22

#
danpost wrote...
Notted wrote...
Gladly: << Code Omitted >>
If you want to make the bombs spawn more quickly, you will need to make variable what you set bombSpawnTimer to.
I don't get what you mean. Do you mean that I have to create a new variable to track bombSpawnTimer? To do what?
danpost danpost

2019/2/22

#
Notted wrote...
I don't get what you mean. Do you mean that I have to create a new variable to track bombSpawnTimer? To do what?
No. You need a new variable to set bombSpawnTimer to (instead on always '80').
Notted Notted

2019/2/22

#
I don't know what that would look like. bombSpawnTimer now no longer has an initialized value, but only drops one bomb. I need it continually keep dropping bombs.
danpost danpost

2019/2/22

#
Notted wrote...
I don't know what that would look like. bombSpawnTimer now no longer has an initialized value, but only drops one bomb. I need it continually keep dropping bombs.
What do you mean that it "no longer has an initialized value"?
Notted Notted

2019/2/22

#
bombSpawnTimer is no longer set equal to 80. It's now empty.
There are more replies on the next page.
1
2