hey,
Check this game.
http://www.greenfoot.org/scenarios/10979
my jumping is not fluid. somebody plz help me to solve this.
here is my frog code..
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class frog extends Actor
{
private int vSpeed=2;
private int acc = 2;
private boolean jumping;
private int jumpStrength = 150;
int sum= 0;
int i =0 ;
public void act()
{
if (Greenfoot.isKeyDown ("left"))
{
move(-4);
}
if (Greenfoot.isKeyDown ("right"))
{
move(4);
}
checkFall();
checkKey();
if(getY() > 580){
Greenfoot.playSound("gameover.mp3");
((back) getWorld()).gameOver();
}
}
public void fall(){
setLocation(getX(),getY() + vSpeed );
vSpeed=2+acc;
jumping =true;
}
public boolean onGround(){
int spriteHeight = getImage().getHeight();
int lookForGround = (spriteHeight/2) ;
Actor ground = getOneObjectAtOffset(0,lookForGround, brick.class);
if (ground == null){
jumping=true;
return false;
}else{
jumping = false;
return true;
}
}
public void checkFall(){
if(onGround()){
vSpeed=0;
}else{
fall();
}
}
public void jump(){
vSpeed= - jumpStrength;
jumping = true;
fall();
}
public void checkKey(){
if(Greenfoot.isKeyDown("space") && jumping == false){
Greenfoot.playSound("jumpsound.mp3");
jump();
}
}
public void checkKeyPress(){
if (Greenfoot.isKeyDown ("left"))
{
move(-4);
}
if (Greenfoot.isKeyDown ("right"))
{
move(4);
}
}
}
