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

2017/3/2

Problem with Reseting the game

Farizio Farizio

2017/3/2

#
I can't see anything which could create an error at this code, however if I reset the game it just crashes with no error log message or anything usefull for solving the problem. Codes in which the error could be:
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
public class Background extends World
{
    private int imageCount = 0;
    private GreenfootImage bgImage = new GreenfootImage("Background.png");
    public int dif = MMPlayer.diff;
    public int height = 0;
 
    public void act() {
        imageCount += 4;
        drawBackgroundImage();
        height++;
        showText("Height:" + height + " / 3000",100,50);
        if(height >= 2980)
        {
            showText ("Level Completed",500,375);
             
        }
        switch (dif)
        {
            case 1:
            PlanetspawnerE();
             
            case 2:
            PlanetspawnerM();
             
            case 3:
            PlanetspawnerH();
        }
    }
... unnecessary
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
public class MMPlayer extends Actor
{
    public static int diff;
    public MMPlayer()
    {
        this.getImage().scale(50, 100);
        setLocation(500,700);
    }
    public void act()
    {
        setImage("MMRocket.png");
        this.getImage().scale(50, 100);
        if(Greenfoot.isKeyDown("right"))
        {
            setImage("Rocket+30.png");
            this.getImage().scale(70, 82);
            move(4);
        }
         
        if(Greenfoot.isKeyDown("left"))
        {
            setImage("Rocket-30.png");
            this.getImage().scale(70, 82);
            move(-4);
        }
         
        if(Greenfoot.isKeyDown("up"))
        {
            setLocation(getX(), (getY()-4));
        }
         
        if(Greenfoot.isKeyDown("down"))
        {
            setLocation(getX(), (getY()+4));
        }
         
        Actor Easy = getOneIntersectingObject(MMEasy.class);
        Actor Medium = getOneIntersectingObject(MMMedium.class);
        Actor Hard = getOneIntersectingObject(MMHard.class);
        Actor Hitbox = getOneIntersectingObject(TryAgain.class);
        if(Easy !=null)
        {
            setImage("Explosion.png");
            diff = 1;
            Greenfoot.setWorld(new Background());
        }
        if(Medium !=null)
        {
            setImage("Explosion.png");
            diff = 2;
            Greenfoot.setWorld(new Background());
        }
        if(Hard !=null)
        {
            setImage("Explosion.png");
            diff = 3;
            Greenfoot.setWorld(new Background());
        }
        if (Hitbox != null)
        {
            setImage("Explosion.png");
            Greenfoot.setWorld(new Background());
        }
         
    }   
}
danpost danpost

2017/3/2

#
Line 7 in MMPlayer should fail. Remove that line.
Farizio Farizio

2017/3/3

#
No it doesn't change anything!
danpost danpost

2017/3/3

#
If it crashes when you reset the project, then it is probably something in your world constructor or in the constructor of one of the object created during the creation of your world. You could start by showing your Background class constructor.
Farizio Farizio

2017/3/3

#
I think that can't be an issue for that, because there is only the command "super(1000, 750, 1)" and "prepare();". What I found out was that if I am in the "GameOver" world and restart everything it doesn't matter if I set the world to "Background" or "MainMenue". That means the problem almost has to be in the world "Background". Here is the complete code of it:
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import greenfoot.*;
public class Background extends World
{
    private int imageCount = 0;
    private GreenfootImage bgImage = new GreenfootImage("Background.png");
    public int dif = MMPlayer.diff;
    public int height = 0;
    public void act() {
        imageCount += 4;
        drawBackgroundImage();
        height++;
        showText("Height:" + height + " / 3000",100,25);
        if(height >= 2980)
        {
            Greenfoot.setWorld(new LevelCompl());
        }
        switch (dif)
        {
            case 1:
            PlanetspawnerE();
             
            case 2:
            PlanetspawnerM();
             
            case 3:
            PlanetspawnerH();
        }
        MMPlayer.diff = 0;
    }
    public void drawBackgroundImage() {
        if (imageCount < -bgImage.getHeight())
        {
            imageCount -= bgImage.getHeight();
        }
        int temp = imageCount;
        getBackground().drawImage(bgImage, 0, temp);
        getBackground().drawImage(bgImage, 0, temp - bgImage.getHeight());
    }
    public Background()
    {   
        super (1000,750,1);
        prepare();
    }
     
 
    private void prepare()
    {
        Player player = new Player();
        addObject (player, 500, 550);
 
    }
 
 
    private void PlanetspawnerE()
    {
        Planet1 planet1 = new Planet1();
        Planet2 planet2 = new Planet2();
        Planet3 planet3 = new Planet3();
        int cons = (int) (Math.random()*800)+1;
         
        switch (cons)
        {
            case 1:
            Planet1 splanet1 = new Planet1();
            planet1 = splanet1;
            addObject(planet1, Greenfoot.getRandomNumber(1000),0);
            break;
             
            case 2:
            Planet2 splanet2 = new Planet2();
            planet2 = splanet2;
            addObject(planet2, Greenfoot.getRandomNumber(1000),0);
            break;
             
            case 3:
            Planet3 splanet3 = new Planet3();
            planet3 = splanet3;
            addObject(planet3, Greenfoot.getRandomNumber(1000),0);
            break;
             
            default:
            break;
        }
         
    }
    private void PlanetspawnerM()
    {
        Planet1[] planet1 = new Planet1[4];
        Planet2[] planet2 = new Planet2[4];
        Planet3[] planet3 = new Planet3[4];
        int[]kindar = new int[12];
        int cons = (int) (Math.random()*600)+1;
         
        switch (cons)
        {
            case 1:
            Planet1 splanet1 = new Planet1();
            planet1[0] = splanet1;
            addObject(planet1[0], Greenfoot.getRandomNumber(1000),0);
            break;
             
            case 2:
            Planet2 splanet2 = new Planet2();
            planet2[0] = splanet2;
            addObject(planet2[0], Greenfoot.getRandomNumber(1000),0);
            break;
             
            case 3:
            Planet3 splanet3 = new Planet3();
            planet3[0] = splanet3;
            addObject(planet3[0], Greenfoot.getRandomNumber(1000),0);
            break;
             
            default:
            break;
        }
         
    }
    private void PlanetspawnerH()
    {
        Planet1[] planet1 = new Planet1[4];
        Planet2[] planet2 = new Planet2[4];
        Planet3[] planet3 = new Planet3[4];
        int[]kindar = new int[12];
        int cons = (int) (Math.random()*200)+1;
         
        switch (cons)
        {
            case 1:
            Planet1 splanet1 = new Planet1();
            planet1[0] = splanet1;
            addObject(planet1[0], Greenfoot.getRandomNumber(1000),0);
            break;
             
            case 2:
            Planet2 splanet2 = new Planet2();
            planet2[0] = splanet2;
            addObject(planet2[0], Greenfoot.getRandomNumber(1000),0);
            break;
             
            case 3:
            Planet3 splanet3 = new Planet3();
            planet3[0] = splanet3;
            addObject(planet3[0], Greenfoot.getRandomNumber(1000),0);
            break;
             
            default:
            break;
        }
         
    }
}
danpost danpost

2017/3/3

#
The only thing that looks really off to me is in your 'drawBackgroundImage' method where you compare 'imageCount to a large negative value; yet, the value of the field is increasing and will never get below '-bgImage..getHeight()'. Change line 31 to:
1
if (imageCount > bgImage.getHeight())
Farizio Farizio

2017/3/4

#
That fixed another problem of mine but not my main problem :( Probably it's just Greenfoot which is bugging a bit, like I have never had an errorlog... However thanks for trying!
danpost danpost

2017/3/4

#
Farizio wrote...
What I found out was that if I am in the "GameOver" world and restart everything it doesn't matter if I set the world to "Background" or "MainMenue". That means the problem almost has to be in the world "Background".
Please post your GameOver class code for inspection. Possibly it may be a factor.
You need to login to post a reply.