Hello everybody,
I need a bit help with my jump n' run game.
I managed to make the main actor jump and fall, but somehow the actor still falls inside the ground pretty often.
Sometimes it works and it stays on the ground but most of the time the actor goes inside the ground.
Actor and Blocks are all 60 px height.
Also there is a problem where the actor jumps the whole time while pressing space. Is it possible to make the actor only jump one time and then it's only possible to jump again when the actor is on the ground again?
I would really appreciate help :)
Thanks!
import greenfoot.*;
public class Peach extends Actor
{
private int vSpeed = 0;
private int acceleration = 2;
public void act()
{
checkKeys();
checkFall();
}
public void checkKeys() {
if (Greenfoot.isKeyDown("left")) {
setLocation(getX()-2, getY());
}
else if (Greenfoot.isKeyDown("right")) {
setLocation(getX()+2, getY());
}
else {
setLocation(getX()+1, getY());
}
if (Greenfoot.isKeyDown("space")){
jump();
}
}
public void checkFall(){
if(onGround()){
}
else{
fall();
}
}
public boolean onGround(){
Actor unter = getOneObjectAtOffset( 0, 30, Ground.class );
return unter != null;
}
public void jump(){
vSpeed = -11;
fall();
}
public void fall(){
setLocation( getX(), getY() + vSpeed);
vSpeed = vSpeed + acceleration;
}
}
It somehow only works with the bottom 2 rows of blocks. If I place other blocks (via world, not shift + click), it seems to bug again. Any solutions for that maybe? :)
(here is an image of the bottom 2 rows, works fine)



The actor was right of the block and then get's teleported onto it.
I use the infinite scrolling engine you made so the game scrolls from left to right. All things are moved 1px to the right with every act then. Could that maybe cause the bug? Like if the actor is normally besides the block, but then everything moves and the actor bugs onto the block?
Movement limitation: