I have been trying to make a game where two people fight but it is not working!Heres the code:
world class
p1projectile
no 2p yet
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class world here. * * @author (your name) * @version (a version number or a date) */ public class world extends World { BazookaMan bazookaman; boolean x = bazookaman.x; /** * Constructor for objects of class world. * */ public world() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 500, 1); prepare(); CheckAlive(x); } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ private void prepare() { BazookaMan bazookaman = new BazookaMan(); addObject(bazookaman, 40, 35); bazookaman.setLocation(41, 35); bazookaman.setLocation(57, 32); bazookaman.setLocation(44, 34); } void CheckAlive(boolean x){ if(x = true){ removeObject(bazookaman);} } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class BazookaMan here. * * @author (your name) * @version (a version number or a date) */ public class BazookaMan extends Mover { Bazooka bazooka; public boolean x; public void act() { if (Greenfoot.isKeyDown("left")){ setRotation(getRotation()- 5); } if (Greenfoot.isKeyDown("right")){ setRotation(getRotation()+ 5); } if (Greenfoot.isKeyDown("z")){ move(1); } if ("space".equals(Greenfoot.getKey())){ fire(); } } private void fire(){ bazooka = new Bazooka(); getWorld().addObject(bazooka,getX(),getY()); bazooka.setRotation(getRotation()); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Bazooka here. * * @author (your name) * @version (a version number or a date) */ public class Bazooka extends Mover { /** * Act - do whatever the Bazooka wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(10.0); } }