This site requires JavaScript, please enable it in your browser!
Greenfoot back
CassWin
CassWin wrote ...

2014/3/1

Help in jumping!

CassWin CassWin

2014/3/1

#
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); } } }
danpost danpost

2014/3/1

#
I do not think this is correct for what you want in the 'fall' method: 'vSpeed = 2+acc;'.
CassWin CassWin

2014/3/1

#
but fall works properly...
CassWin CassWin

2014/3/1

#
what should b there in fall??
danpost danpost

2014/3/1

#
Well '2+acc' will always be '4' since 'acc' never changes. I think what you wanted was 'vSpeed+acc'.
CassWin CassWin

2014/3/1

#
if i do tht the frog falls very fast.. the falling is ok.. prob is the jumping . u saw da game?
danpost danpost

2014/3/1

#
I saw da game! I do not know if it would help, but you could try diminishing the jump strength and slowing down the scenario speed a little.
CassWin CassWin

2014/3/1

#
diminishing the jump meaning?
danpost danpost

2014/3/1

#
Try adjusting the values of 'jumpStrength' and 'acc' -- something more like jumpStrength around twenty and acc of one. Then adjust the scenario speed to suit. You will still need to change the assignment of vSpeed in the fall method.
CassWin CassWin

2014/3/1

#
thanks man :) its working
You need to login to post a reply.