Skip to content

Commit

Permalink
Merge pull request #588 from UQcsse3200/feature/obstacle-minigame
Browse files Browse the repository at this point in the history
Feature/obstacle minigame bug fixes
  • Loading branch information
Foref authored Oct 21, 2023
2 parents c749964 + 47b3f2f commit 5a3abc3
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions source/core/assets/kenney-rpg-expansion/kenneyrpg.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"scaledSize": 18,
"markupEnabled": false,
"flip": false
}
},
"pixel_art": {
"file": "mago3.fnt",
"scaledSize": 18,
Expand Down Expand Up @@ -131,7 +131,7 @@
},
"thin_black": {
"font": "thin_black"
}
},
"pixel_art" : {
"font" : "pixel_art"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"entityType": "CircleConfig",
"entities": [
{
class: com.csse3200.game.entities.configs.CircleConfig,
"class": "com.csse3200.game.entities.configs.CircleConfig",
"spritePath": "images/npc/circle.png",
"position" : {
"x": 28,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
"entityType": "FissureConfig",
"entities": [
{
class: com.csse3200.game.entities.configs.FissureConfig,
"class": "com.csse3200.game.entities.configs.FissureConfig",
"resource": "Solstite",
"position": {
"x": 77,
"y": 52
}
},
{
class: com.csse3200.game.entities.configs.FissureConfig,
"class": "com.csse3200.game.entities.configs.FissureConfig",
"resource": "Nebulite",
"position": {
"x": 59,
"y": 22
}
},
{
class: com.csse3200.game.entities.configs.FissureConfig,
"class": "com.csse3200.game.entities.configs.FissureConfig",
"resource": "Durasteel",
"position": {
"x": 19,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"entityType": "AstroConfig",
"entities": [
{
class: com.csse3200.game.entities.configs.AstroConfig,
"class": "com.csse3200.game.entities.configs.AstroConfig",
"spritePath": "images/npc/caged_NPC.atlas",
"position" : {
"x": 24,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
},
{
"class": com.csse3200.game.entities.configs.PortalConfig,
"class": "com.csse3200.game.entities.configs.PortalConfig",
"teleportX" : 16,
"teleportY" : 20,
"position": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
"entityType": "FissureConfig",
"entities": [
{
class: com.csse3200.game.entities.configs.FissureConfig,
"class": "com.csse3200.game.entities.configs.FissureConfig",
"resource": "Solstite",
"position": {
"x": 76,
"y": 18
}
},
{
class: com.csse3200.game.entities.configs.FissureConfig,
"class": "com.csse3200.game.entities.configs.FissureConfig",
"resource": "Nebulite",
"position": {
"x": 66,
"y": 80
}
},
{
class: com.csse3200.game.entities.configs.FissureConfig,
"class": "com.csse3200.game.entities.configs.FissureConfig",
"resource": "Durasteel",
"position": {
"x": 12,
Expand Down
16 changes: 9 additions & 7 deletions source/core/src/main/com/csse3200/game/areas/SpaceGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class SpaceGameArea extends GameArea {
private static final int NUM_ASTEROIDS = 100;
private TerrainFactory terrainFactory;
private ArrayList<Entity> targetTables;
private Random random;
int randomX, randomY;
private Vector2 goalPosition;

/**
* Constructor for initializing terrain area
Expand Down Expand Up @@ -144,27 +147,26 @@ private void spawnAsteroids() {
* Method for placing the exit point from the obstacle minigame
*/
public Entity spawnGoal() {
Random random = new Random();
int randomX, randomY;
GridPoint2 position;
random = new Random();
// Continue generating random positions until an unoccupied position is found.
do {
randomX = random.nextInt(terrain.getMapBounds(0).x);
randomY = random.nextInt(terrain.getMapBounds(0).y);
position = new GridPoint2(randomX, randomY);
} while (isPositionOccupied(position));
goalPosition = new Vector2((float) randomX, (float) randomY);
} while (isPositionOccupied(goalPosition));
Entity newGoal = MinigameObjectFactory.createObstacleGameGoal(WORMHOLE_SIZE, WORMHOLE_SIZE);
spawnEntityAt(newGoal, position, false, false);
spawnEntityAtVector(newGoal, goalPosition);
goal = newGoal;
return goal;
}

/**
* Check if a position is occupied by an entity.
*/
public boolean isPositionOccupied(GridPoint2 position) {
public boolean isPositionOccupied(Vector2 position) {
// Loop through the list of existing entities and check if any entity occupies the given position.
for (Entity entity : targetTables) {
//GridPoint2 and Vector2 is unrelated
if (entity != null && entity.getPosition().equals(position)) {
return true; // Position is occupied.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class MiniGameAssetsConfig {
public String[] textureAtlasPaths = null;
public String[] backgroundMusicPath = null;


@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -28,13 +29,16 @@ public boolean equals(Object o) {
return Objects.equals(backgroundMusicPath, that.backgroundMusicPath);
}

/*
Arrays problem, will fix later, currently assume there is no need for hashcode.
@Override
public int hashCode() {
int result = Arrays.hashCode(texturePaths);
result = 31 * result + Arrays.hashCode(textureAtlasPaths);
result = 31 * result + (backgroundMusicPath != null ? backgroundMusicPath.hashCode() : 0);
return result;
}
*/

/**
* Loads all assets contained within this config class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public static Entity createCompanion(CompanionConfig config) {
.addComponent(new CompanionActions())
.addComponent(new CombatStatsComponent(config.health, config.maxHealth,
config.baseAttack, config.attackMultiplier, config.isImmune))
.addComponent(new CompanionInventoryComponent())
//.addComponent(new CompanionInventoryComponent()) remove later if confirmed useless
//cannot add multiple copies of the same component, since already added as seen below
.addComponent(inputComponent)
.addComponent(animator)
.addComponent(new CompanionWeaponComponent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,13 @@ public void testCalculateDistanceWithNonZeroDistance() {
}
@Test
public void testIsPositionOccupied() {

SpaceGameArea spaceGameArea = mock(SpaceGameArea.class);




// Define an unoccupied position
GridPoint2 unoccupiedPosition = new GridPoint2(1, 1);


Vector2 unoccupiedPosition = new Vector2(1f, 1f);
when(spaceGameArea.isPositionOccupied(unoccupiedPosition)).thenReturn(false);
assertFalse(spaceGameArea.isPositionOccupied(unoccupiedPosition));

// Define an occupied position
GridPoint2 occupiedPosition = new GridPoint2(2, 2);

Vector2 occupiedPosition = new Vector2(2f, 2f);
when(spaceGameArea.isPositionOccupied(occupiedPosition)).thenReturn(true);
assertTrue(spaceGameArea.isPositionOccupied(occupiedPosition));
}
Expand Down

0 comments on commit 5a3abc3

Please sign in to comment.