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

2021/9/25

Ground problem

orangepizza27 orangepizza27

2021/9/25

#
So I am new to Greenfoot and found out how to make a character have gravity and be able to jump, but I have no clue how to make certain parts of my world to be solid and have my actor be able to "stand" on them...
danpost danpost

2021/9/25

#
orangepizza27 wrote...
So I am new to Greenfoot and found out how to make a character have gravity and be able to jump, but I have no clue how to make certain parts of my world to be solid and have my actor be able to "stand" on them...
You should probably have shown some codes for clarity and completeness. However, I do have a Jump and Run Demo w/Moving Platform scenario up that you can look check out.
orangepizza27 orangepizza27

2021/9/25

#
ok, thanks!
orangepizza27 orangepizza27

2021/9/25

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Player extends Actor
{
    private int ySpeed;
    private int apexTimer;
    public int iN = 1;
    public int count;
    public Player()
    {
    }
 
    public void act()
    {
        int groundLevel = getWorld().getHeight() - getImage().getHeight()/2;
        boolean onGround = (getY() == groundLevel);
        Movement();
        Aump();
        Dump();
        if (!onGround)
        {
            if (ySpeed == 0 && apexTimer > 0) apexTimer--; 
            if (ySpeed == 0 && apexTimer > 0) return;
            ySpeed++;
            setLocation(getX(), getY()+ySpeed);
            if (getY()>=groundLevel)
            {
                setLocation(getX(), groundLevel); 
                Greenfoot.getKey();
           }
        }
        else 
        {
            if ("w".equals(Greenfoot.getKey())) 
            {
                ySpeed = -15;
                setLocation(getX(), getY()+ySpeed);
                apexTimer = 5;
            }
        }
    }
    public void Movement()
    {
        if (Greenfoot.isKeyDown("S"))
        {
            setLocation(getX() , getY() + 3);
        }
        if (Greenfoot.isKeyDown("A"))
        {
            setLocation(getX() - 3, getY());
            _Animation();
        }
        if (Greenfoot.isKeyDown("D"))
        {
            setLocation(getX() +  3, getY() );
            Animation();
        }
    }
    public void Animation()
    {
        if(count % 3 == 0)

            iN++;
        if(iN == 8)
        {
            iN = 1;
        }
        setImage("W" + iN + ".png");
        count++;
        
    }
    public void _Animation()
    {
        if(count % 3 == 0)

            iN++;
        if(iN == 8)
        {
            iN = 1;
        }
        setImage("-W" + iN + ".png");
        count++;
    }
    public void Dump()
    {
        if(Greenfoot.isKeyDown("W"))
        {
            if(Greenfoot.isKeyDown("D"))
            {
                setImage("J1.png");
            }
        }
    }
    public void Aump()
    {
        if(Greenfoot.isKeyDown("W"))
        {
            if(Greenfoot.isKeyDown("A"))
            {
                setImage("-J1.png");
            }
        }
    }
}
    
orangepizza27 orangepizza27

2021/9/25

#
this is currently what I have, and I need some way for the actor to stand on an island
You need to login to post a reply.