Hi, im making a space invaders game and I need help. how do I get the bullet to move up. when I shoot the bullet goes sideways.
This is my code
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Ship here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Ship extends Animal
{
/**
* 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()
{
checkKeyPress();
}
public void checkKeyPress()
{
if(Greenfoot.isKeyDown("Right"))
{
move(10);
}
else if (Greenfoot.isKeyDown("Left"))
{
move(-10);
}
else if ("space".equals(Greenfoot.getKey()))
{
fire();
}
}
public void fire()
{
Bullet b = new Bullet();//makes the bullet
b.setRotation(getRotation());//sets the rotation of the bullet to be the same as the ship's
getWorld().addObject(b, getX(), getY());
}
}
