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

2017/4/21

cant find symbol

BrianOK BrianOK

2017/4/21

#
Trying to make my actor jump and land on the floor but when I do (ground) it says it can't find symbol. Don't understand the problem if any help me fix it or improve. thanks
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class Player extends Actor
    {
        private GreenfootImage[] images=new GreenfootImage[8];
        private int jeda=1,num=0,deltax=30;
        private int vSpeed= 2;
        private int acceleration = 2;
        private int jumpStrength = 12;
        private boolean jumping = false; 
        
        public void addedToWorld(World Game)
        {
            for(int i=0;i<images.length;i++){
                images[i]=new GreenfootImage("walking"+i+".png");
        }
        setImage(images[0]);
    }
        
    public void act()
        {
        if(jeda==0)jeda=5;
        if(jeda==1) {
                setImage(images[num]);
                num++;
                if(num>=images.length)num=0;
        }
        if(jeda>0)jeda--;
        checkKeys();
        checkFall();
}

    public boolean onGround()
    {
        Actor under = getOneObjectAtOffset ( 0,getImage(). getHeight() / 2, Floor.class);
        if(ground= null)
        {
            jumping = true;
            return false;
    }
    else
    {
        moveToGround(ground);
        return  true;
    }
  
}

    private void checkKeys()
{
    if(Greenfoot.isKeyDown("up"))
    {
        setImage("jump.png");
        jump();
    }
}

    public void fall ()
    {
        setLocation (getX(), getY() + vSpeed);
        if(vSpeed <=9)
        {
            vSpeed = vSpeed + acceleration;
        }  
        jumping = true;
}
public void jump()
    {
        vSpeed = -jumpStrength;
        fall();
    }
    public void checkFall()
    {
        if(onGround()) {
            vSpeed = 0;
        }
        else {
            fall();
        }
    }
}

    
Super_Hippo Super_Hippo

2017/4/21

#
You used 'under' the line before, so you can't use 'ground' in the next one. You will also need a == instead of = in line 36.
You need to login to post a reply.