Hello, I'm at a loss. What type of method would I use to add a horizontal line near the bottom of the screen that will simulate the surface of the planet. The ship should stop when it runs into the ground/surface.
public class Ship extends SmoothMover
{
private GreenfootImage Ship;
private static final double GRAVITY = 0.5;
//private int reloadDelayCount;
private double vSpeed;
private double mass;
private GreenfootImage ship = new GreenfootImage("ship.png");
private GreenfootImage shipWithThrust = new GreenfootImage("shipWithThrust.png");
/**
* Construct a ship with default size, mass, velocity and color.
*/
public Ship()
{
Vector initial = new Vector(Greenfoot.getRandomNumber(360), .6);
setRotation(270);
//this (20, 300, new Vector(0, 0.0), defaultColor);
}
/**
* Act - do whatever the Ship wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
checkKeys();
vSpeed += GRAVITY; //add constant acceleration due to gravity.
setLocation(getX(), getY()+vSpeed);
//applyGravity();
}
/**
* Check whether there are any keys pressed.
*/
public void checkKeys()
{
ignite(Greenfoot.isKeyDown("up"));
if(Greenfoot.isKeyDown("left"))
{
turn(-5);
}
if(Greenfoot.isKeyDown("right"))
{
turn(5);
}
}
/**
* Are there flames coming out from behind the ship?
*/
private void ignite(boolean thrust)
{
if (thrust == true)
{
Vector power = new Vector(getRotation(), .2);
addToVelocity(power);
setImage("shipWithThrust.png");
}
else
{
setImage("ship.png");
}
}
/**
* Add new ship to the center of world
*/
public void shipScenario()
{
World myWorld = getWorld();
Ship ship = new Ship();
myWorld.addObject(ship, 40, 30);
}
}
