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

student1's Comments

Back to student1's profile

this is the gravity code i'm using
public void Gravity() { int groundLevel = getWorld().getHeight() - getImage().getHeight()/2; boolean onGround = (getY() == groundLevel); if (!onGround) { ySpeed++; setLocation(getX(), getY()+ySpeed); if (getY()>=groundLevel) { setLocation(getX(), groundLevel); Greenfoot.getKey(); } } else { if ("space".equals(Greenfoot.getKey())) { ySpeed = -15; setLocation(getX(), getY()+ySpeed); } } }
danpost, i'm making a game for my college and i'm using code that enables gravity and i'm wandering how you got it so the player does not go through the blocks