I have a project i'm doing and I need to delay and actor because it is a platform game and when the actor jumps if you hold the space bar the actor flys, I need to delay the actor after it jumps so it doesn't fly. How do I do this?
Here is my code.
This is the part I need the delay.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Odesseus here.
*
* @author (marzukr)
* @version (12-13-12)
*/
public class Odesseus extends Actor
{
private int speed = 4;
private int vSpeed = 0;
private int exel = 2;
private int jp = -5;
/**
* Act - do whatever the Odesseus wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
keycheck();
checkFall();
}
private void keycheck()
{
if(Greenfoot.isKeyDown("right"))
{
moveRight();
}
if(Greenfoot.isKeyDown("left"))
{
moveLeft();
}
if(Greenfoot.isKeyDown("space"))
{
jump();
}
}
public void jump()
{
vSpeed = jp;
fall();
}
public void moveRight()
{
setLocation ( getX() + speed, getY() );
}
public void moveLeft()
{
setLocation ( getX() - speed, getY() );
}
public void fall()
{
setLocation (getX(), getY() + vSpeed);
vSpeed = vSpeed + exel;
}
public boolean onGround()
{
Actor under = getOneObjectAtOffset (0, 40, ship.class);
return under != null;
}
public boolean fiftyfour()
{
Actor under = getOneObjectAtOffset (0 , 40, bush.class);
return under != null;
}
public boolean hi()
{
Actor under = getOneObjectAtOffset (0, 40, stone.class);
return under != null;
}
public boolean yo()
{
Actor under = getOneObjectAtOffset (0, 40, water54.class);
return under != null;
}
public void checkFall()
{
if(onGround())
{
vSpeed = 0;
}
else
{
if(fiftyfour())
{
vSpeed = 0;
}
else
{
if(hi())
{
vSpeed = 0;
}
else
{
if(yo())
{
vSpeed = 0;
}
else
{
fall();
}
}
}
}
}
}
public void jump()
{
vSpeed = jp;
fall();
}

