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

2016/2/20

how do i make gravity

spy9144 spy9144

2016/2/20

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Lander here. * * @author (spy9144) * @version (a version number or a date) */ public class Lander extends Actor { /** * Act - do whatever the ladybug wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. if (Greenfoot.isKeyDown("left")) { turn(-10); // turn left } if (Greenfoot.isKeyDown("right")) { turn(+10); // turn right } move(4); // our new behavior code is going here Actor apple = getOneObjectAtOffset(0, 0, apple.class); if(apple != null) { getWorld().removeObject(apple); apple Eaten;; } } }
danpost danpost

2016/2/20

#
Gravity causes a constant downward acceleration on free objects. This means constantly increasing the speed of the object in the downward direction (increasing of the y-coordinate value of the location of the object). This will require the vertical speed be stored in an int field so that you can increase it each act cycle and use it in moving vertically.
You need to login to post a reply.