I came across Stickman scenario with empty code so I am trying to write the code. I want the game to be the stickman jumping over enemies.
I tried with this code block but it didn't work, the stickman will jump and come down within fractions of second.
I also tried for loop to set the location but it seems even faster.
So please how can I make the stickman jump realistically.
import greenfoot.*;
/
* This is a stick man. Make him run and jump.
*
* @author
* @version
*/
public class Stickman extends Actor
{
private int velocity = 0;
private int velCount = 0;
/
* Make the stickman act.
*/
public void act()
{
run();
checkKeyPress();
}
/
* Method to check key press.
*/
public void checkKeyPress(){
int posX = getX();
int posY = getY();
if (Greenfoot.isKeyDown("up")){
setLocation(posX, posY-70);
setImage("jump.png");
Greenfoot.delay(4);
setImage("stand.png");
setLocation(getX(), posY);
}
}
/
* Method to make stickman run.
*/
public void run(){
move(velocity+6); //Starts running with 7
int posY = getY();
if (getX()+2>getWorld().getWidth()){
//getWorld().addObject(new Stickman(), 0, posY);
//getWorld().removeObject(this);
setLocation(0, posY);
velCount++;
incVelocity();
}
}
/**
* Method to increase velocity by 1 after five rounds.
*/
public void incVelocity(){
if (velCount%5 == 0){
setVelocity(getVelocity()+1);
}
}
public int getVelocity(){return velocity;}
public void setVelocity(int velocity){this.velocity = velocity;}
}

