ok, last thing i have left for this game is to get the hp to scale when it finishes waves 5, 10, 15, etc (boss waves) and starts the spawning over again. i go the wave system fixed so it will spawn them, then when they all die a timer comes up to count down till the next wave, then the next wave starts. i have it where it spawns from 5 different enemy units depending on the wave number (hence the inc hp after waves 5 and so on).
here's a link to the scenario: http://www.greenfoot.org/scenarios/8919
i put some coding i thought would work in the spawning class, but it didn't change their health, so i commented it out.
spawning class
world class
spawning units parent class:
public class spawning extends Actor { /** * Act - do whatever the spawning wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ private int spawnsMade = 0; private int spawnsAlive = 0; private static final int maxspawns = 25; private int unit = 0; private long time = System.currentTimeMillis(); private long counter = 0; private long totaltime = 0; private Random rand = new Random(); private int wave; private int spawnTimer = 0; private int spawnTime = 120; private int i = 0; private int hpinc = 0; /** //if the time is right for the spawn, it spawns a random unit from 1-4. will implement a spawning for //bosses as well. //find out how to pause the timer for the wavetime when the pause button is pressed * add option in here for each minion to see if it's killed, and if so, add minerals, or in each class **/ public void act() { // Add your action code here. wave = ((tdpath)getWorld()).waveNum(); if(wave <= 5 && spawnTime() && spawnsMade <= maxspawns) { spawn(); spawnTimer = spawnTime; } // if(hpinc < 1 && wave > 5 && wave%5 > 0) // { // hpinc++; // ((tdpath)getWorld()).incSpawnHP(); // } // if(wave%5 == 0) // { // hpinc = 0; // } if(wave > 5 && spawnTime() && spawnsMade <= maxspawns) { wave = wave%5; //((tdpath)getWorld()). spawn(); spawnTimer = spawnTime; } } //right now randomly spawns units from 1-4, but will add a spawn of bosses for certain waves which will //be 5. private void spawn() { if(spawnsMade < maxspawns) { switch(wave) { case 1: { getWorld().addObject(new minion1(), 35, 100); spawnsMade++; spawnsAlive++; break; } case 2: { getWorld().addObject(new minion2(), 35, 100); spawnsMade++; spawnsAlive++; break; } case 3: { getWorld().addObject(new minion3(), 35, 100); spawnsMade++; spawnsAlive++; break; } case 4: { getWorld().addObject(new minion4(), 35, 100); spawnsMade++; spawnsAlive++; break; } case 5: { getWorld().addObject(new Boss(), 35, 100); spawnsMade++; spawnsAlive++; break; } } } } // put a method in here that counts how many spawns are left alive for starting the next wave when it's zero // or in the wave class private boolean spawnTime() { if(spawnTimer > 0) { spawnTimer--; } return spawnTimer == 0; } public int getSpawnsAlive() { return spawnsAlive; } public void setSpawnsAlive() { spawnsAlive --; } public boolean spawnedAll() { return spawnsMade == maxspawns; } public void setSpawnsMade() { spawnsMade = 0; } }
public class tdpath extends World { /**have to add a ui for a menu to buy towers, to show towers/their prices and * their abilities/stats. will have to add some music options so the player can * choose from a few different musics to listen to. will try to add sound effects * to tower attacks, and also need to add tower attacks. need to add damage to the * tower attacks that effects the spawn unit's health. will have to add health bars * for units spawned as well. will also have to make a wave function so more than * one wave is in the game, so that spawns can be done in certain orders. also so * that boss waves can be made. make sure to scale unit health to waves, so make * their health inc as the waves increase. * * after game is made and playable, think of a way to make it where towers can't * be placed on the path, unless towers interfere with spawning paths, then figure * it out while making the game. */ /** * Constructor for objects of class tdpath. * */ public Wave w = new Wave(); public minerals m = new minerals(w); public stopMusic s = new stopMusic(); public int mins; private long count = 0; private long lastSecond = 0; private int seconds = 20; private boolean timesUp = false; private fasttowerbutton f; private slowingtowerbutton sL; private damagetowerbutton dt; private splashtowerbutton st; private enemies E = new enemies();; private defenseSpot d; private LivesLeft life; private fasttower ft = new fasttower(); private slowingtower slowT = new slowingtower(); private damagetower damT = new damagetower(); private splashtower splashT = new splashtower(); private spawning spawn = new spawning(); private Timer time = new Timer(); public tdpath() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(1000, 600, 1); life = new LivesLeft(); d = new defenseSpot(life); f = new fasttowerbutton(ft); sL = new slowingtowerbutton(slowT, m); dt = new damagetowerbutton(damT, m); st = new splashtowerbutton(splashT); //addObject(new spawning(), 35, 100); addObject(spawn, 35, 100); addObject(d, 100, 580); addObject(life, 170, 550); addObject(f, 905, 107); addObject(sL, 905, 142); addObject(dt, 905, 174); addObject(st, 905, 207); addObject(m, 905, 63); addObject(w, 905, 21); addObject(new music1(), 905, 507); addObject(new music2(), 905, 539); addObject(new music3(), 905, 572); addObject(new stopMusic(), 905, 461); addObject(new buyingTowers(), 905, 260); addObject(new upgradingTowers(), 905, 400); addObject(new seeingRadius(), 905, 320); //addObject(new Timer(), 600, 580); } public void mineralsAdd(int mins) { m.addMinerals(mins); } public void mineralsSub(int mins) { m.subMinerals(mins); } public int getMins() { return m.getMinerals(); } public int getLifeTaken() { return E.getLivesLost(); } public void incSpawnHP() { double hp = E.getHealth(); E.setHealth(hp*1.5); } public int waveNum() { return w.getWaveNumber(); } public int getSpawnsAlive() { return spawn.getSpawnsAlive(); } public void killSpawn() { spawn.setSpawnsAlive(); } public boolean spawnsDone() { return spawn.spawnedAll(); } public void waveNumSet(int num) { w.setWaveNumber(num); } public void setSpawnsMade() { spawn.setSpawnsMade(); } public boolean timeUp() { return time.isTimeUp(); } public void getTimer() { addObject(time, 400, 100); } public void setTimer() { time.setTime(); } public void removeTime() { removeObject(time); } }
public class enemies extends Actor { /** * Act - do whatever the enemies wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ int x = 0; int y = 0; private int wave = 1; //get from wave class public double health; public int mins; public int lifeLost; public void act() { // Add your action code here. move(); // slowMove(); checkHealth(); } public double getHealth() { return health; } public void decHealth(int damage) { health = health - damage; checkHealth(); } public void setHealth(double hp) { health = hp; } public void checkHealth() { if (health <= 0) { //M.addMinerals(mins); ((tdpath)getWorld()).mineralsAdd(mins); ((tdpath)getWorld()).killSpawn(); ((tdpath)getWorld()).removeObject(this); } } public void move() { if(getWorld().getColorAt(getX()+1, getY()).getRed() < 10 && getWorld().getColorAt(getX()+1, getY()).getGreen() < 10 && x !=-1) { setLocation(getX() + 1,getY()); x = 1; y = 0; } else if(getWorld().getColorAt(getX()-1, getY()).getRed() < 10 && getWorld().getColorAt(getX()-1, getY()).getGreen() < 10 && x !=1) { setLocation(getX()-1, getY()); x = -1; y = 0; } else if(getWorld().getColorAt(getX(), getY()+1).getRed() < 10 && getWorld().getColorAt(getX(), getY()+1).getGreen() < 10 && y != -1) { setLocation(getX(), getY()+1); x = 0; y = 1; } else if(getWorld().getColorAt(getX(), getY()-1).getRed() < 10 && getWorld().getColorAt(getX(), getY()-1).getGreen() < 10 && y !=1) { setLocation(getX(), getY()-1); x = 0; y = -1; } } public void slowMove() { } public int getLivesLost() { return lifeLost; } }