public void moveVertically() { boolean onGround = false; // assume in air vSpeed += acceleration; // apply gravity setLocation(getX(), getY()+vSpeed); // fall Actor actor = getOneIntersectingObject(Collider.class); if (actor != null) { // colliding with another actor int vDir = (int)Math.signum(vSpeed); // vertical direction of movement vSpeed = 0; // kill vertical speed if (vDir > 0) onGround = true; // landing and not bopping head setLocation(getX(), actor.getY()-vDir*(actor.getImage().getHeight()+getImage().getHeight())/2); // assigning stop location } if (onGround && Greenfoot.isKeyDown("space")) vSpeed = -20; // initiate a jump }

