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

2013/5/17

Subclass cannot find symbol - constructor X()?

Entity1037 Entity1037

2013/5/17

#
Two subclasses of X are not recognizing that they are actually a subclass of X. For example:
1
2
3
4
5
6
7
8
9
import greenfoot.*;
 
public class Upgrades extends X //Error is highlighted as occurring here
{
    public void act()
    {
        // Add your action code here.
    }   
}
I have no Idea why it is doing this. The actor X is still named X, so I'm at a loss. Could anyone help me?
danpost danpost

2013/5/17

#
What does your class X look like?
Entity1037 Entity1037

2013/5/17

#
Here's the entire code:
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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
//Megaman X is 26 pixels wide, and 53 pixels tall
//Offset of 13 for X's right/left side
//Offset of 26 for X's up/down side
 
import greenfoot.*;
import java.util.List;
 
public class X extends Actor
{
    int x=0;//X coordinate based on the grid
    int y=0;//Y coordinate based on the grid
     
    int xmove=0;
    int xmove2=0;//This is for dashing
    int xmove3=0;//This is for moving away from walls when wall jumping\
    int xmove3TimerAmount=10;
    int xmove3Timer=xmove3TimerAmount;
    int xmove4=0;//This is for wind/conveyor belts ect.
    int ymove=0;
    int ymove2=0;//This is for other y movement (elevator/knockback ect.)
     
    boolean fall=true;
    boolean jump=false;
    boolean left=false;
    boolean right=false;
     
    int jumpTimerAmount=30;
    int jumpTimer=jumpTimerAmount;
    int gravityTimer=0;
    int gTime=20;
     
    boolean faceLeft=false;
    boolean facedLeft=false;
    boolean shootDown=false;
    boolean jumpDown=false;
    boolean wallDown=false;
     
    boolean dash=false;
    int dashAmount=40;//How long you dash for (it is set up like this so it can be easily changed)
    int dashTimer=dashAmount;
    int dashSlowAmount=10;//How long it takes to slow down (same for this one)
    int dashSlowTimer=dashSlowAmount;
    boolean faceChange=false;
    boolean dashSlow=false;
    boolean dashJump=false;
    boolean airDash=false;
    boolean airDashUpgrade=false;
    boolean noDash=false;
    boolean noDashJump=false;
     
    int cod=getImage().getHeight()/2+1;//Up/down hit detection position
    int cos=getImage().getWidth()/2+1;//Left/right hit detection position
    int cou=getImage().getHeight()/2-7;//Side Up/Down hit detection position
    int coo=getImage().getWidth()/2-4;//Base Left/Right hit detection position
     
    boolean leftFace=false;
    boolean rightFace=true;
     
    boolean die = false;
     
    int width=0;
    public X(int X, int Y)
    {
         
    }
     
    public void addedToWorld(World world) 
    {
        health = world.getHeight()/2-98;
    }
     
    public void act()
    {
        controls();
        GreenfootImage placeHolder = new GreenfootImage("man01.png");
        GreenfootImage blank = new GreenfootImage("Blank.png");
        if (recoil>0){
            damage=0;
            recoil--;
            if (recoil%2==0){
                setImage(blank);
            }else{
                setImage(placeHolder);
            }
        }else{
            setImage(placeHolder);
            Health();
        }
        cheats();
        if (getX()>25||getX()<getWorld().getWidth()-26||getY()>25||getY()<getWorld().getHeight()-26){
            //gridCoordinates();
            ((GridCoordinates)getWorld().getObjects(GridCoordinates.class).get(0)).giveGridCoordinates(x,y);
        }
    }
     
    int xMoved=0;
    int yMoved=0;
    public void gridCoordinates()
    {
        xMoved+=xmove+xmove2+xmove3;
        yMoved+=-ymove+-ymove2;
        if (xMoved<0){
            xMoved=xMoved+50; x--;
        }else if(xMoved>50){
            xMoved=xMoved-50; x++;
        }
        if (yMoved<0){
            yMoved=yMoved+50; y--;
        }else if(yMoved>50){
            yMoved=yMoved-50; y++;
        }
        ((GridCoordinates)getWorld().getObjects(GridCoordinates.class).get(0)).giveGridCoordinates(x,y);
    }
     
    //X-Buster Coding
     
    int shot1Amount=0;
    boolean Shot1=true;
     
    public void shot1Decrease(){shot1Amount--;}
     
    public void XBuster()
    {
        if (shot1Amount<3){
            shot1();
        }
    }
     
    public void shot1()
    {
        if (faceLeft==false&&Greenfoot.isKeyDown("left")&&shootDown==false){
            ((SWorld)getWorld()).addObject(new shot1(6),getX()+16,getY()-10,false);
            shot1Amount++;
        }else if(faceLeft==true&&Greenfoot.isKeyDown("left")&&shootDown==false){
            ((SWorld)getWorld()).addObject(new shot1(-6),getX()-16,getY()-10,false);
            shot1Amount++;
        }
        if (Greenfoot.isKeyDown("left")){
            shootDown=true;
        }else{
            shootDown=false;
        }
    }
    //              |Errors|
    //Air dashing lasts for infinity for seemingly no reason
    public void dashing()
    {
         
        //Dash Slowing
         
        if (dashSlow==true&&dashSlowTimer>0&&noDash==false){
            dashSlowTimer--;
            if (xmove2>0){
                xmove2=1;
            }else if(xmove2<0){
                xmove2=-1;
            }
        }else if(dashSlow==true){
            dashSlow=false;
            dashSlowTimer=dashSlowAmount;
            xmove2=0;
            dash=false;
            airDash=false;
            dashJump=false;
        }else if(! Greenfoot.isKeyDown("right")&&dashTimer!=dashAmount&&dashJump==false&&airDash==false){
            dashTimer=dashAmount;
        }
         
        //Air Dash if Upgrade is Present
         
        List dashUpgrade = getWorld().getObjects(dashUpgrade.class);
         
        if (! dashUpgrade.isEmpty()){
            Actor DashUpgrade = (Actor) dashUpgrade.get(0);
            if (DashUpgrade!=null){
                airDashUpgrade=true;
            }
        }
         
        if (airDashUpgrade==false){
            if (Greenfoot.isKeyDown("right")&&dash==false){
                if (fall==true||jump==true){
                    noDash=true;
                }
            }
            if (fall==false&&jump==false){
                noDash=false;
            }
        }else{
            if (Greenfoot.isKeyDown("right")&&dash==false){
                if (fall==true||jump==true){
                    airDash=true;
                }
            }
        }
         
        //Dashing
         
        if (Greenfoot.isKeyDown("right")&&dashTimer>0&&noDash==false||dashJump==true){
            dash=true;
            if (airDash==true){
                ymove=0;
                gravityTimer=18;
            }
            dashTimer--;
            if (faceLeft==true){
                xmove2=-3;
            }else{
                xmove2=3;
            }
            dashSlow=false;
        }else if(xmove2!=0){
            dashSlow=true;
            if (airDash==true){
                dashSlowTimer=0;
                noDashJump=true;
            }
        }
         
        //Consistant dash speed when dash jumping
         
        if (dash==true&&airDash==false&&noDashJump==false){
            if (jump==true||fall==true){
                dashSlowTimer=1;
                dashSlow=false;
                dashTimer=1;
                dashJump=true;
            }
        }else{
            dashJump=false;
            noDashJump=false;
        }
    }
     
    public void controls()
    {
         
        //Xmove
         
        if (Greenfoot.isKeyDown("a")&&right==false&&recoil<=recoilAmount-recoilAmount/3){
            xmove=-1;
            left=true;
            faceLeft=true;
        }else{
            left=false;
        }
         
        if (Greenfoot.isKeyDown("d")&&left==false&&recoil<=recoilAmount-recoilAmount/3){
            xmove=1;
            right=true;
            faceLeft=false;
        }else{
            right=false;
        }
         
        if (left==false&&right==false){
            xmove=0;
        }
         
        //Stop dashing if player looks another way
         
        if (faceLeft!=facedLeft&&jump==false&&fall==false&&dash==true&&dashJump==false){
            dashTimer=0;
            dashSlowTimer=0;
            dashSlow=true;
            facedLeft=faceLeft;
        }else{
            facedLeft=faceLeft;
        }
         
        //Ymove/Wall Jumping/Grivity Physics
         
        if (Greenfoot.isKeyDown("up")&&jumpTimer>0&&fall==false&&jumpDown==false&&recoil<recoilAmount-recoilAmount/3){
            ymove=-2;
            jumpTimer--;
            jump=true;
        }else if (jumpTimer!=jumpTimerAmount){
            fall=true;
            ymove++;
            jumpTimer=jumpTimerAmount;
        }else if(ymove>-1){
            jump=false;
        }
         
        if (jumpTimer<1){
            jumpDown=true;
        }
         
        if (! Greenfoot.isKeyDown("up")){
            jumpDown=false;
        }
         
        if (dashTimer!=dashAmount&&jump==true||fall==true){
            dashTimer=1;
            dashSlowTimer=1;
        }
         
        //Control for rate of gravitational acceleration
         
        if (fall==true){
            gravityTimer++;
            if (gravityTimer>gTime&&ymove<5){
                ymove++;
                gravityTimer=0;
            }else if(gravityTimer>gTime){
                gravityTimer=0;
            }
        }else{
            gravityTimer=0;
            if (jump==false){
                ymove=0;
            }
        }
         
        //Floor detection
         
        Actor downco=getOneObjectAtOffset(0,cod,Box.class);
        Actor downco2=getOneObjectAtOffset(coo,cod,Box.class);
        Actor downco3=getOneObjectAtOffset(-coo,cod,Box.class);
        Actor downco4=getOneObjectAtOffset(0,cod,Base.class);
        Actor downco5=getOneObjectAtOffset(coo,cod,Base.class);
        Actor downco6=getOneObjectAtOffset(-coo,cod,Base.class);
        Actor downco7=getOneObjectAtOffset(0,cod,Spike.class);
        Actor downco8=getOneObjectAtOffset(coo,cod,Spike.class);
        Actor downco9=getOneObjectAtOffset(0,cod,Spike.class);
         
        //Left Wall detection
         
        Actor leftco=getOneObjectAtOffset(-cos,0,Box.class);
        Actor leftco2=getOneObjectAtOffset(-cos,cou,Box.class);
        Actor leftco3=getOneObjectAtOffset(-cos,-cou,Box.class);
        Actor leftco4=getOneObjectAtOffset(-cos,0,Base.class);
        Actor leftco5=getOneObjectAtOffset(-cos,cou,Base.class);
        Actor leftco6=getOneObjectAtOffset(-cos,-cou,Base.class);
        Actor leftco7=getOneObjectAtOffset(-cos,0,Spike.class);
        Actor leftco8=getOneObjectAtOffset(-cos,cou,Spike.class);
        Actor leftco9=getOneObjectAtOffset(-cos,-cou,Spike.class);
         
        //Right Wall detection
         
        Actor rightco=getOneObjectAtOffset(cos,0,Box.class);
        Actor rightco2=getOneObjectAtOffset(cos,cou,Box.class);
        Actor rightco3=getOneObjectAtOffset(cos,-cou,Box.class);
        Actor rightco4=getOneObjectAtOffset(cos,0,Base.class);
        Actor rightco5=getOneObjectAtOffset(cos,cou,Base.class);
        Actor rightco6=getOneObjectAtOffset(cos,-cou,Base.class);
        Actor rightco7=getOneObjectAtOffset(cos,0,Spike.class);
        Actor rightco8=getOneObjectAtOffset(cos,cou,Spike.class);
        Actor rightco9=getOneObjectAtOffset(cos,-cou,Spike.class);
         
        //Ceiling detection
         
        Actor upco=getOneObjectAtOffset(0,-cod,Box.class);
        Actor upco2=getOneObjectAtOffset(coo,-cod,Box.class);
        Actor upco3=getOneObjectAtOffset(-coo,-cod,Box.class);
        Actor upco4=getOneObjectAtOffset(0,-cod,Base.class);
        Actor upco5=getOneObjectAtOffset(coo,-cod,Base.class);
        Actor upco6=getOneObjectAtOffset(-coo,-cod,Base.class);
         
        //Floor detect effect
         
        if (jump==false&&downco!=null||downco2!=null||downco3!=null||downco4!=null||downco5!=null||downco6!=null||downco7!=null||downco8!=null||downco9!=null){
            fall=false;
            if (dashJump==true){
                dashJump=false;
                dashSlowTimer=0;
            }
        }else if(jump==false&&fall==false){
            fall=true;
            ymove=1;
        }
         
        //Some wall jump code
         
        if (jumpDown==true){
            wallDown=true;
        }
         
        //Call dashing
         
        dashing();
         
        //No moving if on invincibility frames
        if (recoil>recoilAmount-recoilAmount/3){
            xmove=0;
            xmove2=0;
            if (faceLeft==true){
                xmove=1;
            }else{
                xmove=-1;
            }
        }
        //Left wall detect effect/wall jumping
         
        if (leftco!=null||leftco2!=null||leftco3!=null||leftco4!=null||leftco5!=null||leftco6!=null||leftco7!=null||leftco8!=null||leftco9!=null){
            if (Greenfoot.isKeyDown("right")&&Greenfoot.isKeyDown("up")&&dashTimer>0&&dash==false){
                dashJump=true;
                setLocation(getX()+5,getY());
                //xmove3=3;
            }else if (dashTimer!=dashAmount){
                dashTimer=0;
                dashSlowTimer=0;
                dashSlow=true;
            }
            if (Greenfoot.isKeyDown("a")&&recoil<=recoilAmount-recoilAmount/3){
                if (jump==true||fall==true){
                    faceLeft=false;
                    leftFace=true;
                    if (ymove<0&&wallDown==false){
                        ymove=0;
                        gravityTimer=0;
                    }
                    if (ymove>1){
                        ymove=1;
                    }
                    if (Greenfoot.isKeyDown("up")&&wallDown==false){
                        wallDown=true;
                        ymove=-2;
                    }else if (! Greenfoot.isKeyDown("up")){
                        wallDown=false;
                    }
                }
            }else if(leftFace==true){
                leftFace=false;
                faceLeft=true;
            }
            if (xmove<0){
                xmove=0;
            }
            if (xmove2<0){
                xmove2=0;
            }
        }
         
        //Right wall detect effect/wall jumping
         
        if (rightco!=null||rightco2!=null||rightco3!=null||rightco4!=null||rightco5!=null||rightco6!=null||rightco7!=null||rightco8!=null||rightco9!=null){
            if (Greenfoot.isKeyDown("right")&&Greenfoot.isKeyDown("up")&&dashTimer>0&&dash==false){
                dashJump=true;
                setLocation(getX()-5,getY());
                //xmove3=-3;
            }else if (dashTimer!=dashAmount){
                dashTimer=0;
                dashSlowTimer=0;
                dashSlow=true;
            }
            if (Greenfoot.isKeyDown("d")&&recoil<=recoilAmount-recoilAmount/3){
                if (jump==true||fall==true){
                    faceLeft=true;
                    rightFace=true;
                    if (ymove<0&&wallDown==false){
                        ymove=0;
                        gravityTimer=0;
                    }
                    if (ymove>1){
                        ymove=1;
                    }
                    if (Greenfoot.isKeyDown("up")&&wallDown==false){
                        wallDown=true;
                        ymove=-2;
                    }else if (! Greenfoot.isKeyDown("up")){
                        wallDown=false;
                    }
                }
            }else if(rightFace==true){
                rightFace=false;
                faceLeft=false;
            }
            if (xmove>0){
                xmove=0;
            }
            if (xmove2>0){
                xmove2=0;
            }
        }
         
        //xmove 3 control
         
        if (xmove3!=0&&xmove3Timer>0){
            xmove3Timer--;
        }else if(xmove3!=0){
            xmove3Timer=xmove3TimerAmount;
            if (xmove3>0){
                xmove3--;
            }else if(xmove3<0){
                xmove3++;
            }
        }
        if (xmove3!=0){
            xmove=0;
            if (xmove3>0&&faceLeft==false){
                xmove3=0;
                xmove3Timer=xmove3TimerAmount;
            }
            if (xmove3<0&&faceLeft==true){
                xmove3=0;
                xmove3Timer=xmove3TimerAmount;
            }
        }
         
        //Ceiling detect effect
         
        if (upco!=null||upco2!=null||upco3!=null||upco4!=null||upco5!=null||upco6!=null){
            if (ymove<0){
               ymove=0;
            }
        }
         
        /*//Screen Loop
         *
        if(getY()>getWorld().getHeight()-2){
            if (getOneObjectAtOffset(getX(),0,Block.class)==null){
                setLocation(getX(),1);
            }else{
                die=true;
            }
        }else if(getY()==0){
            setLocation(getX(),getWorld().getHeight()-3);
        }else if(getX()>getWorld().getWidth()-2){
            setLocation(1,getY());
        }else if(getX()==0){
            setLocation(getWorld().getWidth()-3,getY());
        }*/
         
        //Jump Cheat
         
        if (Greenfoot.isKeyDown("j")){
            ymove=-2;
            fall=true;
        }
         
        //This makes sure you can't move while dashing
         
        if (xmove2!=0){
            xmove=0;
        }
         
        //Call X-Buster method
         
        XBuster();
         
        //Move Command
        setLocation(getX()+xmove+xmove2+xmove3,getY()+ymove+ymove2);
    }
     
    public void cheats()
    {
        if (Greenfoot.isKeyDown("g")){
            GreenfootImage bg = new GreenfootImage("Blank.png");
            ((SWorld)getWorld()).setScrollingBackground(bg);
        }
    }
     
    //health is measured based on actor positions on the Y coordinate
    //getWorld().getHeight()/2-96 is the top of the health meter
    //getWorld().getHeight()/2+82 is the bottom of the health meter
    //Spacing between health point actors is 6 cells (pixels)
    //X coordinate for all health related actors for X is 30
    //The total health is 30 units
     
    int health; //=getWorld().getHeight()/2-96;
    int damage=0;
    int heal=0;
    int recoilAmount=150;
    int recoil=0;
    boolean healthIncreaseDown=false;
    boolean healthDecreaseDown=false;
     
    //Methods that recieve damage and heal values
     
    public void damage(int receiveDamage){damage+=receiveDamage;}
    public void heal(int receiveHealth){heal+=receiveHealth;}
     
    //Health Coding
     
    public void Health()
    {
         
        //Cheats to test if health System Works
         
        if (Greenfoot.isKeyDown("p")&&healthDecreaseDown==false){
            healthDecreaseDown=true;
            damage+=1;
        }else if(! Greenfoot.isKeyDown("p")){
            healthDecreaseDown=false;
        }
         
         if(Greenfoot.isKeyDown("o")&&healthIncreaseDown==false){
            healthIncreaseDown=true;
            heal+=1;
        }else if(! Greenfoot.isKeyDown("o")){
            healthIncreaseDown=false;
        }
         
        //Actual Health System
         
        if (damage>0){
            for (damage=damage; damage>0; damage--){
                if (health<=getWorld().getHeight()/2+82){
                    List health1=getWorld().getObjectsAt(30,health,Health1.class);
                    if (! health1.isEmpty()){
                        Actor Health1 = (Actor) health1.get(0);
                        if (Health1!=null){
                            getWorld().removeObject(Health1);
                            ((Score) getWorld().getObjects(Score.class).get(0)).add(1);//Increment total damage counter
                            recoil=recoilAmount;
                        }
                    }
                    health+=6;
                }
            }
        }
         
        if (health>getWorld().getHeight()/2+81){
            die=true;
        }
         
        if (heal>0){
            for (heal=heal; heal>0; heal--){
                if (health>=getWorld().getHeight()/2-96){
                    health-=6;
                    ((SWorld)getWorld()).addObject(new Health1(),30,health,false);
                }
            }
        }
         
        //Other things that kill you
         
        if (getOneObjectAtOffset(0,0,Box.class)!=null){
            damage+=30;
        }
         
        if (getY()==getWorld().getHeight()-getImage().getHeight()/2-1){
            damage+=30;
        }
         
        if (die==true){
            for (int i=10; i>=0; i--){
                getWorld().addObject(new XExplosion(),getX(),getY());
            }
            getWorld().removeObject(this);
        }
         
    }
}
I know, it's pretty huge.
danpost danpost

2013/5/17

#
All that code and no constructor (which the error message was saying it could not find). Just adding a simple empty constructor should solve the issue.
1
public X() {}
Entity1037 Entity1037

2013/5/17

#
Huh, it worked. I have no Idea why, but OK then. Thank you!
You need to login to post a reply.