Skip to content

Commit

Permalink
added saveable component functions for spawner and enemies
Browse files Browse the repository at this point in the history
  • Loading branch information
Kintaro Kawai authored and Kintaro Kawai committed Oct 19, 2023
1 parent 24fdba9 commit 259e290
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 4 deletions.
16 changes: 16 additions & 0 deletions source/core/assets/levels/earth/main_area/entities/spawners.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
class: com.csse3200.game.entities.configs.SpawnerConfig,
"wave1" : {
<<<<<<< Updated upstream
"roboMan" : 5,
"redGhost" : 5,
"chain": 0
Expand All @@ -17,6 +18,21 @@
"roboMan" : 10,
"redGhost" : 10,
"chain": 0
=======
"necromancer" : 1,
"roboMan" : 1,
"chain" : 1
},
"wave2" : {
"redGhost" : 1,
"roboMan" : 1,
"necromancer" : 1
},
"wave3" : {
"roboMan" : 1,
"necromancer" : 1,
"Knight" : 1
>>>>>>> Stashed changes
},
"position": {
"x": 1,
Expand Down
13 changes: 13 additions & 0 deletions source/core/src/main/com/csse3200/game/areas/MapGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void create() {
spawnTutnpc();
spawnHellman();
spawnSpawners();
spawnEnemies();
spawnJail();

spawnAstronaut();
Expand Down Expand Up @@ -503,6 +504,18 @@ private void spawnSpawners() {
}
}

/**
* Spawns all the spawners detailed in the Game Area.
*/
private void spawnEnemies() {
if (mapConfig.areaEntityConfig == null) return;

for (EnemyConfig enemyConfig : mapConfig.areaEntityConfig.getEntities(EnemyConfig.class)) {
Entity enemy = EnemyFactory.createEnemy(enemyConfig);
spawnEntityAt(enemy, enemyConfig.position, true, true);
}
}

/**
* Spawns the botanist NPC at the position given in the config file
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,112 @@ public void spawnEnemy(EnemyName name) {
Entity enemy = EnemyFactory.createEnemy(name);
ServiceLocator.getStructurePlacementService().spawnEntityAtVector(enemy, worldPos);
}

public LinkedHashMap<String, Integer> getWave1() {
LinkedHashMap<String, Integer> currentWaveContents = new LinkedHashMap<>();

EnemyName name;
int count;

for (Map.Entry<String, Integer> entry : config.wave1.entrySet()) {
name = EnemyName.getEnemyName(entry.getKey());
count = entry.getValue();
if (currentWave == 0) {
if (enemyType1.equals(name)) {
currentWaveContents.put(name.toString(), enemyType1ToSpawn);
}
if (enemyType2.equals(name)) {
currentWaveContents.put(name.toString(), enemyType2ToSpawn);
}
if (enemyType3.equals(name)) {
currentWaveContents.put(name.toString(), enemyType3ToSpawn);
}
}
if (currentWave > 0) {
currentWaveContents.put(name.toString(), 0);
}
}
return currentWaveContents;
}

public LinkedHashMap<String, Integer> getWave2() {
LinkedHashMap<String, Integer> currentWaveContents = new LinkedHashMap<>();

EnemyName name;
int count;

for (Map.Entry<String, Integer> entry : config.wave2.entrySet()) {
name = EnemyName.getEnemyName(entry.getKey());
count = entry.getValue();
if (currentWave == 1) {
if (enemyType1 == null) {
currentWaveContents.put(name.toString(), count);
} else if (enemyType1.equals(name)) {
currentWaveContents.put(name.toString(), enemyType1ToSpawn);
} else {
currentWaveContents.put(name.toString(), count);
}
if (enemyType2 == null) {
currentWaveContents.put(name.toString(), count);
} else if (enemyType2.equals(name)) {
currentWaveContents.put(name.toString(), enemyType2ToSpawn);
} else {
currentWaveContents.put(name.toString(), count);
}
if (enemyType3 == null) {
currentWaveContents.put(name.toString(), count);
} else if (enemyType3.equals(name)) {
currentWaveContents.put(name.toString(), enemyType3ToSpawn);
} else {
currentWaveContents.put(name.toString(), count);
}
}
if (currentWave < 1) {
currentWaveContents.put(name.toString(), count);
}
if (currentWave > 1) {
currentWaveContents.put(name.toString(), 0);
}
}
return currentWaveContents;
}

public LinkedHashMap<String, Integer> getWave3() {
LinkedHashMap<String, Integer> currentWaveContents = new LinkedHashMap<>();

EnemyName name;
int count;

for (Map.Entry<String, Integer> entry : config.wave3.entrySet()) {
name = EnemyName.getEnemyName(entry.getKey());
count = entry.getValue();
if (currentWave == 2) {
if (enemyType1 == null) {
currentWaveContents.put(name.toString(), count);
} else if (enemyType1.equals(name)) {
currentWaveContents.put(name.toString(), enemyType1ToSpawn);
} else {
currentWaveContents.put(name.toString(), count);
}
if (enemyType2 == null) {
currentWaveContents.put(name.toString(), count);
} else if (enemyType2.equals(name)) {
currentWaveContents.put(name.toString(), enemyType2ToSpawn);
} else {
currentWaveContents.put(name.toString(), count);
}
if (enemyType3 == null) {
currentWaveContents.put(name.toString(), count);
} else if (enemyType3.equals(name)) {
currentWaveContents.put(name.toString(), enemyType3ToSpawn);
} else {
currentWaveContents.put(name.toString(), count);
}
}
if (currentWave < 2) {
currentWaveContents.put(name.toString(), count);
}
}
return currentWaveContents;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.csse3200.game.entities.Extractor;
import com.csse3200.game.entities.configs.ParticleEffectsConfig;
import com.csse3200.game.entities.configs.*;
import com.csse3200.game.GdxGame;
import com.csse3200.game.areas.ExtractorMiniGameArea;
import com.csse3200.game.areas.terrain.TerrainComponent;
Expand All @@ -12,14 +12,12 @@
import com.csse3200.game.components.npc.SpawnerComponent;
import com.csse3200.game.components.resources.Resource;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.configs.SpawnerConfig;
import com.csse3200.game.entities.enemies.EnemyName;
import com.csse3200.game.input.ExtinguisherInputComponent;
import com.csse3200.game.input.FireInputComponent;
import com.csse3200.game.input.HoleInputComponent;
import com.csse3200.game.input.SpannerInputComponent;

import com.csse3200.game.entities.configs.ExtractorConfig;
import com.csse3200.game.entities.configs.ShipConfig;
import com.csse3200.game.entities.PlaceableEntity;

import com.csse3200.game.files.FileLoader;
Expand All @@ -28,11 +26,14 @@
import com.csse3200.game.physics.components.ColliderComponent;
import com.csse3200.game.physics.components.HitboxComponent;
import com.csse3200.game.physics.components.PhysicsComponent;
import com.csse3200.game.physics.components.PhysicsMovementComponent;
import com.csse3200.game.rendering.TextureRenderComponent;
import com.csse3200.game.services.GameStateObserver;
import com.csse3200.game.services.ServiceLocator;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* Factory to create structure entities - such as extractors or ships.
Expand Down Expand Up @@ -288,6 +289,15 @@ public static Entity createSpawner(SpawnerConfig config) {
new Entity()
.addComponent(new SpawnerComponent(config));

spawner.addComponent(new SaveableComponent<>(p -> {
SpawnerConfig spawnerConfig = config;
spawnerConfig.wave1 = p.getComponent(SpawnerComponent.class).getWave1();
spawnerConfig.wave2 = p.getComponent(SpawnerComponent.class).getWave2();
spawnerConfig.wave3 = p.getComponent(SpawnerComponent.class).getWave3();
spawnerConfig.position = p.getGridPosition();
return spawnerConfig;
}, SpawnerConfig.class));

spawner.scaleHeight(1.5f);
return spawner;
}
Expand Down

0 comments on commit 259e290

Please sign in to comment.