Hello, what's the code for gravity (to turn it on).
import greenfoot.*;
/**
* Write a description of class robot here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class robot extends Actor
{
private int balloonEaten = 0;
private Counter counter;
private skull skull;
private int vSpeed = 0;
private int acceleration =2;
private int setLocation;
public robot(Counter pointCounter)
{
counter = pointCounter;
}
public void act()
{
checkFall();
if (Greenfoot.isKeyDown("shift"))
Greenfoot.start();
if (Greenfoot.isKeyDown("enter"))
Greenfoot.stop();
if (Greenfoot.isKeyDown("right"))
move(5);
if (Greenfoot.isKeyDown("left"))
move(-5);
if (Greenfoot.isKeyDown("space"))
turn(17);
setRotation(90);
if (Greenfoot.isKeyDown("up"))
{ move(-5); }
if (Greenfoot.isKeyDown("down"))
{ move(5); }
setRotation(0);
if (isAtEdge() )
{
turn(90);
}
Actor balloon = getOneIntersectingObject(balloon.class);
if(balloon != null)
{
World myWorld = getWorld();
balloonEaten++;
counter.add(1);
Greenfoot.playSound("balloon pop.mp3");
myWorld.removeObject(balloon);
myWorld.addObject(new Explosions(),getX(),getY());
if (counter.getValue() >= 9) {
gameOver();
}
if (balloonEaten >= 10) {
YouWin youwin = new YouWin();
myWorld.addObject(youwin, myWorld.getWidth()/2, myWorld.getHeight()/2);
}
if (balloonEaten >= 1) {
skull skull = new skull(counter);
myWorld.addObject(skull, Greenfoot.getRandomNumber(myWorld.getWidth()), Greenfoot.getRandomNumber(myWorld.getHeight()));
}
}
}
private void fall()
{
setLocation(getX(), getY(), +vSpeed);
vSpeed = vSpeed + acceleration;
}
public boolean onGround()
{
int spriteHeight = getImage().getHeight();
int lookForGround = (int)(spriteHeight/2) + 5;
Actor ground = getOneObjectAtOffset(0, lookForGround, road.class);
if(ground == null)
{
return false;
}
else
{
return true;
}
}
public void checkFall()
{
if(onGround())
{
vSpeed =0;
}
else
{
fall();
}
}
/**
* We have won the game.
*/
public void gameOver()
{
Greenfoot.playSound("superstition.wav");
Greenfoot.stop();
}
}
setLocation(getX(), getY(), +vSpeed);