Skip to content

Commit

Permalink
Merge pull request #148 from UQcsse3200/Team-2--Engineers-Praneet
Browse files Browse the repository at this point in the history
Team-2--Engineers-Praneet
  • Loading branch information
The-AhmadAA authored Sep 12, 2023
2 parents ddf01ed + 8904c88 commit 172c9fb
Show file tree
Hide file tree
Showing 4 changed files with 296 additions and 104 deletions.
112 changes: 56 additions & 56 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public class ForestGameArea extends GameArea {
private static final int NUM_GHOSTS = 0;
private static final int NUM_GRUNTS = 5;
private static final int NUM_BOSS = 4;


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);
// 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 = {

Expand Down Expand Up @@ -145,17 +145,17 @@ public class ForestGameArea extends GameArea {
};
private static final String backgroundMusic = "sounds/background/Sci-Fi1.ogg";
private static final String[] forestMusic = {backgroundMusic};

private final TerrainFactory terrainFactory;

private Entity player;

// 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;


/**
* Initialise this ForestGameArea to use the provided TerrainFactory.
*
Expand All @@ -166,7 +166,7 @@ public ForestGameArea(TerrainFactory terrainFactory) {
super();
this.terrainFactory = terrainFactory;
}

/**
* Create the game area, including terrain, static entities (trees), dynamic entities (player)
*/
Expand All @@ -179,13 +179,13 @@ public void create() {
// spawnBuilding1();
// spawnBuilding2();
// spawnMountains();

// Set up infrastructure for end game tracking
player = spawnPlayer();
player.getEvents().addListener("spawnWave", this::spawnXenoGrunts);

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));
Expand All @@ -206,28 +206,28 @@ public void create() {
// spawnGapScanners();
// bossKing1 = spawnBossKing1();
// bossKing2 = spawnBossKing2();

bossKing2 = spawnBossKing2();
}

private void displayUI() {
Entity ui = new Entity();
ui.addComponent(new GameAreaDisplay("Box Forest"));
ui.addComponent(ServiceLocator.getGameEndService().getDisplay());
ui.addComponent(ServiceLocator.getCurrencyService().getDisplay());
spawnEntity(ui);
}

private void spawnTerrain() {
// Background terrain
terrain = terrainFactory.createTerrain(TerrainType.FOREST_DEMO);
spawnEntity(new Entity().addComponent(terrain));

// 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(
Expand Down Expand Up @@ -291,26 +291,26 @@ private void spawnTerrain() {
// 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();
Expand Down Expand Up @@ -340,7 +340,7 @@ private Entity spawnPlayer(GridPoint2 position) {
// spawnEntityAt(ghostKing, randomPos, true, true);
// return ghostKing;
// }

/**
* Spawns a projectile that only heads towards the enemies in its lane.
*
Expand All @@ -354,7 +354,7 @@ private void spawnProjectile(Vector2 position, short targetLayer, int direction,
Projectile.setPosition(position);
spawnEntity(Projectile);
}

/**
* Spawns a projectile specifically for general mobs/xenohunters
*
Expand All @@ -368,7 +368,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.
*
Expand Down Expand Up @@ -399,8 +399,8 @@ private void spawnProjectile(Vector2 position, short targetLayer, int space, int
// return bossKing1;
//
// }


private void spawnXenoGrunts() {
int[] pickedLanes = new Random().ints(1, 7)
.distinct().limit(5).toArray();
Expand Down Expand Up @@ -441,11 +441,11 @@ private void spawnXenoGrunts() {
// }
// return bossKing2;
// }

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);
Expand All @@ -458,7 +458,7 @@ private Entity spawnBossKing2() {
}
return bossKing2;
}

/**
* Creates multiple projectiles that travel simultaneous. They all have same
* the starting point but different destinations.
Expand All @@ -477,7 +477,7 @@ private void spawnMultiProjectile(Vector2 position, short targetLayer, int direc
--half;
}
}

/**
* Returns projectile that can do an area of effect damage
*
Expand All @@ -494,7 +494,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
Expand All @@ -510,7 +510,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
Expand All @@ -527,7 +527,7 @@ 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.
Expand All @@ -543,11 +543,11 @@ 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 randomPos1 = RandomUtils.random(minPos, maxPos);
GridPoint2 randomPos2 = RandomUtils.random(minPos, maxPos);
Expand All @@ -558,41 +558,41 @@ private void spawnWeaponTower() {
spawnEntityAt(stunTower, randomPos2, 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 randomPos = RandomUtils.random(minPos, maxPos);
Entity weaponTower = TowerFactory.createTNTTower();
spawnEntityAt(weaponTower, randomPos, true, true);
}

}


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();
resourceService.loadTextures(forestTextures);
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();
Expand All @@ -601,53 +601,53 @@ private void unloadAssets() {
resourceService.unloadAssets(forestSounds);
resourceService.unloadAssets(forestMusic);
}

@Override
public void dispose() {
super.dispose();
ServiceLocator.getResourceService().getAsset(backgroundMusic, Music.class).stop();
this.unloadAssets();
}

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();
spawnEntityAt(towerfactory, randomPos, true, true);
}
}

private void spawnEngineer() {
for (int i = 0; i < terrain.getMapBounds(0).x; i += 3) {
Entity engineer = EngineerFactory.createEngineer();
spawnEntityAt(engineer, new GridPoint2(1, i), true, true);
}
}

/**
* Creates the scanners (one per lane) that detect absence of towers and presence of mobs,
* and trigger engineer spawning
*/
/**
* Creates the scanners (one per lane) that detect absence of towers and presence of mobs,
* and trigger engineer spawning
*/
// private void spawnGapScanners() {
// for (int i = 0; i < terrain.getMapBounds(0).y; i++) {
// Entity scanner = GapScannerFactory.createScanner();
Expand Down
Loading

0 comments on commit 172c9fb

Please sign in to comment.