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

2018/12/26

Game Creation: Directional Idle, Shooting and Jumping.

7
8
9
10
danpost danpost

2019/1/3

#
Unlimited wrote...
So to get that to work i need to remove PlayerY and the getX() after Azure actor and Vile actor. Is that correct?
Well, you can remove line 2 -- the line with playerY in it. Then, you can use playerX instead of Azure getX() in line 3. With the code being in the Vile class, you only need to use getX() in lieu of Vile getX() in line 3.
Unlimited Unlimited

2019/1/3

#
Well thanks for the reply but i figured something out afterall, it was just a lot more then just changing a couple lines but it works now. I only have one more thing and then ill be done Whenever the player character dies in the "boss fight" is there a error message that "Azure" cannot be found as the boss asks for the position but the character has been removed. Is there a quick way to say that the boss can test for either "Azure" or the "GameOver" Object so the error does not happen? if not or if you wish not to awnser then ill just leave it as it is, that is fine too.
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
public void checkPlayer()
    {
        if(Azure == null)
        {
            if (!getObjectsInRange(200, Azure.class).isEmpty()) Azure  = (getObjectsInRange(200, Azure.class).get(0)) ;
        }
        else if (shooting() == true)
        {
            int playerX = Azure.getX();
             
                if(Azure.getX() > getX()  && animSet != shootAnim){
                setAnim(shootAnim, 2);
                speed = 0;
                if(shootingCounter <= 0)
                getWorld().addObject(new EnemyVilePlasma(), getX()+90, getY()-34);
                shootingCounter = 5;
            }
                else if (Azure.getX() < getX()  && animSet != shootLeftAnim ){
                setAnim(shootLeftAnim, 2);
                speed = 0;
                if(shootingCounter <= 0)
                getWorld().addObject(new EnemyVilePlasmaLeft(), getX()-90, getY()-34);
                shootingCounter = 5;
            }
             
        }
            else if (shooting() == false)
            {
                 
                if(animSet != rightAnim && animSet == shootAnim){
                setAnim(rightAnim, 2);
                speed = 15;
            }
                if(animSet != leftAnim && animSet == shootLeftAnim){
                setAnim(leftAnim, 2);
                speed = -15;
             
            }
        }
    }
danpost danpost

2019/1/3

#
Between lines 6 and 7, insert the following:
1
else if (Azure.getWorld() == null) return;
Unlimited Unlimited

2019/1/3

#
That sadly did not work. Still the same error.
danpost danpost

2019/1/3

#
Unlimited wrote...
That sadly did not work. Still the same error.
Show the entire class code and post the entire terminal error trace that that particular code produces.
Unlimited Unlimited

2019/1/3

#
java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:714) at greenfoot.Actor.getY(Actor.java:178) at Azure.fallOutOfWorld(Azure.java:378) at Azure.act(Azure.java:95) at greenfoot.core.Simulation.actActor(Simulation.java:567) at greenfoot.core.Simulation.runOneLoop(Simulation.java:530) at greenfoot.core.Simulation.runContent(Simulation.java:193) at greenfoot.core.Simulation.run(Simulation.java:183)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class Vile here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Vile extends Enemy
{
    private int vSpeed = 0;
    private int acceleration = 1;
    private int shootingCounter = 5;
    private int stopCounter = 200;
    private int resumeCounter = 220;
    private int spriteHeight = getImage().getHeight();
    private int spriteWidth = getImage().getWidth();
    private int lookForGroundDistance = (int)spriteHeight/2;
    private int lookForEdge = (int)spriteWidth/2;
    private int speed = 15;
    private Actor Azure;
     
    private int health = 50;
     
    private int animCount;
    private int animDelay = 6;
     
    private static GreenfootImage[] vileStandAnim = new GreenfootImage[1];
    private static GreenfootImage[] vileStandLeftAnim = new GreenfootImage[1];
    private static GreenfootImage[] rightAnim = new GreenfootImage[2];
    private static GreenfootImage[] leftAnim = new GreenfootImage[2];
    private static GreenfootImage[] shootAnim = new GreenfootImage[1];
    private static GreenfootImage[] shootLeftAnim = new GreenfootImage[1];
     
     
    static
    {
        for (int i=0; i<vileStandAnim.length; i++) vileStandAnim[i] = new GreenfootImage("VileStand_0"+(i+1)+".png");
        for (int i=0; i<vileStandLeftAnim.length; i++) vileStandLeftAnim[i] = new GreenfootImage("VileStandLeft_0"+(i+1)+".png");
        for (int i=0; i<rightAnim.length; i++) rightAnim[i] = new GreenfootImage("VileDash_0"+(i+1)+".png");
        for (int i=0; i<leftAnim.length; i++) leftAnim[i] = new GreenfootImage("VileDashLeft_0"+(i+1)+".png");
        for (int i=0; i<shootAnim.length; i++) shootAnim[i] = new GreenfootImage("VileShoot_0"+(i+1)+".png");
        for (int i=0; i<shootLeftAnim.length; i++) shootLeftAnim[i] = new GreenfootImage("VileShootLeft_0"+(i+1)+".png");
    }  
     
    private void setAnim(GreenfootImage[] anim, int frameRate)
    {
        animSet = anim;
        animCount = -1;
        animDelay = frameRate;
        animate();
    }
     
     
     
    private GreenfootImage[] animSet = vileStandLeftAnim;
     
     
    /**
     * Act - do whatever the Vile wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        animate();
        checkAnim();
        checkFall();
        canMoveRight();
        canMoveLeft();
        move();
        stopCounter--;
        shootingCounter--;
        resumeCounter--;
        destroy();
        checkPlayer();
         
    }
 
    public void checkPlayer()
    {
        if(Azure == null)
        {
            if (!getObjectsInRange(500, Azure.class).isEmpty()) Azure  = (getObjectsInRange(500, Azure.class).get(0)) ;
        }
        else if (Azure.getWorld() == null) return;
        else if (shooting() == true)
        {
            int playerX = Azure.getX();
             
                if(Azure.getX() > getX()  && animSet != shootAnim){
                setAnim(shootAnim, 2);
                speed = 0;
                if(shootingCounter <= 0)
                getWorld().addObject(new EnemyVilePlasma(), getX()+90, getY()-34);
                shootingCounter = 5;
            }
                else if (Azure.getX() < getX()  && animSet != shootLeftAnim ){
                setAnim(shootLeftAnim, 2);
                speed = 0;
                if(shootingCounter <= 0)
                getWorld().addObject(new EnemyVilePlasmaLeft(), getX()-90, getY()-34);
                shootingCounter = 5;
            }
             
        }
            else if (shooting() == false)
            {
                 
                if(animSet != rightAnim && animSet == shootAnim){
                setAnim(rightAnim, 2);
                speed = 15;
            }
                if(animSet != leftAnim && animSet == shootLeftAnim){
                setAnim(leftAnim, 2);
                speed = -15;
             
            }
        }
    }
     
    public void setHealth(int points) {
        health += points;
    }
    public int getHealth() {
        return health;
    }
 
    public void destroy()
    {
        World myWorld = getWorld();
        AzureWorld azureworld = (AzureWorld)myWorld;
        if(health==0)
        {
             
            GameOver gameover = new GameOver();
            getWorld().removeObject(this);
            myWorld.addObject(gameover, myWorld.getWidth()/2,myWorld.getHeight()/2);
 
        }
    }
     
    public boolean shooting()
    {
        if (stopCounter <= 0)
        {
             
                if(resumeCounter <= 0){
                    stopCounter = 200;
                    resumeCounter = 220;
                }
                    return true;
        }
        else
        {
             
             
            return false;
        }
    }
     
     
    public void move()
    {
         
         
        if(canMoveRight() == true && canMoveLeft() == false )
        {
            speed = 15;
            move(speed);
        }
         
        else if(canMoveLeft() == true && canMoveRight() == false)
        {
            speed = -15;
            move(speed);
        }
        else
        {
            move(speed);
        }
    }
     
    public boolean canMoveLeft()
    {
       boolean canMoveLeft = true;
         
       int imageWidth = getImage().getWidth();
       int imageHeight = getImage().getHeight();
       if (getOneObjectAtOffset(imageWidth/-2 -3, imageHeight/-2, Collider.class) !=null ||
       getOneObjectAtOffset(imageWidth/-2 -3, imageHeight/2-65, Collider.class) !=null)
            canMoveLeft = false;
         
       return canMoveLeft;
          
    }
      
    public boolean canMoveRight()
    {
        boolean canMoveRight = true;
         
        int imageWidth = getImage().getWidth();
        int imageHeight = getImage().getHeight();
        if (getOneObjectAtOffset(imageWidth/2 +3, imageHeight/-2, Collider.class) !=null ||
        getOneObjectAtOffset(imageWidth/2 +3, imageHeight/2-65, Collider.class) !=null)
            canMoveRight = false;
         
        return canMoveRight;
    }
     
    public void checkAnim()
    {
        if(speed == 15 && animSet != rightAnim)setAnim(rightAnim, 2);
        else if(speed == -15 && animSet != leftAnim) setAnim(leftAnim, 2);
         
    }
     
    public void fall()
    {
        setLocation(getX(), getY() +vSpeed);
          
        {
            vSpeed = vSpeed + acceleration;
        }
         
    }
      
    public boolean onGround()
    {
        int spriteHeight = getImage().getHeight();
        int lookForGround = (int) (spriteHeight/2-30);
          
        Actor ground = getOneObjectAtOffset(0, lookForGround, Collider.class);
          
        if(ground == null)
        {
             
            return false;
        }
        else
        {
            moveToGround(ground);
            return true;
        }
          
    }
     
     public void moveToGround(Actor ground)
    {
        int groundHeight = ground.getImage().getHeight();
        int newY = ground.getY() - (groundHeight + getImage().getHeight())/2+30;
          
        setLocation(getX(), newY);
         
          
    }
      
    public void checkFall()
    {
        if(onGround())
        {
            vSpeed = 0;
              
        }
        else
        {
            fall();
        }
  
    }
     
    private void animate()
    {
        animCount = (animCount+1)%(animSet.length*animDelay);
        if (animCount%animDelay == 0) setImage(animSet[animCount/animDelay]);
    }
}
danpost danpost

2019/1/3

#
Unlimited<< Error Trace Omitted >> << Code Omitted >>[/quote wrote...
The error is not occurring by code in the Vile class. Show the entire Azure class codes.
Unlimited Unlimited

2019/1/3

#
Oh my bad. Here
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * This class is just an example. You can delete it or change the code.
 * It's not necessary for the scrolling system.
 */
public class Azure extends ScrollingActor
{
    private int vSpeed = 0;
    private int acceleration = 1;
    private boolean jumping;
    private int shootingCounter = 10;
    private int Counter = 1;
    boolean hitInv = false;
     
  
     
     
     
    private static GreenfootImage[] rightAnim = new GreenfootImage[10];
    private static GreenfootImage[] leftAnim = new GreenfootImage[10];
    private static GreenfootImage[] standAnim = new GreenfootImage[9];
    private static GreenfootImage[] standLeftAnim = new GreenfootImage[9];
    private static GreenfootImage[] runAnim = new GreenfootImage[10];
    private static GreenfootImage[] runLeftAnim = new GreenfootImage[10];
    private static GreenfootImage[] runBAnim = new GreenfootImage[10];
    private static GreenfootImage[] runLeftBAnim = new GreenfootImage[10];
    private static GreenfootImage[] jumpAnim = new GreenfootImage[3];
    private static GreenfootImage[] jumpLeftAnim = new GreenfootImage[3];
    private static GreenfootImage[] standBAnim = new GreenfootImage[1];
    private static GreenfootImage[] standLeftBAnim = new GreenfootImage[1];
    private static GreenfootImage[] rightBAnim = new GreenfootImage[11];
    private static GreenfootImage[] leftBAnim = new GreenfootImage[11];
    private static GreenfootImage[] jumpBAnim = new GreenfootImage[4];
    private static GreenfootImage[] jumpLeftBAnim = new GreenfootImage[4];
    private static GreenfootImage[] exAnim = new GreenfootImage[7];
    private static GreenfootImage[] getHitAnim = new GreenfootImage[4];
    private static GreenfootImage[] getHitLeftAnim = new GreenfootImage[4];
     
    static
    {
        for (int i=0; i<standAnim.length; i++) standAnim[i] = new GreenfootImage("Stand_0"+(i+1)+".png");
        for (int i=0; i<standLeftAnim.length; i++) standLeftAnim[i] = new GreenfootImage("StandLeft_0"+(i+1)+".png");
        for (int i=0; i<rightAnim.length; i++) rightAnim[i] = new GreenfootImage("Walk-A_"+(i < 10 ? "0" : "")+(i+1)+".png");
        for (int i=0; i<leftAnim.length; i++) leftAnim[i] = new GreenfootImage("WalkLeft-A_"+(i < 10 ? "0" : "")+(i+1)+".png");
        for (int i=0; i<runAnim.length; i++) runAnim[i] = new GreenfootImage("Run_0"+(i+1)+".png");
        for (int i=0; i<runLeftAnim.length; i++) runLeftAnim[i] = new GreenfootImage("RunLeft_0"+(i+1)+".png");
        for (int i=0; i<runBAnim.length; i++) runBAnim[i] = new GreenfootImage("RunB_0"+(i+1)+".png");
        for (int i=0; i<runLeftBAnim.length; i++) runLeftBAnim[i] = new GreenfootImage("RunLeftB_0"+(i+1)+".png");
        for (int i=0; i<jumpAnim.length; i++) jumpAnim[i] = new GreenfootImage("Jump_0"+(i+1)+".png");
        for (int i=0; i<jumpLeftAnim.length; i++) jumpLeftAnim[i] = new GreenfootImage("JumpLeft_0"+(i+1)+".png");
        for (int i=0; i<standBAnim.length; i++) standBAnim[i] = new GreenfootImage("StandB_0"+(i+1)+".png");
        for (int i=0; i<standLeftBAnim.length; i++) standLeftBAnim[i] = new GreenfootImage("StandLeftB_0"+(i+1)+".png");
        for (int i=0; i<rightBAnim.length; i++) rightBAnim[i] = new GreenfootImage("WalkB_"+(i < 10 ? "0" : "")+(i+1)+".png");
        for (int i=0; i<leftBAnim.length; i++) leftBAnim[i] = new GreenfootImage("WalkLeftB_"+(i < 10 ? "0" : "")+(i+1)+".png");
        for (int i=0; i<jumpBAnim.length; i++) jumpBAnim[i] = new GreenfootImage("JumpB_0"+(i+1)+".png");
        for (int i=0; i<jumpLeftBAnim.length; i++) jumpLeftBAnim[i] = new GreenfootImage("JumpLeftB_0"+(i+1)+".png");
        for (int i=0; i<getHitAnim.length; i++) getHitAnim[i] = new GreenfootImage("Damage_0"+(i+1)+".png");
        for (int i=0; i<getHitLeftAnim.length; i++) getHitLeftAnim[i] = new GreenfootImage("DamageLeft_0"+(i+1)+".png");
    }
     
     
     
     
    private int animCount;
    private int animDelay = 6;
  
     
    private void setAnim(GreenfootImage[] anim, int frameRate)
    {
        animSet = anim;
        animCount = -1;
        animDelay = frameRate;
        animate();
    }
     
     
     
    private GreenfootImage[] animSet = standAnim;
     
     
     
     
    /**
     * Here you can tell your actor what he has to do.
     */
    public void act() {
        animate();
        canMoveRight();
        canMoveLeft();
        horizontalMovement();
        checkFall();
        shootingCounter --;
        getHit();
        fallOutOfWorld();
    }
     
    public void fall()
    {
        setLocation(getX(), getY() +vSpeed);
          
        {
            vSpeed = vSpeed + acceleration;
        }
        jumping = true;
    }
      
    public boolean onGround()
    {
        int spriteHeight = getImage().getHeight();
        int lookForGround = (int) (spriteHeight/2-30);
          
        Actor ground = getOneObjectAtOffset(0, lookForGround, Collider.class);
          
        if(ground == null)
        {
            jumping = true;
            return false;
        }
        else
        {
            moveToGround(ground);
            return true;
        }
          
    }
      
    public boolean ceiling()
    {
        int spriteHeight = getImage().getHeight();
        int yDistance = (int) (spriteHeight/-2);
          
        Actor ceiling = getOneObjectAtOffset(0, yDistance, Collider.class);
          
        if(ceiling != null)
        {
            vSpeed =0;
            hitHead(ceiling);
            return true;
        }
        else
        {
              
            return false;
        }
          
    }
      
      
    public void hitHead(Actor ceiling)
    {
        int ceilingHeight = ceiling.getImage().getHeight();
        int newY = ceiling.getY() + (ceilingHeight + getImage().getHeight())/2;
          
        setLocation(getX(), newY);
          
          
    }
      
      
     
      
    public boolean canMoveLeft()
    {
       boolean canMoveLeft = true;
         
       int imageWidth = getImage().getWidth();
       int imageHeight = getImage().getHeight();
       if (getOneObjectAtOffset(imageWidth/-2 -3, imageHeight/-2, Collider.class) !=null ||
       getOneObjectAtOffset(imageWidth/-2 -3, imageHeight/2-35, Collider.class) !=null)
            canMoveLeft = false;
         
       return canMoveLeft;
          
    }
      
    public boolean canMoveRight()
    {
        boolean canMoveRight = true;
         
        int imageWidth = getImage().getWidth();
        int imageHeight = getImage().getHeight();
        if (getOneObjectAtOffset(imageWidth/2 +3, imageHeight/-2, Collider.class) !=null ||
        getOneObjectAtOffset(imageWidth/2 +3, imageHeight/2-35, Collider.class) !=null)
            canMoveRight = false;
         
        return canMoveRight;
    }
      
    public void moveToGround(Actor ground)
    {
        int groundHeight = ground.getImage().getHeight();
        int newY = ground.getY() - (groundHeight + getImage().getHeight())/2+30;
          
        setLocation(getX(), newY);
        jumping = false;
          
    }
      
    public void checkFall()
    {
        if(onGround())
        {
            vSpeed = 0;
              
        }
        else
        {
            fall();
        }
  
    }
      
     
     
     
         
    public void horizontalMovement()
    {
        boolean onGround = false;
        int boost = 6;
         
        int dir = 0;
        int vDir = (int)Math.signum(vSpeed);
         
         
         
        if (Greenfoot.isKeyDown("left") && canMoveLeft()) dir--;
        if (Greenfoot.isKeyDown("right") && canMoveRight()) dir++;   
         
          
        setLocation(getX()+(8)*dir, getY());
         
        if(dir == -1){
            Counter = 0;
        }
        if(dir == 1){
            Counter = 1;
        }
        if (dash() == true)
        setLocation(getX()+(8+boost)*dir, getY());
         
        if (jump() == true)
        setLocation(getX(), getY() - 20);
         
        if (vDir > 0) onGround = true;
         
         
         
         
        
        if (dir == -1 && animSet != leftAnim && dash() == false &&  shooting() == false &&  vSpeed <= 0 ) setAnim(leftAnim, 3);
        else if (dir == 1 && animSet != rightAnim && dash() == false && shooting() == false && vSpeed <= 0) setAnim(rightAnim, 3);
         
        else if (dir == 0 && animSet != standLeftAnim  && shooting() == false && vSpeed <= 0 && Counter == 0) setAnim( standLeftAnim, 6);
        else if (dir == 0 && animSet != standAnim && shooting() == false && vSpeed <= 0 && Counter == 1) setAnim( standAnim, 6);
         
        else if (dir == 1 && animSet != jumpAnim && jump() == true && shooting() == false ) setAnim(jumpAnim, 16);
        else if (dir == -1 && animSet != jumpLeftAnim && jump() == true && shooting() == false ) setAnim(jumpLeftAnim, 16);
         
        else if (dir == 0 && animSet != jumpLeftAnim && jump() == true && shooting() == false && Counter == 0) setAnim(jumpLeftAnim, 6);
        else if (dir == 0 && animSet != jumpAnim && jump() == true && shooting() == false && Counter == 1) setAnim(jumpAnim, 6);
         
        else if ( dir == 1 && dash() == true && animSet != runAnim && jump() == false && shooting() == false &&  vSpeed <= 0 )setAnim(runAnim,2);
        else if ( dir == -1 && dash() == true && animSet != runLeftAnim && jump() == false && shooting() == false &&  vSpeed <= 0 )setAnim(runLeftAnim,2);
         
        else if ( dir == 1 && dash() == true && animSet != runBAnim && jump() == false && shooting() == true &&  vSpeed <= 0 )setAnim(runBAnim,2);
        else if ( dir == -1 && dash() == true && animSet != runLeftBAnim && jump() == false && shooting() == true &&  vSpeed <= 0 )setAnim(runLeftBAnim,2);
         
        else if (dir == 0 && animSet != standLeftBAnim && jump() == false && shooting() == true && vSpeed <= 0 && Counter == 0) setAnim(standLeftBAnim, 6);
        else if (dir == 0 && animSet != standBAnim && jump() == false && shooting() == true && vSpeed <= 0 && Counter == 1) setAnim(standBAnim, 6);
         
        else if (dir == 1 && animSet != leftBAnim && dash() == false && shooting() == true &&  vSpeed <= 0 ) setAnim(leftBAnim, 3);
        else if (dir == -1 && animSet != rightBAnim && dash() == false && shooting() == true && vSpeed <= 0 ) setAnim(rightBAnim, 3);
     
        else if (dir == -1 && animSet != jumpBAnim && jump() == true && shooting() == true ) setAnim(jumpBAnim, 8);
        else if (dir == 1 && animSet != jumpLeftBAnim && jump() == true && shooting() == true ) setAnim(jumpLeftBAnim, 8);
         
        else if (dir == 0 && animSet != jumpBAnim && jump() == true && shooting() == true && Counter == 0) setAnim(jumpBAnim, 8);
        else if (dir == 0 && animSet != jumpLeftBAnim && jump() == true && shooting() == true && Counter == 1) setAnim(jumpLeftBAnim, 8);
         
        if(dir == 1 && shooting() == true && shootingCounter <=0 )
        {
            getWorld().addObject(new PlasmaShot(), getX()+90, getY()-34);
            shootingCounter = 10;
            Greenfoot.playSound("Laser.mp3");
        }
        else if(dir == -1 && shooting() == true && shootingCounter <=0 )
        {
            getWorld().addObject(new PlasmaShotLeft(), getX()-90, getY()-34);
            shootingCounter = 10;
            Greenfoot.playSound("Laser.mp3");
        }
        else if (dir == 0 && (animSet == jumpLeftBAnim || animSet == standBAnim ) && shooting() == true && shootingCounter <=0 )
        {
            getWorld().addObject(new PlasmaShot(), getX()+90, getY()-34);
            shootingCounter = 10;
            Greenfoot.playSound("Laser.mp3");
        }
        else if (dir == 0 && (animSet == jumpBAnim || animSet == standLeftBAnim) && shooting() == true && shootingCounter <=0 )
        {
            getWorld().addObject(new PlasmaShotLeft(), getX()-90, getY()-34);
            shootingCounter = 10;
            Greenfoot.playSound("Laser.mp3");
        }
        else if ((dir == 1 || dir == 0) && animSet != getHitAnim && hitInv == true) setAnim(getHitAnim,2);
     
        else if (dir == -1 && animSet != getHitLeftAnim && hitInv == true) setAnim(getHitLeftAnim,2);
    }
     
    public boolean jump()
    {
        if (Greenfoot.isKeyDown("space")){
            return true;
        }
        else
        {
            return false;
        }
    }
     
    public boolean dash()
    {
        if (Greenfoot.isKeyDown("s"))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
     
    public boolean shooting()
    {
        if (Greenfoot.isKeyDown("d"))
        {
            return true;
             
        }
        else
        {
            return false;
        }
    }
     
    public void getHit()
    {
       Actor Enemy = getOneIntersectingObject(Enemy.class);
       if(Enemy != null)
       {
           World myWorld = getWorld();
           AzureWorld azureworld = (AzureWorld)myWorld;
           HP healthbar = azureworld.getHP();
            
           if (hitInv == false)
           {
               healthbar.loseHealth();
               hitInv = true;
                
                
               if(healthbar.health <=0)
               {
                   GameOver gameover = new GameOver();
                   myWorld.addObject(gameover, myWorld.getWidth()/2,myWorld.getHeight()/2);
                   myWorld.removeObject(this);
               }
                
            }
            
        }
        else
        {
            hitInv = false;
         }
    }
     
    public void fallOutOfWorld()
    {
        World myWorld = getWorld();
        AzureWorld azureworld = (AzureWorld)myWorld;
        if (getY()>300){
            GameOver gameover = new GameOver();
            getWorld().removeObject(this);
             
            myWorld.addObject(gameover, myWorld.getWidth()/2,myWorld.getHeight()/2);
        }  
    }
     
    private void animate()
    {
        animCount = (animCount+1)%(animSet.length*animDelay);
        if (animCount%animDelay == 0) setImage(animSet[animCount/animDelay]);
    }
}
danpost danpost

2019/1/3

#
Unlimited wrote...
Oh my bad. Here << Code Omitted >>
Okay, Correct class, but not the code that created that particular error trace. Fortunately, I could figure out what was going on (as getY was only used once in the fallOutOfWorld method). The problem is that you have two ways for the Azure object to "die". You cannot ask about one after the other once has it removed from the world. Insert the following as the first line in the fallOutOfWorld method:
1
if (getWorld() == null) return;
Unlimited Unlimited

2019/1/3

#
Ah yes that fixed it. Thank you very much. You really were a great help and i appoligise for any inconviniences ive caused.
You need to login to post a reply.
7
8
9
10