import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class rocket here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Rocket extends Actor
{
GreenfootImage rocket = new GreenfootImage("shipNoFire.png ");
GreenfootImage ship = new GreenfootImage("ship.png ");
int x;
int y;
/**
* Act - do whatever the rocket wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
x = this.getX();
y = this.getY();
// initialize rocket class
movements();
}
public void movements()
{
if(Greenfoot.isKeyDown("w")&& y <= 1200)
{
//says to check for key up and if condition is true move up 3 pixel's
setLocation(getX(),getY()-3);
}
if(Greenfoot.isKeyDown("s")&& y >= 0)
{
//says to check for key up and if condition is true move up 3 pixel's
setLocation(getX(),getY()+3);
}
if(Greenfoot.isKeyDown("a")&& x <= 1600)
{
//says to check for key up and if condition is true move up 3 pixel's
setLocation(getX()-3,getY());
}
if(Greenfoot.isKeyDown("d")&& x >= 0)
{
//says to check for key up and if condition is true move up 3 pixel's
setLocation(getX()+3,getY());
}
}
public void Bullets()
{
if(Greenfoot.isKeyDown("space"))
{
addObject(new Laser(),getX()+5,getY());
}
}
}
