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

2023/6/28

cant jump while holding two buttons

Mauckenweg Mauckenweg

2023/6/28

#
In my jumpnrun you can use a/d to move and m to sprint. this works fine but i cant jump (space) while sprinting. is it possible to fix this?
Mauckenweg Mauckenweg

2023/6/28

#
public void move()
    {
        currentX = getX();
       currentY = getY();
       currentGlobalX = getGlobalX();
       
        ySpeed++; // adds gravity
        animZaehler++;
        if (Greenfoot.isKeyDown("left")&&!Greenfoot.isKeyDown("M")&& getGlobalX() != 0)
        {
            move(4);
            if (getX() <= 300)getWorld().moveCamera(2); 
        }   
        if (Greenfoot.isKeyDown("right")&&!Greenfoot.isKeyDown("M")&& getGlobalX() != 0)
        {
            move(-4);
            if (getX() <= 300)getWorld().moveCamera(-2);
        }
        if (Greenfoot.isKeyDown("right")&&Greenfoot.isKeyDown("M")&& getGlobalX() != 0)
        {
            move(8);
            if (getX() <= 300)getWorld().moveCamera(4);
        }
        if (Greenfoot.isKeyDown("left")&&Greenfoot.isKeyDown("M")&& getGlobalX() != 0)
        {
            move(-8);
            if (getX() <= 300)getWorld().moveCamera(-4);
        }
        setLocation(getX(), getY()+ySpeed/2);
        // check for change in horizontal direction
        
        if (isTouching(Boden.class))onGround=true;
        if (!isTouching(Boden.class))onGround=false;
        while (getOneObjectAtOffset(0, getImage().getHeight()/3+1, Boden.class) != null)
        {
            setLocation(getX(), getY()-1); 
            ySpeed = 0;
        }
        // check above the actor
        while (getOneObjectAtOffset(0, -getImage().getHeight()/2-1, Boden.class) != null) 
        {
            setLocation(getX(), getY()+1);
            ySpeed = 0;
        }
        // check to right of actor
        while (getOneObjectAtOffset(getImage().getWidth()/3+1, 0, Boden.class) != null&&isTouching(Boden.class))
        {
            setLocation(getX()-1, getY());
            xSpeed = 0;
        }
        // check to left of actor
        while (getOneObjectAtOffset(-getImage().getWidth()/3-1, 0, Boden.class) != null&&isTouching(Boden.class))
        {
            setLocation(getX()+1, getY());
            xSpeed = 0;
        }
       
    }
danpost danpost

2023/6/28

#
Mauckenweg wrote...
In my jumpnrun you can use a/d to move and m to sprint. this works fine but i cant jump (space) while sprinting. is it possible to fix this?
It is not possible to jump at all without any code for jumping.
You need to login to post a reply.