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

2019/5/27

I'm having trouble keeping the same score across different levels

1
2
3
AmyIsBadAtCoding AmyIsBadAtCoding

2019/5/28

#
This is my code. The reason why I have been using this thread because I've genuinely been told off for making different threads when others have similar issues by who I think was a mod lmao. Here's my code, this has the change world code in:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import greenfoot.*;
 
/**
 * Write a description of class Plane here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Plane extends Actor
{
/**
 * shrinking plane size
 */
    public Plane()
    {
     GreenfootImage image = getImage();
        image.scale(image.getWidth() - 60, image.getHeight() - 60);
        setImage(image);
        }
     
    
    private Counter counter;
/**
 * adding up-down controlls and if the actor touches the right side they will go to a random world
 */
    public void act()
    {
     
        {
            setRotation(0);
            move(2);
    }
        if (Greenfoot.isKeyDown("Up"))
    {
            setRotation(-20);
            move(2);
    }
    if (Greenfoot.isKeyDown("Down"))
    {
        setRotation(50);
            move(2);
        }
    if (getX() == getWorld().getWidth()-1)
    {
        if (Greenfoot.getRandomNumber(3)==0)
        {
            Greenfoot.setWorld(new SkyEnemy());
    }
       if (Greenfoot.getRandomNumber(3)==1)
       {
           Greenfoot.setWorld(new SkyEnemyTwo());
        }
        if (Greenfoot.getRandomNumber(3)==2)
        {
            Greenfoot.setWorld(new SkyEnemyThree());
        }
    }
    /**
     * plane can collect ball, play sound and add 1 to counter
     */
    Actor Ball = getOneObjectAtOffset(0,0,Ball.class);
    if (Ball != null)
    {
        getWorld().removeObject(Ball);
        Greenfoot.playSound ("Coin-collect-sound-effect.mp3");
        counter.add(1);
    }
}
/**
 * counter code
 */
public Plane (Counter pointcounter)
{
    this();
    counter = pointcounter;
}
}
You need to login to post a reply.
1
2
3