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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 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()); } } |