Skip to content

Commit

Permalink
Merge pull request #24 from UQdeco2800/map_contents
Browse files Browse the repository at this point in the history
Map contents
  • Loading branch information
fy3344 authored Sep 1, 2021
2 parents 44fbf58 + 3759f2a commit 36cb1d4
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 0 deletions.
Binary file added source/core/assets/images/FirstAidKit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/core/assets/images/carObstacle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/core/assets/images/fire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/core/assets/images/food.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/core/assets/images/snake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/core/assets/images/stone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions source/core/src/main/com/deco2800/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
public class ForestGameArea extends GameArea {
private static final Logger logger = LoggerFactory.getLogger(ForestGameArea.class);
private static final int NUM_TREES = 7;
private static final int NUM_OBSTACLES = 12;
private static final int NUM_HEALTH_OBJECTS = 10;
private static final int NUM_GHOSTS = 2;
private static final GridPoint2 PLAYER_SPAWN = new GridPoint2(1, 8);
private static final float WALL_WIDTH = 0.1f;
Expand All @@ -39,6 +41,12 @@ public class ForestGameArea extends GameArea {
"images/iso_grass_1.png",
"images/iso_grass_2.png",
"images/iso_grass_3.png",
"images/carObstacle.png",
"images/stone.png",
"images/FirstAidKit.png",
"images/snake.png",
"images/fire.png",
"images/food.png",
"images/dragon.png",
"images/pixelghost.png",
"images/pixelghost1.png",
Expand Down Expand Up @@ -71,6 +79,8 @@ public void create() {

spawnTerrain();
spawnTrees();
spawnObstables();
spawnHealthObjects();
player = spawnPlayer();
spawnGhosts();
spawnGhostKing();
Expand Down Expand Up @@ -124,6 +134,53 @@ private void spawnTrees() {
}
}

private void spawnObstables() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2);

for (int i = 0; i < NUM_OBSTACLES; i++) {
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
switch(i % 3) {
case 0:
Entity car = ObstacleFactory.createCarObstacle();
spawnEntityAt(car, randomPos, true, false);
break;
case 1:
Entity stone = ObstacleFactory.createStoneObstacle();
spawnEntityAt(stone, randomPos, true, false);
break;
case 2:
Entity snake = ObstacleFactory.createSnake();
spawnEntityAt(snake, randomPos, true, false);
break;
case 3:
Entity fire = ObstacleFactory.createFire();
spawnEntityAt(fire, randomPos, true, false);
break;
}
}
}

private void spawnHealthObjects() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2);

for (int i = 0; i < NUM_HEALTH_OBJECTS; i++) {
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
switch(i % 2) {
case 0:
Entity food = ObstacleFactory.createFood();
spawnEntityAt(food, randomPos, true, false);
break;
case 1:
Entity firstAid = ObstacleFactory.createFirstAidKit();
spawnEntityAt(firstAid, randomPos, true, false);
break;
}
}
}


private Entity spawnPlayer() {
Entity newPlayer = PlayerFactory.createPlayer();
spawnEntityAt(newPlayer, PLAYER_SPAWN, true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.deco2800.game.physics.components.ColliderComponent;
import com.deco2800.game.physics.components.PhysicsComponent;
import com.deco2800.game.rendering.TextureRenderComponent;
import com.deco2800.game.components.CombatStatsComponent;

/**
* Factory to create obstacle entities.
Expand All @@ -33,6 +34,98 @@ public static Entity createTree() {
return tree;
}

public static Entity createCarObstacle() {
Entity car =
new Entity()
.addComponent(new TextureRenderComponent("images/carObstacle.png"))
.addComponent(new PhysicsComponent())
.addComponent(new ColliderComponent().setLayer(PhysicsLayer.OBSTACLE));

car.getComponent(PhysicsComponent.class).setBodyType(BodyType.StaticBody);
car.getComponent(TextureRenderComponent.class).scaleEntity();
car.scaleHeight(2.5f);
PhysicsUtils.setScaledCollider(car, 0.5f, 0.2f);
return car;
}

public static Entity createStoneObstacle() { //CombatStatsComponent combat) {
Entity stone =
new Entity()
.addComponent(new TextureRenderComponent("images/stone.png"))
.addComponent(new PhysicsComponent())
.addComponent(new ColliderComponent().setLayer(PhysicsLayer.OBSTACLE));

stone.getComponent(PhysicsComponent.class).setBodyType(BodyType.StaticBody);
stone.getComponent(TextureRenderComponent.class).scaleEntity();
stone.scaleHeight(2.5f);
PhysicsUtils.setScaledCollider(stone, 0.5f, 0.2f);
//demote health by smallest amount
// combat.addHealth(-1);
return stone;
}

public static Entity createSnake() {
Entity snake =
new Entity()
.addComponent(new TextureRenderComponent("images/snake.png"))
.addComponent(new PhysicsComponent())
.addComponent(new ColliderComponent().setLayer(PhysicsLayer.OBSTACLE));

snake.getComponent(PhysicsComponent.class).setBodyType(BodyType.StaticBody);
snake.getComponent(TextureRenderComponent.class).scaleEntity();
snake.scaleHeight(2.5f);
PhysicsUtils.setScaledCollider(snake, 0.5f, 0.2f);
//demote health medium
// CombatStatsComponent.addHealth(-3);
return snake;
}

public static Entity createFire() {
Entity fire =
new Entity()
.addComponent(new TextureRenderComponent("images/fire.png"))
.addComponent(new PhysicsComponent())
.addComponent(new ColliderComponent().setLayer(PhysicsLayer.OBSTACLE));

fire.getComponent(PhysicsComponent.class).setBodyType(BodyType.StaticBody);
fire.getComponent(TextureRenderComponent.class).scaleEntity();
fire.scaleHeight(2.5f);
PhysicsUtils.setScaledCollider(fire, 0.5f, 0.2f);
//demote health the most
// combat.addHealth(-3);
return fire;
}

public static Entity createFirstAidKit() {
Entity FirstAidKit =
new Entity()
.addComponent(new TextureRenderComponent("images/FirstAidKit.png"))
.addComponent(new PhysicsComponent())
.addComponent(new ColliderComponent().setLayer(PhysicsLayer.OBSTACLE));

FirstAidKit.getComponent(PhysicsComponent.class).setBodyType(BodyType.StaticBody);
FirstAidKit.getComponent(TextureRenderComponent.class).scaleEntity();
FirstAidKit.scaleHeight(2.5f);
PhysicsUtils.setScaledCollider(FirstAidKit, 0.5f, 0.2f);
// combat.addHealth(2);
return FirstAidKit;
}

public static Entity createFood() {
Entity Food =
new Entity()
.addComponent(new TextureRenderComponent("images/food.png"))
.addComponent(new PhysicsComponent())
.addComponent(new ColliderComponent().setLayer(PhysicsLayer.OBSTACLE));

Food.getComponent(PhysicsComponent.class).setBodyType(BodyType.StaticBody);
Food.getComponent(TextureRenderComponent.class).scaleEntity();
Food.scaleHeight(2.5f);
PhysicsUtils.setScaledCollider(Food, 0.5f, 0.2f);
// combat.addHealth(1);
return Food;
}

/**
* Creates an invisible physics wall.
* @param width Wall width in world units
Expand Down

0 comments on commit 36cb1d4

Please sign in to comment.