Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Team4-LevelCompleted-Megan' into…
Browse files Browse the repository at this point in the history
… t3branch

# Conflicts:
#	source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
#	source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java
  • Loading branch information
Moksh-Mehta7 committed Oct 14, 2023
2 parents e21eaf1 + ad771f0 commit e445867
Show file tree
Hide file tree
Showing 25 changed files with 528 additions and 374 deletions.
111 changes: 53 additions & 58 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,11 @@

import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.areas.terrain.TerrainFactory;
import com.csse3200.game.areas.terrain.TerrainFactory.TerrainType;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.*;
import com.csse3200.game.physics.PhysicsLayer;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.math.GridPoint2;
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.ProjectileEffects;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.*;

import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.screens.AssetLoader;

import com.csse3200.game.utils.math.RandomUtils;
import com.csse3200.game.services.ResourceService;
Expand All @@ -29,14 +15,9 @@
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 static com.csse3200.game.screens.AssetLoader.loadAllAssets;
import java.util.ArrayList;

import java.util.TimerTask;

/** Forest area for the demo game with trees, a player, and some enemies. */
public class ForestGameArea extends GameArea {
Expand All @@ -46,10 +27,6 @@ public class ForestGameArea extends GameArea {
private static final int NUM_GRUNTS = 5;
private static final int NUM_BOSS = 4;


private static final int NUM_MOBBOSS2=3;
private static final int NUM_MOBBOSS1=1;

private SecureRandom rand = new SecureRandom();

private int wave = 0;
Expand Down Expand Up @@ -186,7 +163,10 @@ public class ForestGameArea extends GameArea {
"images/towers/PierceTower.atlas",
"images/towers/RicochetTower.atlas",
"images/mobboss/iceBaby.atlas",
"images/bombship/bombship.atlas"
"images/bombship/bombship.atlas",
"images/mobs/coat.atlas",
"images/mobs/night_borne.atlas",
"images/mobs/arcane_archer.atlas"
};
private static final String[] forestSounds = {
"sounds/Impact4.ogg",
Expand Down Expand Up @@ -227,20 +207,15 @@ public class ForestGameArea extends GameArea {
"sounds/mobBoss/patrickSpawn.mp3",
"sounds/mobBoss/patrickCast.mp3",
"sounds/mobBoss/patrickThunder.mp3",
"sounds/mobBoss/patrickHit.mp3"
"sounds/mobBoss/patrickHit.mp3",
"sounds/mobBoss/spawnDemonSlime.mp3"
};
private static final String backgroundMusic = "sounds/background/Sci-Fi1.ogg";

private static final String[] forestMusic = {backgroundMusic};
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 mobBoss2;
private Entity mobBoss1;

/**
* Initialise this ForestGameArea to use the provided TerrainFactory.
*
Expand Down Expand Up @@ -318,11 +293,17 @@ public void create() {
spawnTerrain();

// Set up infrastructure for end game tracking
// player = spawnPlayer();

waves = WaveFactory.createWaves();
spawnEntity(waves);
waves.getEvents().addListener("spawnWave", this::spawnMob);
player = spawnPlayer();

waves = WaveFactory.createWaves();
spawnEntity(waves);
waves.getEvents().addListener("spawnWave", this::spawnMob);
// spawnCoat();
// spawnDodgingDragonKnight(17,4);
// spawnDeflectWizard(17, 3);
// spawnSplittingXenoGrunt(17, 2);
// spawnPatrick();
// spawnDemonBoss();

spawnScrap();
spawnGapScanners();
Expand Down Expand Up @@ -394,10 +375,10 @@ private Entity spawnPlayer(GridPoint2 position) {
}

// commented 383 - 386 out as there was a missing arg?
// private void spawnDemonBoss() {
// Entity demon = MobBossFactory.createDemonBoss();
// spawnEntityAt(demon, new GridPoint2(19, 5), true, false);
// }
private void spawnDemonBoss() {
Entity demon = MobBossFactory.createDemonBoss(5000);
spawnEntityAt(demon, new GridPoint2(19, 5), true, false);
}

private void spawnPatrick() {
Entity patrick = MobBossFactory.createPatrickBoss(3000);
Expand Down Expand Up @@ -514,6 +495,20 @@ public void spawnMob(String entity, GridPoint2 randomPos, int health) {
case "IceBoss":
mob = MobBossFactory.createIceBoss(health);
break;

case "Coat":
mob = NPCFactory.createCoat(health);
break;
case "NightBorne":
mob = NPCFactory.createNightBorne(health);
break;
case "SplittingNightBorne":
mob = NPCFactory.createSplittingNightBorne(health);
break;
case "ArcaneArcher":
mob = NPCFactory.createDodgingArcaneArcher(health);
break;

case "PatrickBoss":
mob = MobBossFactory.createPatrickBoss(health);
break;
Expand Down Expand Up @@ -620,28 +615,22 @@ public void spawnMob(String entity, GridPoint2 randomPos, int health) {
// spawnEntityAt(waterSlime, randomPos, true, false);
// }
// }
// 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);
// }
private void spawnDodgingDragonKnight(int x, int y) {
GridPoint2 pos = new GridPoint2(x, y);
Entity fireworm = NPCFactory.createDodgingDragonKnight(100);
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 spawnDeflectWizard(int x, int y) {
GridPoint2 pos = new GridPoint2(x, y);
Entity xenoGrunt = NPCFactory.createDeflectWizard(100);
xenoGrunt.setScale(1.5f, 1.5f);
spawnEntityAt(xenoGrunt, pos, true, true);
}
//
// private void spawnFireWorm() {
//
Expand Down Expand Up @@ -720,6 +709,12 @@ public void spawnMob(String entity, GridPoint2 randomPos, int health) {
// }
// }

private void spawnCoat() {
Entity gregMob = NPCFactory.createCoat(100);
gregMob.setScale(1.5f, 1.5f);
spawnEntityAt(gregMob, new GridPoint2(17, 4), false, false);
}

/**
* Creates multiple projectiles that travel simultaneous. They all have same
* the starting point but different destinations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
Expand All @@ -15,6 +16,7 @@
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.UIComponent;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
Expand Down Expand Up @@ -89,6 +91,15 @@ public void updateScrapsStats() {
scrapsTb.getLabel().setText(text);
}

/**
* Displays a warning animation of the scraps display if the player tries to
* build something that costs more than the balance
*/
public void scrapBalanceFlash() {
// TODO: IMPLEMENT THIS
scrapsTb.setText("Insufficient!");
}

/**
* Updates the currency (Crystals) value on the UI component
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,19 @@

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Array;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.TowerFactory;
import com.csse3200.game.screens.TowerType;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.ButtonFactory;
import com.csse3200.game.ui.UIComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.Set;

/**
* Displays a button to represent the remaining mobs left in the current wave and a button to skip to the next wave.
Expand All @@ -40,8 +31,6 @@ public class UIElementsDisplay extends UIComponent {
};
private Sound click;
private Sound hover;
// private TextButton remainingMobsButton = new ButtonFactory().createButton("Mobs left:");
// private final TextButton timerButton = new ButtonFactory().createButton("Next wave:");
private TextButton remainingMobsButton;
private TextButton timerButton;
private final int timer = 110;
Expand All @@ -62,14 +51,11 @@ private void addActors() {
remainingMobsButton = new TextButton("Mobs:"
+ ServiceLocator.getWaveService().getEnemyCount(), skin);
buttonTable.top().right();
towerTable.top();
towerTable.top().padTop(80f);

buttonTable.setFillParent(true);
towerTable.setFillParent(true);

towerTable.setDebug(true);
towerTable.padTop(50f);

TowerType[] defaultTowers = {
TowerType.TNT,
TowerType.DROID,
Expand Down Expand Up @@ -98,6 +84,10 @@ private void addActors() {
}
}

// Update the centrally located towerTypes list -
ServiceLocator.setTowerTypes(towers);

// Create the buttons - TODO This needs overhauling to pretty buttons
TextButton tower1 = new TextButton(towers.get(0).getTowerName(), skin);
TextButton tower2 = new TextButton(towers.get(1).getTowerName(), skin);
TextButton tower3 = new TextButton(towers.get(2).getTowerName(), skin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.currency.Scrap;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;
import org.slf4j.Logger;
Expand All @@ -22,6 +24,13 @@ public class CurrencyTask extends DefaultTask implements PriorityTask {
private final int currencyAmount = scrap.getAmount(); // amount of currency to update
private static final String IDLE = "idleStartEco";
private static final String MOVE = "moveStartEco";
private static final String DEATH = "deathStartEco";

public enum STATE {
IDLE, DEATH
}
public STATE towerState = STATE.IDLE;


/**
* @param priority Task priority for currency updates. Must be a positive integer.
Expand All @@ -40,7 +49,8 @@ public CurrencyTask(int priority, int interval) {
public void start() {
super.start();
owner.getEntity().getEvents().addListener("addIncome",this::changeInterval);
endTime = timeSource.getTime() + (30 * 1000L);
// TODO: changed 30 TIMES MULTIPLIER to 5 times
endTime = timeSource.getTime() + (interval * 1500L);
owner.getEntity().getEvents().trigger(IDLE);
}

Expand All @@ -52,14 +62,38 @@ public void start() {
@Override
public void update() {
if (timeSource.getTime() >= endTime) {
owner.getEntity().getEvents().trigger(MOVE);
updateCurrency(); // update currency
updateTowerState();
logger.info(String.format("Interval: %d", interval));
endTime = timeSource.getTime() + (interval * 1000L); // reset end time

}
}

/**
* This method acts is the state machine for IncomeTower. Relevant animations are triggered based on relevant state
* of the game. If the tower runs out of health it dies.
*/
public void updateTowerState() {
if (owner.getEntity().getComponent(CombatStatsComponent.class).getHealth() <= 0 && towerState != STATE.DEATH) {
owner.getEntity().getEvents().trigger(DEATH);
towerState = STATE.DEATH;
}

switch (towerState) {
case IDLE -> {
owner.getEntity().getEvents().trigger(MOVE);
updateCurrency(); // update currency
towerState = STATE.IDLE;
}
case DEATH -> {
if (owner.getEntity().getComponent(AnimationRenderComponent.class).isFinished()) {
owner.getEntity().setFlagForDelete(true);
}
}
}
}


/**
* Updates the currency based on time intervals.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void start() {
// Default to idle mode
owner.getEntity().getEvents().trigger(WALK);
owner.getEntity().getEvents().addListener("addFireRate",this::changeFireRateInterval);
endTime = timeSource.getTime() + (INTERVAL * 500);
endTime = timeSource.getTime() + (INTERVAL * 1000);
}

/**
Expand Down
Loading

0 comments on commit e445867

Please sign in to comment.