Hello,
I am currently attempting to make my own (crappy) jumping engine, but I have encountered a problem I have pondered over for many a hour: I can not get the object to leave ground or, if I can, it jumps infinetly. Here is my code and by the way I am using static int's if you are wondering.
Thanks for the help.
import greenfoot.*; import java.awt.Color; public class Cube extends Conector { public boolean fall = false; public boolean jump; private double gravity=1.1; private double yspeed; private double exactX; private double exactY; private boolean ready=true; public void addedToWorld(World world) { GreenfootImage image=new GreenfootImage(25,25); image.setColor(new Color(205,201,201,175)); image.fill(); setImage(image); } public void setLocation(int x, int y) { exactX = x; exactY = y; super.setLocation(x, y); } public void setLocation(double x, double y) { exactX = x; exactY = y; super.setLocation((int) x, (int) y); } public double getexactX() { return exactX; } public double getexactY() { return exactY; } public void act() { setLocation(getexactX(),getexactY()+gravity); Actor platform = getOneObjectAtOffset(0, getImage().getHeight()/2, Platform.class); int groundHeight = 20; int newY = platy - (groundHeight + getImage().getHeight())/2; if(Greenfoot.isKeyDown("a")) { setLocation(getexactX()-2,getexactY()+gravity); } if(Greenfoot.isKeyDown("d")) { setLocation(getexactX()+2,getexactY()+gravity); } if(ready=true&&Greenfoot.isKeyDown("w")) { yspeed=-5; setLocation(getexactX(), getexactY()+yspeed); fall=true; } if(fall=true&&platy<getY()) { yspeed-=gravity; } if(fall=false) { vspeed=0; } if(getOneObjectAtOffset(0,20,Platform.class)!=null) { setLocation(getexactX(),platy-20); fall=false; } }}