I'm trying to create an assassins creed side scroller.
I'm experiencing a bug with the jumping method ive implemented.
Entire Assassin Class:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Assassin here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Assassin extends ScrollActor
{
int speed = 5;
int gravity = 10;
int vertSpeed;
/**
* Act - do whatever the Assassin wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
jump();
}
public void move()
{
if (Greenfoot.isKeyDown("right")) {
// move the camera forwards, actor moves with the camera by default
getWorld().moveCamera(speed);
}
if (Greenfoot.isKeyDown("left")) {
// move the camera backwards, actor moves with the camera by default
getWorld().moveCamera(-speed);
}
}
public void jump()
{
if(onGround()){
if(Greenfoot.isKeyDown("up") || Greenfoot.isKeyDown( "space")){
setLocationFromCamera(getXFromCamera(), getYFromCamera() - 10*gravity);
}
}
else{
fall();
}
}
public boolean onGround(){
Object under = getOneObjectAtOffset(0, getImage().getHeight()/2-8 , null);
return under != null;
}
public void fall()
{
setLocationFromCamera(getXFromCamera(), getYFromCamera() + gravity);
}
}
