From 0af96ee2fe841f2ccf27e3c77b0dd769f426165d Mon Sep 17 00:00:00 2001 From: Moksh Mehta Date: Tue, 3 Oct 2023 06:25:08 +1100 Subject: [PATCH] merged main into t3 brach --- .../csse3200/game/areas/ForestGameArea.java | 569 +++++++++++------- 1 file changed, 338 insertions(+), 231 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index 138e0e6d9..bf09242fc 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -2,30 +2,24 @@ import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.math.GridPoint2; -import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; + +import com.csse3200.game.areas.terrain.TerrainComponent; import com.csse3200.game.components.ProjectileEffects; import com.csse3200.game.areas.terrain.TerrainFactory; import com.csse3200.game.areas.terrain.TerrainFactory.TerrainType; -import com.csse3200.game.components.TouchAttackComponent; -import com.csse3200.game.components.player.PlayerStatsDisplay; +import com.csse3200.game.components.ProjectileEffects; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.factories.*; -import com.csse3200.game.physics.PhysicsLayer; import com.csse3200.game.utils.math.RandomUtils; import com.csse3200.game.services.ResourceService; -import com.csse3200.game.services.GameEndService; import com.csse3200.game.services.ServiceLocator; import com.csse3200.game.components.gamearea.GameAreaDisplay; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.security.SecureRandom; import java.util.Random; import java.util.Timer; - - -import static com.csse3200.game.entities.factories.NPCFactory.createGhost; - -import java.util.ArrayList; import java.util.TimerTask; /** Forest area for the demo game with trees, a player, and some enemies. */ @@ -37,8 +31,10 @@ public class ForestGameArea extends GameArea { private static final int NUM_BOSS = 4; - private static final int NUM_BOSSKING2=3; - private static final int NUM_BOSSKING1=1; + private static final int NUM_MOBBOSS2=3; + private static final int NUM_MOBBOSS1=1; + + private SecureRandom rand = new SecureRandom(); private int wave = 0; private Timer waveTimer; @@ -46,13 +42,13 @@ public class ForestGameArea extends GameArea { private Timer bossSpawnTimer; private int bossSpawnInterval = 10000; // 1 minute in milliseconds private static final int NUM_WEAPON_TOWERS = 3; - private static final GridPoint2 PLAYER_SPAWN = new GridPoint2(0, 0); + private static final GridPoint2 PLAYER_SPAWN = new GridPoint2(2, 4); // Temporary spawn point for testing private static final float WALL_WIDTH = 0.1f; - + // Required to load assets before using them private static final String[] forestTextures = { - "images/desert_bg.png", + "images/desert_bg.png", "images/ice_bg.png", "images/lava_bg.png", "images/projectiles/projectile.png", @@ -94,7 +90,6 @@ public class ForestGameArea extends GameArea { "images/towers/wallTower.png", "images/background/building2.png", "images/iso_grass_3.png", - "images/terrain_use.png", "images/Dusty_MoonBG.png", "images/economy/scrap.png", "images/economy/crystal.png", @@ -106,13 +101,27 @@ public class ForestGameArea extends GameArea { "images/projectiles/basic_projectile.png", "images/projectiles/mobProjectile.png", "images/projectiles/engineer_projectile.png", - "images/projectiles/mobKing_projectile.png", + "images/projectiles/mobBoss_projectile.png", "images/projectiles/snow_ball.png", "images/projectiles/burn_effect.png", "images/projectiles/stun_effect.png", "images/projectiles/firework_anim.png", "images/projectiles/pierce_anim.png", - "images/projectiles/snow_ball.png" + "images/projectiles/snow_ball.png", + "images/mobboss/demon.png", + "images/mobboss/demon2.png", + "images/mobs/fire_worm.png", + "images/mobboss/patrick.png", + "images/GrassTile/grass_tile_1.png", + "images/GrassTile/grass_tile_2.png", + "images/GrassTile/grass_tile_3.png", + "images/GrassTile/grass_tile_4.png", + "images/GrassTile/grass_tile_5.png", + "images/GrassTile/grass_tile_6.png", + "images/GrassTile/grass_tile_7.png", + "images/highlight_tile.png", + "images/mobboss/iceBaby.png" + }; private static final String[] forestTextureAtlases = { "images/economy/econ-tower.atlas", @@ -138,13 +147,22 @@ public class ForestGameArea extends GameArea { "images/projectiles/mobProjectile.atlas", "images/projectiles/mobProjectile.atlas", "images/projectiles/engineer_projectile.atlas", - "images/projectiles/mobKing_projectile.atlas", + "images/projectiles/mobBoss_projectile.atlas", "images/projectiles/snow_ball.atlas", "images/projectiles/pierce_anim.atlas", "images/projectiles/burn_effect.atlas", "images/projectiles/firework_anim.atlas", "images/projectiles/mobProjectile.atlas", - "images/projectiles/stun_effect.atlas" + "images/projectiles/stun_effect.atlas", + "images/mobboss/demon.atlas", + "images/mobs/fire_worm.atlas", + "images/mobs/dragon_knight.atlas", + "images/mobs/skeleton.atlas", + "images/mobs/wizard.atlas", + "images/mobs/water_queen.atlas", + "images/mobs/water_slime.atlas", + "images/mobboss/patrick.atlas", + "images/mobboss/iceBaby.atlas" }; private static final String[] forestSounds = { "sounds/Impact4.ogg", @@ -156,33 +174,63 @@ public class ForestGameArea extends GameArea { "sounds/engineers/firing_auto.mp3", "sounds/engineers/firing_single.mp3", "sounds/projectiles/on_collision.mp3", - "sounds/projectiles/explosion.mp3" + "sounds/projectiles/explosion.mp3", + "sounds/waves/wave-start/Wave_Start_Alarm.ogg", + "sounds/waves/wave-end/Wave_Over_01.ogg", + "sounds/mobBoss/iceBabySound.mp3", + "sounds/mobBoss/mobSpawnStomp.mp3", + "sounds/mobBoss/iceBabyAOE.mp3", + "sounds/mobs/wizardSpell.mp3", + "sounds/mobs/waterQueenSpell.mp3", + "sounds/mobs/boneBreak.mp3", + "sounds/mobs/fireWormRoar.mp3", + "sounds/mobBoss/demonBreath.mp3", + "sounds/mobBoss/demonSpawn.wav", + "sounds/mobBoss/demonAttack.wav", + "sounds/mobBoss/demonBreathIn.mp3", + "sounds/mobBoss/demonLand.mp3", + "sounds/mobBoss/demonJump.mp3", + "sounds/mobBoss/demonHeal.mp3", + "sounds/mobBoss/demonCleave.mp3", + "sounds/mobBoss/demonDeath.mp3", + "sounds/mobBoss/slimeySplat.mp3", + "sounds/mobBoss/slimeJump.mp3", + "sounds/mobBoss/slimePop.mp3", + "sounds/mobBoss/patrickAttack.mp3", + "sounds/mobBoss/patrickAppear.mp3", + "sounds/mobBoss/patrickScream.mp3", + "sounds/mobBoss/patrickSpell.mp3", + "sounds/mobBoss/patrickSpawn.mp3", + "sounds/mobBoss/patrickCast.mp3", + "sounds/mobBoss/patrickThunder.mp3", + "sounds/mobBoss/patrickHit.mp3" }; private static final String backgroundMusic = "sounds/background/Sci-Fi1.ogg"; private static final String[] forestMusic = {backgroundMusic}; - - private final TerrainFactory terrainFactory; - + +// private final TerrainFactory terrainFactory; + private Entity player; - + private Entity waves; + // Variables to be used with spawn projectile methods. This is the variable // that should occupy the direction param. private static final int towardsMobs = 100; - private Entity bossKing2; - private Entity bossKing1; + private Entity mobBoss2; + private Entity mobBoss1; /** * Initialise this ForestGameArea to use the provided TerrainFactory. * - * @param terrainFactory TerrainFactory used to create the terrain for the GameArea. * @requires terrainFactory != null */ - public ForestGameArea(TerrainFactory terrainFactory) { + public ForestGameArea() { super(); - this.terrainFactory = terrainFactory; } - // Add this method to start the wave spawning timer when the game starts. + /** + * Add this method to start the wave spawning timer when the game starts. + */ private void startWaveTimer() { waveTimer = new Timer(); waveTimer.scheduleAtFixedRate(new TimerTask() { @@ -193,7 +241,9 @@ public void run() { }, 0, 10000); // 10000 milliseconds = 10 seconds } - // Add this method to stop the wave timer when the game ends or as needed. + /** + * Add this method to stop the wave timer when the game ends or as needed. + */ private void stopWaveTimer() { if (waveTimer != null) { waveTimer.cancel(); @@ -201,19 +251,37 @@ private void stopWaveTimer() { } } + /** + * Cases to spawn a wave + */ private void spawnWave() { wave++; switch (wave) { case 1: case 2: - spawnXenoGrunts(); + spawnWaterQueen(); + spawnWizard(); + logger.info("Lol"); + break; case 3: - bossKing2 = spawnBossKing2(); + spawnWaterSlime(); + spawnIceBaby(); + logger.info("Lol"); + // mobBoss2 = spawnMobBoss2(); break; case 4: - bossKing2 = spawnBossKing2(); + spawnFireWorm(); + // spawnDragonKnight(); + logger.info("Lol"); + // mobBoss2 = spawnMobBoss2(); break; + case 5: + case 6: + spawnSkeleton(); + case 7: + spawnDemonBoss(); + spawnPatrick(); default: // Handle other wave scenarios if needed break; @@ -228,39 +296,28 @@ private void spawnWave() { public void create() { // Load game assets loadAssets(); + logger.info("Lol"); displayUI(); + logger.info("Lol"); spawnTerrain(); - + logger.info("Lol"); + // Set up infrastructure for end game tracking - player = spawnPlayer(); - player.getEvents().addListener("spawnWave", this::spawnXenoGrunts); - +// player = spawnPlayer(); + + waves = WaveFactory.createWaves(); + spawnEntity(waves); + waves.getEvents().addListener("spawnWave", this::spawnMob); + playMusic(); - - // Types of projectile -// spawnAoeProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f), 1); - spawnProjectile(new Vector2(0, 10), PhysicsLayer.NPC, towardsMobs, new Vector2(2f, 2f)); - spawnMultiProjectile(new Vector2(0, 10), PhysicsLayer.NPC, towardsMobs, 20, new Vector2(2f, 2f), 7); - spawnEffectProjectile(new Vector2(0, 10), PhysicsLayer.HUMANS, towardsMobs, new Vector2(2f, 2f), ProjectileEffects.BURN, true); - spawnPierceFireBall(new Vector2(2, 3), PhysicsLayer.NPC, towardsMobs, new Vector2(2f, 2f)); - spawnRicochetFireball(new Vector2(2, 4), PhysicsLayer.NPC, towardsMobs, new Vector2(2f, 2f)); - spawnSplitFireWorksFireBall(new Vector2(2, 5), PhysicsLayer.NPC, towardsMobs, new Vector2(2f, 2f), 12); - spawnEffectProjectile(new Vector2(2, 6), PhysicsLayer.NPC, towardsMobs, new Vector2(2f, 2f), ProjectileEffects.SLOW, false); - spawnXenoGrunts(); - spawnWeaponTower(); - //bossKing1 = spawnBossKing1(); - startWaveTimer(); -// spawnIncome(); spawnScrap(); spawnTNTTower(); - + //spawnWeaponTower(); spawnGapScanners(); spawnDroidTower(); - bossKing2 = spawnBossKing2(); - } - + private void displayUI() { Entity ui = new Entity(); ui.addComponent(new GameAreaDisplay("Box Forest")); @@ -268,21 +325,23 @@ private void displayUI() { ui.addComponent(ServiceLocator.getCurrencyService().getDisplay()); spawnEntity(ui); } - + private void spawnTerrain() { - // Background terrain - terrain = terrainFactory.createTerrain(TerrainType.FOREST_DEMO); - spawnEntity(new Entity().addComponent(terrain)); - + + terrain = ServiceLocator.getMapService().getComponent(); + spawnEntity(ServiceLocator.getMapService().getEntity()); + // Terrain walls float tileSize = terrain.getTileSize(); GridPoint2 tileBounds = terrain.getMapBounds(0); Vector2 worldBounds = new Vector2(tileBounds.x * tileSize, tileBounds.y * tileSize); - + // Left - // ! THIS ONE DOESNT WORK. GRIDPOINTS2UTIL.ZERO is (0, 4), not (0, 0) spawnEntityAt( - ObstacleFactory.createWall(WALL_WIDTH, worldBounds.y), new GridPoint2(1, 0), false, false); + ObstacleFactory.createWall(WALL_WIDTH, worldBounds.y), + new GridPoint2(0, 2), + false, + false); // Right spawnEntityAt( ObstacleFactory.createWall(WALL_WIDTH, worldBounds.y), @@ -292,76 +351,35 @@ private void spawnTerrain() { // Top spawnEntityAt( ObstacleFactory.createWall(worldBounds.x, WALL_WIDTH * 7), - new GridPoint2(0, tileBounds.y - 1), + new GridPoint2(0, tileBounds.y), false, false); // Bottom - // spawnEntityAt( - // ObstacleFactory.createWall(worldBounds.x, WALL_WIDTH), GridPoint2Utils.ZERO, false, false); - // * TMPORARY spawnEntityAt( - ObstacleFactory.createWall(worldBounds.x, WALL_WIDTH * 7), new GridPoint2(0, 0), false, false); + ObstacleFactory.createWall(worldBounds.x, WALL_WIDTH ), + new GridPoint2(0, 2), + false, + false); } -// private void spawnBuilding1() { -// GridPoint2 minPos = new GridPoint2(0, 0); -// GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); -// -// for (int i = 0; i < NUM_BUILDINGS; i++) { -// GridPoint2 randomPos = RandomUtils.random(minPos, maxPos); -// Entity building1 = ObstacleFactory.createBuilding1(); -// spawnEntityAt(building1, randomPos, true, false); -// } -// } -// private void spawnBuilding2() { -// GridPoint2 minPos = new GridPoint2(0, 0); -// GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); -// -// for (int i = 0; i < NUM_BUILDINGS; i++) { -// GridPoint2 randomPos = RandomUtils.random(minPos, maxPos); -// Entity building2 = ObstacleFactory.createBuilding2(); -// spawnEntityAt(building2, randomPos, true, false); -// } -// } -// private void spawnMountains() { -// ArrayList fixedPositions = new ArrayList<>(); //Generating ArrayList -// -// fixedPositions.add(new GridPoint2(5, 8)); -// fixedPositions.add(new GridPoint2(12, 4)); -// fixedPositions.add(new GridPoint2(20, 10)); -// fixedPositions.add(new GridPoint2(33, 17)); -// -// for (GridPoint2 fixedPos : fixedPositions) { -// Entity tree = ObstacleFactory.createMountain(); -// spawnEntityAt(tree, fixedPos, true, false); -// } -// for (int i = 0; i < NUM_BUILDINGS; i++) { -// GridPoint2 randomPos = RandomUtils.random(minPos, maxPos); -// Entity building1 = ObstacleFactory.createBuilding1(); -// spawnEntityAt(building1, randomPos, true, false); -// } -// } - private void spawnBuilding2() { GridPoint2 minPos = new GridPoint2(0, 0); GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); - + for (int i = 0; i < NUM_BUILDINGS; i++) { GridPoint2 randomPos = RandomUtils.random(minPos, maxPos); Entity building2 = ObstacleFactory.createBuilding2(); spawnEntityAt(building2, randomPos, true, false); } } - - + private Entity spawnPlayer() { Entity newPlayer = PlayerFactory.createPlayer(); spawnEntityAt(newPlayer, PLAYER_SPAWN, true, true); - newPlayer.addComponent(new TouchAttackComponent(PhysicsLayer.NPC)); return newPlayer; } - + // Spawn player at a specific position private Entity spawnPlayer(GridPoint2 position) { Entity newPlayer = PlayerFactory.createPlayer(); @@ -369,44 +387,26 @@ private Entity spawnPlayer(GridPoint2 position) { return newPlayer; } -// private void spawnGhosts() { -// GridPoint2 minPos = new GridPoint2(0, 0); -// GridPoint2 maxPos = terrain.getMapBounds(0).sub(0, 2); -// -// for (int i = 0; i < NUM_GHOSTS; i++) { -// int fixedX = terrain.getMapBounds(0).x - 1; // Rightmost x-coordinate -// int randomY = MathUtils.random(0, maxPos.y); -// GridPoint2 randomPos = new GridPoint2(fixedX, randomY); -// Entity ghost = createGhost(player); -// spawnEntityAt(ghost, randomPos, true, true); -// } -// } -// private Entity spawnBossKing1() { -// GridPoint2 minPos = new GridPoint2(0, 0); -// GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); -// GridPoint2 randomPos -// = new GridPoint2(0, 0); -// Entity ghostKing = NPCFactory.createGhostKing(player); -// spawnEntityAt(ghostKing, randomPos, true, true); -// return ghostKing; -// } + private void spawnDemonBoss() { + Entity demon = MobBossFactory.createDemonBoss(); + spawnEntityAt(demon, new GridPoint2(19, 5), true, false); + } + private void spawnPatrick() { + Entity patrick = MobBossFactory.createPatrickBoss(3000); + spawnEntityAt(patrick, new GridPoint2(18, 5), true, false); + } - private Entity spawnBossKing1() { - int[] pickedLanes = new Random().ints(0, 8) - .distinct().limit(5).toArray(); - for (int i = 0; i < NUM_BOSSKING1; i++) { - GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]); - bossKing1 = BossKingFactory.createBossKing1(player, pickedLanes[i]); - spawnEntityAt(bossKing1, - randomPos, - true, - false); - } - return bossKing1; + private void spawnPatrickDeath() { + Entity patrickDeath = MobBossFactory.patrickDead(); + spawnEntityAt(patrickDeath, new GridPoint2(18, 5), true, false); } + private void spawnIceBaby() { + Entity iceBaby = MobBossFactory.createIceBoss(); + spawnEntityAt(iceBaby, new GridPoint2(19, 5), true, false); + } /** * Spawns a projectile that only heads towards the enemies in its lane. @@ -421,7 +421,7 @@ private void spawnProjectile(Vector2 position, short targetLayer, int direction, Projectile.setPosition(position); spawnEntity(Projectile); } - + /** * Spawns a projectile specifically for general mobs/xenohunters * @@ -435,7 +435,7 @@ private void spawnProjectileTest(Vector2 position, short targetLayer, int direct Projectile.setPosition(position); spawnEntity(Projectile); } - + /** * Spawns a projectile to be used for multiple projectile function. * @@ -451,35 +451,158 @@ private void spawnProjectile(Vector2 position, short targetLayer, int space, int spawnEntity(Projectile); } + /** + * Spawn an entity on the map. Is called during a wave. Add cases here for each mob type + * @param entity mob to be spawned + * @param randomPos position to be spawned at + */ + public void spawnMob(String entity, GridPoint2 randomPos) { + Entity mob; + switch (entity) { + case "Xeno": + mob = NPCFactory.createXenoGrunt(); + break; + case "SplittingWaterSlime": + mob = NPCFactory.createSplittingWaterSlime(); + break; + case "DodgingDragon": + mob = NPCFactory.createDodgingDragonKnight(); + break; + case "DeflectWizard": + mob = NPCFactory.createDeflectWizard(); + break; + case "WaterQueen": + mob = NPCFactory.createWaterQueen(); + break; + case "FireWorm": + mob = NPCFactory.createFireWorm(); + break; + case "Skeleton": + mob = NPCFactory.createSkeleton(); + break; + case "IceBoss": + mob = MobBossFactory.createIceBoss(); + break; + case "DemonBoss": + mob = MobBossFactory.createDemonBoss(); + break; + case "PatrickBoss": + mob = MobBossFactory.createPatrickBoss(100); + break; + default: + mob = NPCFactory.createXenoGrunt(); + } + if (entity.contains("Boss")) { + mob.scaleHeight(5f); + mob.scaleWidth(5f); + } else { + mob.setScale(1.5f, 1.5f); + } + spawnEntityAt(mob, randomPos, true, false); + } + + // * TEMPORARY FOR TESTING + // private void spawnSplittingXenoGrunt(int x, int y) { + // GridPoint2 pos = new GridPoint2(x, y); + // Entity xenoGrunt = NPCFactory.createSplittingXenoGrunt(); + // xenoGrunt.setScale(1.5f, 1.5f); + // spawnEntityAt(xenoGrunt, pos, true, true); + // } + + // * TEMPORARY FOR TESTING + private void spawnDodgingDragonKnight(int x, int y) { + GridPoint2 pos = new GridPoint2(x, y); + Entity fireworm = NPCFactory.createDodgingDragonKnight(); + fireworm.setScale(1.5f, 1.5f); + spawnEntityAt(fireworm, pos, true, true); + } + + // * TEMPORARY FOR TESTING + private void spawnDeflectWizard(int x, int y) { + GridPoint2 pos = new GridPoint2(x, y); + Entity xenoGrunt = NPCFactory.createDeflectWizard(); + xenoGrunt.setScale(1.5f, 1.5f); + spawnEntityAt(xenoGrunt, pos, true, true); + } + + private void spawnFireWorm() { + + int[] pickedLanes = rand.ints(0, ServiceLocator.getMapService().getHeight() ) + + .distinct().limit(5).toArray(); + for (int i = 0; i < NUM_GRUNTS; i++) { + GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]); + Entity fireWorm = NPCFactory.createFireWorm(); + fireWorm.setScale(1.5f, 1.5f); + spawnEntityAt(fireWorm, randomPos, true, false); + } + } + + private void spawnSkeleton() { + + int[] pickedLanes = new Random().ints(0, ServiceLocator.getMapService().getHeight() ) + .distinct().limit(5).toArray(); + for (int i = 0; i < NUM_GRUNTS; i++) { + GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]); + Entity skeleton = NPCFactory.createSkeleton(); + skeleton.setScale(1.5f, 1.5f); + spawnEntityAt(skeleton, randomPos, true, false); + } + } + + private void spawnDragonKnight() { + + int[] pickedLanes = rand.ints(0, ServiceLocator.getMapService().getHeight() ) + + .distinct().limit(5).toArray(); + for (int i = 0; i < NUM_GRUNTS; i++) { + GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]); + Entity fireWorm = NPCFactory.createDodgingDragonKnight(); + fireWorm.setScale(1.5f, 1.5f); + spawnEntityAt(fireWorm, randomPos, true, false); + } + } + + private void spawnWizard() { + + int[] pickedLanes = rand.ints(0, ServiceLocator.getMapService().getHeight() ) + + .distinct().limit(5).toArray(); + for (int i = 0; i < NUM_GRUNTS; i++) { + GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]); + Entity wizard = NPCFactory.createDeflectWizard(); + wizard.setScale(1.5f, 1.5f); + spawnEntityAt(wizard, randomPos, true, false); + } + } + + private void spawnWaterQueen() { + + int[] pickedLanes = new Random().ints(0, ServiceLocator.getMapService().getHeight() ) + + .distinct().limit(5).toArray(); + for (int i = 0; i < NUM_GRUNTS; i++) { + GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]); + Entity waterQueen = NPCFactory.createWaterQueen(); + waterQueen.setScale(1.5f, 1.5f); + spawnEntityAt(waterQueen, randomPos, true, false); + } + } + + private void spawnWaterSlime() { + + int[] pickedLanes = new Random().ints(0, ServiceLocator.getMapService().getHeight() ) -// private Entity spawnBossKing() { -// for (int i = 0; i < NUM_BOSS; i++) { -// int fixedX = terrain.getMapBounds(0).x - 1; // Rightmost x-coordinate -// int randomY = MathUtils.random(0, maxPos.y); -// GridPoint2 randomPos = new GridPoint2(fixedX, randomY); -// bossKing1 = BossKingFactory.createBossKing1(player); -// spawnEntityAt(bossKing1, -// randomPos, -// true, -// false); -// } -// return bossKing1; -// -// } - - - private void spawnXenoGrunts() { - int[] pickedLanes = new Random().ints(1, 7) .distinct().limit(5).toArray(); for (int i = 0; i < NUM_GRUNTS; i++) { GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]); - System.out.println(randomPos); - Entity xenoGrunt = NPCFactory.createXenoGrunt(player); - xenoGrunt.setScale(1.5f, 1.5f); - spawnEntityAt(xenoGrunt, randomPos, true, false); + Entity waterSlime = NPCFactory.createSplittingWaterSlime(); + waterSlime.setScale(1.5f, 1.5f); + spawnEntityAt(waterSlime, randomPos, true, false); } } + // private Entity spawnGhostKing() { // GridPoint2 minPos = new GridPoint2(0, 0); // GridPoint2 maxPos = terrain.getMapBounds(0).sub(0, 0); @@ -492,37 +615,6 @@ private void spawnXenoGrunts() { // // } -// private Entity spawnBossKing2() { -// GridPoint2 minPos = new GridPoint2(0, 0); -// GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); -// -// for (int i = 0; i < NUM_BOSS; i++) { -// int fixedX = terrain.getMapBounds(0).x - 1; // Rightmost x-coordinate -// int randomY = MathUtils.random(0, maxPos.y); -// GridPoint2 randomPos = new GridPoint2(fixedX, randomY); -// bossKing2 = BossKingFactory.createBossKing2(player); -// spawnEntityAt(bossKing2, -// randomPos, -// true, -// false); -// } -// return bossKing2; -// } - - private Entity spawnBossKing2() { - int[] pickedLanes = new Random().ints(0, 8) - .distinct().limit(5).toArray(); - for (int i = 0; i < NUM_BOSSKING2; i++) { - GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]); - bossKing2 = BossKingFactory.createBossKing2(player); - spawnEntityAt(bossKing2, - randomPos, - true, - false); - } - return bossKing2; - } - /** * Creates multiple projectiles that travel simultaneous. They all have same * the starting point but different destinations. @@ -541,7 +633,7 @@ private void spawnMultiProjectile(Vector2 position, short targetLayer, int direc --half; } } - + /** * Returns projectile that can do an area of effect damage * @@ -558,7 +650,7 @@ private void spawnEffectProjectile(Vector2 position, short targetLayer, int dire Projectile.setPosition(position); spawnEntity(Projectile); } - + /** * Spawns a pierce fireball. * Pierce fireball can go through targetlayers without disappearing but damage @@ -574,7 +666,7 @@ private void spawnPierceFireBall(Vector2 position, short targetLayer, int direct projectile.setPosition(position); spawnEntity(projectile); } - + /** * Spawns a ricochet fireball * Ricochet fireballs bounce off targets with a specified maximum count of 3 @@ -591,14 +683,14 @@ private void spawnRicochetFireball(Vector2 position, short targetLayer, int dire projectile.setPosition(position); spawnEntity(projectile); } - + /** * Spawns a split firework fireball. * Splits into mini projectiles that spreads out after collision. * * @param position The position of the Entity that's shooting the projectile. * @param targetLayer The enemy layer of the "shooter". - * @param direction The direction the projectile should head towards. + * @param direction The direction the projectile should towards. * @param speed The speed of the projectiles. * @param amount The amount of projectiles appearing after collision. */ @@ -607,12 +699,13 @@ private void spawnSplitFireWorksFireBall(Vector2 position, short targetLayer, in projectile.setPosition(position); spawnEntity(projectile); } - + + private void spawnWeaponTower() { GridPoint2 minPos = new GridPoint2(0, 0); - GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); - - for (int i = 0; i < NUM_WEAPON_TOWERS; i++) { + GridPoint2 maxPos = terrain.getMapBounds(0).sub(5, 1); + + for (int i = 0; i < NUM_WEAPON_TOWERS + 7 ; i++) { GridPoint2 randomPos1 = RandomUtils.random(minPos, maxPos); GridPoint2 randomPos2 = RandomUtils.random(minPos, maxPos); Entity wallTower = TowerFactory.createWallTower(); @@ -622,38 +715,52 @@ private void spawnWeaponTower() { spawnEntityAt(stunTower, randomPos2, true, true); } } - + + // * TEMPORARY FOR TESTING + private void spawnFireTowerTowerAt(int x, int y) { + GridPoint2 pos = new GridPoint2(x, y); + Entity fireTower = TowerFactory.createFireTower(); + + spawnEntityAt(fireTower, pos, true, true); + } + private void spawnDroidTowerAt(int x, int y) { + GridPoint2 pos = new GridPoint2(x, y); + Entity droidTower = TowerFactory.createDroidTower(); + + spawnEntityAt(droidTower, pos, true, true); + } + private void spawnTNTTower() { GridPoint2 minPos = new GridPoint2(0, 0); - GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); - - for (int i = 0; i < NUM_WEAPON_TOWERS; i++) { + GridPoint2 maxPos = terrain.getMapBounds(0).sub(5, 1); + + for (int i = 0; i < NUM_WEAPON_TOWERS + 5; i++) { GridPoint2 randomPos = RandomUtils.random(minPos, maxPos); Entity weaponTower = TowerFactory.createTNTTower(); spawnEntityAt(weaponTower, randomPos, true, true); } - + } private void spawnDroidTower() { GridPoint2 minPos = new GridPoint2(0, 0); - GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); + GridPoint2 maxPos = terrain.getMapBounds(0).sub(5, 1); - for (int i = 0; i < NUM_WEAPON_TOWERS; i++) { + for (int i = 0; i < NUM_WEAPON_TOWERS + 5; i++) { GridPoint2 randomPos = RandomUtils.random(minPos, maxPos); Entity weaponTower = TowerFactory.createDroidTower(); - spawnEntityAt(weaponTower, randomPos, true, true); + spawnEntityAt(weaponTower, randomPos, true, false); } } - - + + private void playMusic() { Music music = ServiceLocator.getResourceService().getAsset(backgroundMusic, Music.class); music.setLooping(true); music.setVolume(0.3f); music.play(); } - + private void loadAssets() { logger.debug("Loading assets"); ResourceService resourceService = ServiceLocator.getResourceService(); @@ -661,13 +768,13 @@ private void loadAssets() { resourceService.loadTextureAtlases(forestTextureAtlases); resourceService.loadSounds(forestSounds); resourceService.loadMusic(forestMusic); - + while (!resourceService.loadForMillis(10)) { // This could be upgraded to a loading screen logger.info("Loading... {}%", resourceService.getProgress()); } } - + private void unloadAssets() { logger.debug("Unloading assets"); ResourceService resourceService = ServiceLocator.getResourceService(); @@ -676,7 +783,7 @@ private void unloadAssets() { resourceService.unloadAssets(forestSounds); resourceService.unloadAssets(forestMusic); } - + @Override public void dispose() { super.dispose(); @@ -684,28 +791,28 @@ public void dispose() { this.unloadAssets(); stopWaveTimer(); } - + private void spawnScrap() { GridPoint2 minPos = new GridPoint2(0, 0); GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); - + for (int i = 0; i < 5; i++) { GridPoint2 randomPos = RandomUtils.random(minPos, maxPos); Entity scrap = DropFactory.createScrapDrop(); spawnEntityAt(scrap, randomPos, true, false); } - + for (int i = 0; i < 5; i++) { GridPoint2 randomPos = RandomUtils.random(minPos, maxPos); Entity crystal = DropFactory.createCrystalDrop(); spawnEntityAt(crystal, randomPos, true, false); } } - + private void spawnIncome() { GridPoint2 minPos = new GridPoint2(0, 0); GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); - + for (int i = 0; i < 50; i++) { GridPoint2 randomPos = RandomUtils.random(minPos, maxPos); Entity towerfactory = TowerFactory.createIncomeTower();