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:
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:
//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.
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.