yes, there is the chance that there will be multiple
moneyCounter.setValue(moneyCounter.getValue()+1);
moneyCounter.setValue(moneyCounter.getValue()+1);
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** hard reset hinzufügen knöpfe lernen (World)//vielicht auto turret töne animationen# hintergrund# tot 25% geldverlust * project plan: kauf system hinzufügen * (ROBOTER)für wie schnell schieße ich * (Schuss)für wie groß sind meine kugeln * (Rakete)für geld pro rakte * (ROBOTER)unsterblichkeit kaufen für 1000 + im menü unsterblich * (ROBOTER)game end für 10000 kaufen * */ public class Robot extends Animal { /** * Act - do whatever the Robot wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { shop(); shoot(); turn(); System.out.println("firerate" + fireRate); } public Counter actCounter; int fireRate = 28; public int overheat; public int duration = fireRate; // Zeit bis zum nächsten schuss private int firing; public void shoot() { if (firing != 0) firing--; { if (Greenfoot.isKeyDown("space") && firing == 0) { addBullet(); firing = fireRate; } } } public void addBullet() { Bullet bullet = new Bullet(); getWorld().addObject(bullet, getX() +2, getY()); bullet.setRotation(getRotation()); } public void turn() { if (Greenfoot.isKeyDown("d")) { turn(8); } if (Greenfoot.isKeyDown("a")) { turn(-8); } } Button upgradeShootingSpeed = new Button("shooting_speed_not_Pressed.png"); public void shop() { if(Greenfoot.isKeyDown("e")) { if(fireRate != 0) { upgradeShootingSpeed.setImage("shooting_speed_not_Pressed.png"); getWorld().addObject(upgradeShootingSpeed, 450, 100); getWorld().showText("Level: "+fireRate, 750, 100); } else { upgradeShootingSpeed.setImage("shooting_speed_max.png"); getWorld().addObject(upgradeShootingSpeed, 450, 100); } } if(fireRate != 0) { if(Greenfoot.mouseClicked(upgradeShootingSpeed)){ upgradeShootingSpeed.setImage("shooting_speed_Pressed.png"); fireRate = fireRate-4; Greenfoot.delay(7); upgradeShootingSpeed.setImage("shooting_speed_not_Pressed.png"); getWorld().showText("Level: "+fireRate, 750, 100); if(fireRate == 0) { upgradeShootingSpeed.setImage("shooting_speed_max.png"); getWorld().showText("Level: Max", 750, 100); } } } if(Greenfoot.isKeyDown("escape")) { getWorld().removeObject(upgradeShootingSpeed); getWorld().showText("", 750, 100); } } }
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 Animal { /** * 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() { move(7); die(); if (getWorld() != null) { kill(); } } protected void addedToWorld(World world) { if (moneyCounter == null) {moneyCounter = new Counter("Money: "); world.addObject(moneyCounter, 60, 40); } } public Counter moneyCounter; public void die() { if(isTouching(Bullet.class)) { moneyCounter.setValue(moneyCounter.getValue()+1); getWorld().removeObject(this); } } public void kill() { if(isTouching(Robot.class)) { getWorld().removeObject(this); Greenfoot.stop(); } } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MyWorld here. * * @author (your name) * @version (a version number or a date) */ public class MyWorld extends World { GifImage SPBG = new GifImage("space_background.gif"); public MyWorld() { super(900, 900, 1); //welt mit 900 mal 900 pixeln setBackground("space_background.gif");// damit es keinen White screen gibt beim reset prepare(); //roboter hinzufügen if(stopSpawn == false) { rocketSpawn(1); } } public void act() { stop(); regulateRockets(); setBackground( SPBG.getCurrentImage() ); } public void regulateRockets() { if (getObjects(Rocket.class).size() < 1) { if(stopSpawn == false) { rocketSpawn(1); } } } public void prepare() { Robot robot = new Robot(); addObject(robot , 450 ,450 ); } public boolean stopSpawn = false; public void stop() { if(("e").equals(Greenfoot.getKey())) { stopSpawn = true; removeObject(r); } if(Greenfoot.isKeyDown("escape")){ stopSpawn = false; rocketSpawn(1); } } Rocket r = new Rocket(); public void rocketSpawn (int howMany) { for(int i=0; i<howMany; i++) { int border = Greenfoot.getRandomNumber(4); int position = Greenfoot.getRandomNumber(900); if(border == 1) { addObject(r ,position ,0); }else if(border == 2) { addObject(r ,0 ,position); }else if(border == 3) { addObject(r ,position ,900); }else if(border == 4) { addObject(r ,900 ,position); } r.turnTowards(450, 450); } } }
public class Robot extends Animal { private Counter money = new Counter("Money: "); protected void addedToWorld(World world) { world.addObject(money, 60, 40); } ... }
public class Bullet extends Actor { ... // the robot that launched the bullet. private final Robot owner; public Bullet( final Robot _owner ) { owner = _owner; } public void act() { ... killRocket(); } private void killRocket() { for (final Rocket collidingRocket : this.getIntersectingObjects(Rocket.class)) { getWorld().removeObject(collidingRocket); owner.killedRocket(); } } ... }
public void killedRocket() { money.setValue(money.getValue() + 1); }
Bullet bullet = new Bullet(this);
in class Rocket: private void killRobot() // renamed from "kill()" { for (final Robot collidingRobot : getIntersectingObjects(Robot.class)) { getWorld().removeObject(this); collidingRobot.killedByRocket(); } } in class Robot: public void killedByRocket() { money.setValue(3 * money.getValue() / 4); }