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
danpost danpost

2019/2/22

#
Notted wrote...
bombSpawnTimer is no longer set equal to 80. It's now empty.
"empty"? Show latest codes.
Notted Notted

2019/2/25

#
private int bombSpawnTimer;
 private int bombSpawnTimerSetter;
danpost danpost

2019/2/25

#
Notted wrote...
<< Code Omitted >>
Insufficient amount of code given.
Notted Notted

2019/2/26

#
private int bombSpawnTimer;
    private int bombSpawnTimerSetter;


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

private void difficultyRising()
    {
        int width = getWorld().getWidth();
       int numOfBombsRefB = ((MyWorld)getWorld()).getABucket().getNumOfBombs();
       GreenfootSound newDifficultySound = new GreenfootSound ("newlevel.wav");  
       if (Math.abs(bomberSpeed) < width) bomberSpeed = (int)Math.signum(bomberSpeed)*(3+numOfBombsRefB/25);
       bombSpawnTimer = (int)Math.signum(bombSpawnTimer)*(4-numOfBombsRefB/25);
    }
Zestix Zestix

2019/2/26

#
Notted wrote...
private int bombSpawnTimer;
    private int bombSpawnTimerSetter;


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

private void difficultyRising()
    {
        int width = getWorld().getWidth();
       int numOfBombsRefB = ((MyWorld)getWorld()).getABucket().getNumOfBombs();
       GreenfootSound newDifficultySound = new GreenfootSound ("newlevel.wav");  
       if (Math.abs(bomberSpeed) < width) bomberSpeed = (int)Math.signum(bomberSpeed)*(3+numOfBombsRefB/25);
       bombSpawnTimer = (int)Math.signum(bombSpawnTimer)*(4-numOfBombsRefB/25);
    }
The thing is it can't work in Line 7 it is decreasing but right after that (Line 8) you just set it back to 80 that way the number switches from 80 to 79 and back all the time Change Line 1 to private int bombSpawnTimer = 80; and remove line 8. Right behind line 11 you can set the timer to 80 again
danpost danpost

2019/2/26

#
Sorry, Zestix, but you missed out on some previously posted stuff. What you suggest is actually a regression. What actually needs done is to set line 2 equal to 80, next switch the first two lines and then set the new line 2 equal to bombSpawnTimerSetter. Zestix is correct that line 8 needs removed, however after line 11, bombSpawnTimer should be set to bombSpawnTimerSetter, not 80. This will allow the setter field to be reduced to speed up the spawning of bombs (in difficultyRising).
Zestix Zestix

2019/2/26

#
danpost wrote...
Sorry, Zestix, but you missed out on some previously posted stuff. What you suggest is actually a regression. What actually needs done is to set line 2 equal to 80, next switch the first two lines and then set the new line 2 equal to bombSpawnTimerSetter. Zestix is correct that line 8 needs removed, however after line 11, bombSpawnTimer should be set to bombSpawnTimerSetter, not 80. This will allow the setter field to be reduced to speed up the spawning of bombs (in difficultyRising).
I guess I was a little hasty wasn't I
danpost danpost

2019/2/26

#
Zestix wrote...
I guess I was a little hasty wasn't I
That is alright. Sometimes it is quite difficult to decipher what the current issue is. Oftentimes, I have to go back through the posts to figure it out myself. It it really bad when a whole lot of changes were done, only to find they had to be undone to correct the real issue.
Notted Notted

2019/2/27

#
It's still not working. I get where you are coming from, however. bombSpawnTimer is how much it decreases by. bombSpawnTimerSetter is now how much time there is in between. But the bombSpawnTimerSetter is not get reduced by the bombSpawnTimer (in the code it would like bombSpawnTimerSetter = bombSpawnTimerSetter - bombSpawnTimer;). Would I put that in the difficultyRising() or the spawnBomb() method?
Notted Notted

2019/2/27

#
This code seems to work:
private int bombSpawnTimerSetter = 80;
    private int bombSpawnTimer = bombSpawnTimerSetter;
    private int bomberSpeed = 2;
    private int gotoY = 96;
    private int gotoX = 540;
    public void act() 
    {
        spawnBomb();
        movingBomber();
        difficultyRising();
        
    }  
    private void spawnBomb()
    {
        bombSpawnTimerSetter = bombSpawnTimerSetter - 1;
        if (bombSpawnTimerSetter < 0)
        {
        getWorld().addObject(new Bomb(), getX(), getY());
        bombSpawnTimerSetter = 80;
        }
    }
    private void movingBomber()
    {
        
        move(bomberSpeed);
        if ((getX()-gotoX >= 0 && bomberSpeed > 0) || (getX()-gotoX <= 0 && bomberSpeed < 0))
        {
            bomberSpeed = -bomberSpeed;
            int width = getWorld().getWidth();
            gotoX = width/2+(50+Greenfoot.getRandomNumber(width/2-80))*bomberSpeed/4;
        }
    }
    private void difficultyRising()
    {
       int width = getWorld().getWidth();
       int numOfBombsRefB = ((MyWorld)getWorld()).getABucket().getNumOfBombs();
       GreenfootSound newDifficultySound = new GreenfootSound ("newlevel.wav");  
       if (Math.abs(bomberSpeed) < width) bomberSpeed = (int)Math.signum(bomberSpeed)*(3+numOfBombsRefB/25);
       bombSpawnTimer = (int)Math.signum(bombSpawnTimer)*(4-numOfBombsRefB/25);
       //bombSpawnTimerSetter = bombSpawnTimerSetter - bombSpawnTimer;
    }
}
I'm still not sure if bombSpawnTimerSetter = bombSpawnTimerSetter - bombSpawnTimer would work as intended. bombSpawnTimer is basicly there for the reduction bit; it's how fast the bombs are being dropped. Edit: Tweaking the first number in
(int)Math.signum(bombSpawnTimer)*(0+numOfBombsRefB/25);
increases the rate of the bomb drops. It seems to be the one that increases the rate at which the bombs are dropped.
danpost danpost

2019/2/27

#
You are confusing the use of your fields. The spawnBomb method should only use bombSpawnTimer except at the end where it should set bombSpawnTimer to bombSpawnTimerSetter. The difficultyRising method should only deal with bombSpawnTimerSetter, reducing its value to increase the bomb spawn rate.
You need to login to post a reply.
1
2