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

2017/4/26

how to make my game faster

BrianOK BrianOK

2017/4/26

#
i've almost done my game but i want my run and jump to get faster over time... not sure how to do this but i need everything to speed up after every 10 seconds or so.
danpost danpost

2017/4/26

#
If you want everything to speed up, you can probably just use 'Greenfoot.setSpeed' in your world constructor to set the initial speed of the scenario using a value set to a int field (maybe starting at a value of 50). Then, in the world act method, you can increment (or increase) the value of that variable and use the same method call to speed everything up. An int field will also be needed to count out the ten seconds between speed changes.
BrianOK BrianOK

2017/4/26

#
danpost wrote...
If you want everything to speed up, you can probably just use 'Greenfoot.setSpeed' in your world constructor to set the initial speed of the scenario using a value set to a int field (maybe starting at a value of 50). Then, in the world act method, you can increment (or increase) the value of that variable and use the same method call to speed everything up. An int field will also be needed to count out the ten seconds between speed changes.
can you show me an example? i wouldnt know how to do this.
danpost danpost

2017/4/26

#
The basics are given here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class MyWorld extends World
{
    int timer;
    int speed = 50;
 
    public MyWorld()
    {
        super(600, 400, 1);
        Greenfoot.setSpeed(speed);
        prepare();
    }
 
    public void act()
    {
        timer++;
        if (timer == 600)
        {
            timer = 0;
            speed++;
            Greenfoot.setSpeed(speed);
        }
    }
The ten second gap will shorten as the speed increases; but that should not ruin the effect too much. I am guessing that the game will be lost within about 2 to 2.5 minute anyway. There is another way to do this, but is a bit more complicated. It involves tracking the location and speeds of everything in more precise units than in pixels (or cells). The world can hold a speed factor field that everything will use to keep in time with everything else as the speed increases. With this way, the ten second gap between speed changes will remain constant.
You need to login to post a reply.