How to make my actor so he can jump not only on the ground.class(platforms) but also on the bottom of the background thank you.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Vilkas here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Vilkas extends Actor
{
private GreenfootImage image1 = new GreenfootImage("wombat.png");
private GreenfootImage image2 = new GreenfootImage ("wombat-left.png");
private int vSpeed = 0;
private int acceleration = 2;
private boolean jumping;
private int jumpStrength = 20;
public void act()
{
checkFall();
animate();
CheckKeys();
platformAbove();
checkRightWalls();
checkLeftWalls();
}
public void CheckKeys()
{
if(Greenfoot.isKeyDown("a")){
move(-5);
}
if(Greenfoot.isKeyDown("d")){
move(5);
}
if(Greenfoot.isKeyDown("space") && jumping == false){
jump();
}
}
public void jump()
{
vSpeed = vSpeed - jumpStrength;
jumping = true;
fall();
}
public void animate()
{
if((Greenfoot.isKeyDown("d"))){
setImage (image1);
}
if((Greenfoot.isKeyDown("a"))){
setImage (image2);
}
}
public void fall()
{
setLocation(getX(),getY()+ vSpeed);
if(vSpeed <=9)
{
vSpeed = vSpeed + acceleration;
}
jumping = true;
}
public boolean onGround()
{
int spriteHeight = getImage().getHeight();
int yDistance = (int) (spriteHeight / 2 + 50 );
Actor ground = getOneObjectAtOffset (0,getImage().getHeight() / 2, Ground.class);
if(ground == null)
{
jumping = true;
return false;
}
else
{
moveToGround(ground);
return true;
}
}
public void checkFall()
{
if(onGround()) {
vSpeed=0;
}
else {
fall();
}
}
public void moveToGround(Actor ground)
{
int groundHeight = ground.getImage().getHeight();
int newY = ground.getY() - (groundHeight + getImage().getHeight()) / 2;
setLocation(getX(),newY);
jumping = false;
}
public boolean platformAbove()
{
int spriteHeight = getImage().getHeight();
int yDistance = (int)(spriteHeight/-2);
Actor ceiling = getOneObjectAtOffset(0, yDistance, Ground.class);
if(ceiling != null)
{
vSpeed = 1;
bopHead(ceiling);
return true;
}
else
{
return false;
}
}
public boolean checkRightWalls()
{
int spriteWidth = getImage().getWidth();
int xDistance = (int) (spriteWidth/2);
Actor rightWall = getOneObjectAtOffset(xDistance,0,Ground.class);
if(rightWall == null)
{
return false;
}
else {
stopByRightWall(rightWall);
return true;
}
}
public void stopByRightWall (Actor rightWall)
{
int wallWidth = rightWall.getImage().getWidth();
int newX = rightWall.getX() - (wallWidth + getImage().getWidth()) / 2;
setLocation(newX - 5, getY());
}
public void bopHead(Actor ceiling)
{
int ceilingHeight = ceiling.getImage().getHeight();
int newY = ceiling.getY() + (ceilingHeight + getImage().getHeight())/2;
setLocation(getX(), newY);
}
public boolean checkLeftWalls()
{
int spriteWidth = getImage().getWidth();
int xDistance = (int) (spriteWidth/2);
Actor leftWall = getOneObjectAtOffset(-xDistance,0,Ground.class);
if(leftWall == null)
{
return false;
}
else {
stopByleftWall(leftWall);
return true;
}
}
public void stopByleftWall (Actor leftWall)
{
int wallWidth = leftWall.getImage().getWidth();
int newX = leftWall.getX() + (wallWidth + getImage().getWidth()) / 2;
setLocation(newX + 5, getY());
}
}
