Skip to content

Commit

Permalink
Merge pull request #303 from UQcsse3200/Team-5--Bug-Fix
Browse files Browse the repository at this point in the history
[Team 5]  Bug Fixes and Code Smell Adjustments
  • Loading branch information
Hasakev authored Oct 17, 2023
2 parents 5b6ab27 + d531d1f commit 2ae51b8
Show file tree
Hide file tree
Showing 36 changed files with 306 additions and 504 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.csse3200.game.ai.tasks;

import com.csse3200.game.components.Component;
import com.csse3200.game.components.ComponentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
83 changes: 21 additions & 62 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

import com.csse3200.game.components.ProjectileEffects;

import com.csse3200.game.services.GameTime;
import com.csse3200.game.utils.math.RandomUtils;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.SecureRandom;
import java.util.Timer;

import static com.csse3200.game.screens.AssetLoader.loadAllAssets;
Expand All @@ -21,6 +24,13 @@
public class ForestGameArea extends GameArea {
private static final Logger logger = LoggerFactory.getLogger(ForestGameArea.class);

/* Change below to change the number of ms between spawns of engineers in the case */
private static final long ENGINEER_MIN_SPAWN_INTERVAL = 1000;

private long lastSpawnTime = 0;

private int wave = 0;

private Timer waveTimer;
private static final GridPoint2 PLAYER_SPAWN = new GridPoint2(2, 4);
// Temporary spawn point for testing
Expand Down Expand Up @@ -212,8 +222,6 @@ public class ForestGameArea extends GameArea {
private static final String BACKGROUND_MUSIC = "sounds/background/Sci-Fi1.ogg";

private static final String[] forestMusic = {BACKGROUND_MUSIC};
private Entity player;
private Entity waves;

/**
* Initialise this ForestGameArea to use the provided TerrainFactory.
Expand All @@ -223,19 +231,6 @@ public ForestGameArea() {
super();
}

/**
* Add this method to start the wave spawning timer when the game starts.
*/
// private void startWaveTimer() {
// waveTimer = new Timer();
// waveTimer.scheduleAtFixedRate(new TimerTask() {
// @Override
// public void run() {
// spawnWave();
// }
// }, 0, 10000); // 10000 milliseconds = 10 seconds
// }

/**
* Add this method to stop the wave timer when the game ends or as needed.
*/
Expand All @@ -246,37 +241,6 @@ private void stopWaveTimer() {
}
}

/**
* Cases to spawn a wave
*/
// private void spawnWave() {
// wave++;
// switch (wave) {
// case 1:
// case 2:
// spawnFireWorm();
// spawnDragonKnight();
//
// break;
// case 3:
// spawnSkeleton();
// spawnWizard();
// // mobBoss2 = spawnMobBoss2();
// break;
// case 4:
// spawnWaterQueen();
// spawnWaterSlime();
// // mobBoss2 = spawnMobBoss2();
//
// break;
// case 5:
// spawnDemonBoss();
// default:
// // Handle other wave scenarios if needed
// break;
// }
// }

/**
* Create the game area, including terrain, static entities (trees), dynamic entities (player)
*/
Expand All @@ -291,15 +255,14 @@ public void create() {
spawnTerrain();

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

logger.info("Creating waves");
waves = WaveFactory.createWaves();
Entity waves = WaveFactory.createWaves();
spawnEntity(waves);
waves.getEvents().addListener("spawnWave", this::spawnMob);

spawnScrap();
spawnGapScanners();

}

private void displayUI() {
Expand Down Expand Up @@ -345,19 +308,6 @@ private void spawnTerrain() {

}

//private Entity spawnPlayer() {
// Entity newPlayer = PlayerFactory.createPlayer();
// spawnEntityAt(newPlayer, PLAYER_SPAWN, true, true);
// return newPlayer;
// }

// Spawn player at a specific position
// private Entity spawnPlayer(GridPoint2 position) {
// Entity newPlayer = PlayerFactory.createPlayer();
// spawnEntityAt(newPlayer, position, true, true);
// return newPlayer;
// }

/**
* Spawn an entity on the map. Is called during a wave. Add cases here for each mob type
* @param entity mob to be spawned
Expand Down Expand Up @@ -478,10 +428,19 @@ private void spawnScrap() {
* and trigger engineer spawning
*/
private void spawnGapScanners() {
GameTime gameTime = ServiceLocator.getTimeSource();
long currSpawnTime = gameTime.getTime();

long diff = currSpawnTime - this.lastSpawnTime;
if (diff < ENGINEER_MIN_SPAWN_INTERVAL) {
return;
}

for (int i = 0; i < terrain.getMapBounds(0).y; i++) {
Entity scanner = GapScannerFactory.createScanner();
spawnEntityAt(scanner, new GridPoint2(0, i), true, true);
}
this.lastSpawnTime = currSpawnTime;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import com.csse3200.game.services.CurrencyService;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Render a tiled terrain for a given tiled map and orientation. A terrain is a map of tiles that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class EffectsComponent extends Component {
private final boolean aoe;
private HitboxComponent hitboxComponent;
private final short targetLayer;
private Array<CombatStatsComponent> burnEntities = new Array<>();
private ArrayList<Entity> stunnedEntities = new ArrayList<>();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void addActors() {

// Animate the engineer count label
engineerTb.setPosition(table.getX() - 200f, Gdx.graphics.getHeight() - 145f);
engineerTb.addAction(new SequenceAction(Actions.moveTo(table.getX() + 20f, Gdx.graphics.getHeight() - 145,
engineerTb.addAction(new SequenceAction(Actions.moveTo(table.getX() + 20f, Gdx.graphics.getHeight() - 145f,
1f, Interpolation.fastSlow)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* Displays the name of the current game area.
*/
public class GameAreaDisplay extends UIComponent {
private static final Logger logger = LoggerFactory.getLogger(GameAreaDisplay.class);
private static final String DEFAULT_STYLE = "default";
private String gameAreaName = "";
private Label title;
Expand All @@ -27,7 +26,6 @@ public GameAreaDisplay(String gameAreaName) {
public void create() {
super.create();
addActors();
final Skin skin = new Skin();
}

public void render(float delta) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.csse3200.game.components.maingame;

import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.csse3200.game.components.npc;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.components.Component;
import com.csse3200.game.physics.PhysicsEngine;
Expand Down Expand Up @@ -32,7 +33,6 @@ public class DodgingComponent extends Component {
private float dodgeSpeed = 1.75f;
private float originalSpeed; // Original entity vertical speed
private PhysicsEngine physics;
private Random random = new Random();

// Sometimes the raycast mechanic doesn't detect the other entity because of the
// target's (or self) collider size does not match. This value makes sure the
Expand Down Expand Up @@ -95,7 +95,7 @@ public void create() {
* @param mobPos The current Vector2 mob position in the map.
*/
public void changeTraverseDirection(Vector2 mobPos) {
int randDirection = random.nextInt(2) == 1 ? -1 : 1;
int randDirection = MathUtils.random(0,2) == 1 ? -1 : 1;

if (isTargetVisible(mobPos)) {
// If mob is in the top half quadrant of the map grid, make the entity dodge
Expand Down

This file was deleted.

Loading

0 comments on commit 2ae51b8

Please sign in to comment.