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?
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;
}
}