I have left the source code for my new game out. This is because they game doesn't work properly. The fire method for level three robot is broken so could some please help me with the code.
private boolean spaceDown;
if (spaceDown != Greenfoot.isKeyDown("space")) { spaceDown = ! spaceDown;
if (spaceDown == true) { fire() // or whatever, for producing a projectile } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class cannon here. * * @author (your name) * @version (a version number or a date) */ public class Enemy extends thrun { /** * Act - do whatever the cannon wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.isKeyDown("W")) { turn(-3); } if (Greenfoot.isKeyDown("S")) { turn(3); } if (spaceDown != Greenfoot.isKeyDown("space")) { spaceDown = ! spaceDown; } if (spaceDown == true) { fire(); // or whatever, for producing a projectile } } /** * Fire the cannon */ private void fire() { Cannonball stuff = new Cannonball(); getWorld().addObject(stuff, getX(), getY()); stuff.setRotation(getRotation()); stuff.move(35.0); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Road here. * * @author (your name) * @version (a version number or a date) */ public class Road extends World { private boolean spaceDown; /** * Constructor for objects of class Road. * */ public Road() { super(1000, 700, 1); prepare(); } /** * Prepare the world for the start of the program. * That is: create the initial objects and add them to the world. */ private void prepare() { house house2 = new house(); addObject(house2,75,82); house2.setLocation(31,32); cannon cannon = new cannon(); addObject(cannon,104,283); cannon.setLocation(125,332); cannon.setLocation(69,331); Enemy enemy = new Enemy(); addObject(enemy,948,323); enemy.setLocation(948,328); } }
private boolean spaceDown;