-
Notifications
You must be signed in to change notification settings - Fork 9
Obstacle Minigame ‐ Sprint 1
The player can do basic movements with the ship using the arrow keys as follows:
D
and →
-- Move Right
A
and ←
-- Move Left
W
and ↑
-- Move Up
A
and ↓
-- Move Down
The spawnAsteroids
method is used to spawn an asteroid in the obstacle minigame:
-
Position: A
GridPoint2
object,posAs
, is set to coordinates(22, 10)
. -
Asteroid Creation: The
ObstacleFactory.createAsteroid
method creates an asteroid of sizeASTEROID_SIZE
for both width and height. -
Spawning: The
spawnEntityAt
method is called to place the created asteroid at theposAs
position with two boolean flags set tofalse
.
In essence, when invoked, the method spawns an asteroid of a certain size at coordinates (22, 10)
.
private void spawnAsteroids() {
//Extra Spicy Asteroids
GridPoint2 posAs = new GridPoint2(22, 10);
spawnEntityAt(ObstacleFactory.createAsteroid(ASTEROID_SIZE,ASTEROID_SIZE), posAs, false, false);
}
The spawnStaticAsteroidsRight
method spawns a specified number (n
) of static asteroids in a horizontal line to the right:
-
Base Case: If
n
is 0 or negative, the method exits. -
Asteroid Creation: An asteroid of size
STATIC_ASTEROID_SIZE
is spawned at the givenpos
. -
Position Update: The x-coordinate of
pos
is incremented by 1 for the next asteroid. -
Recursion: The method calls itself to spawn the next asteroid to the right, decreasing the count (
n
) by 1.
In essence, it places n
static asteroids in a straight line to the right of the provided starting position.
private void spawnStaticAsteroidsRight(int n, GridPoint2 pos){
if (n <= 0) {
return;
}
spawnEntityAt(
ObstacleFactory.createStaticAsteroid(STATIC_ASTEROID_SIZE, STATIC_ASTEROID_SIZE), pos, false, false);
// Increment the position for the next asteroid
pos.x += 1;
pos.y += 0;
spawnStaticAsteroidsRight(n - 1, pos); // Recursive call
}
The spawnGoal
method creates and places the obstacle minigame goal, resembling a wormhole:
-
Position: Sets the goal's location to coordinates
(24,10)
. -
Goal Creation: Uses the
ObstacleFactory
to create a game goal of sizeWORMHOLE_SIZE
and spawns it at the defined position.
Simply put, it spawns a game goal (like a wormhole) at coordinates (24,10)
.
private void spawnGoal(){
GridPoint2 position = new GridPoint2(24,10);
spawnEntityAt(
ObstacleFactory.createObstacleGameGoal(WORMHOLE_SIZE,WORMHOLE_SIZE), position,false,false);
}
The spawnShip
method does the following:
-
Ship Creation: Creates a new ship using
ShipFactory
. -
Spawning: Places the ship at the location defined by
SHIP_SPAWN
with twotrue
flags. -
Adding to List: Adds the created ship to the
targetables
list.
In essence, it creates a ship, spawns it at a specific location, and adds it to a targetable entities list.
private void spawnShip(){
Entity newShip = ShipFactory.createShip();
spawnEntityAt(newShip, SHIP_SPAWN, true, true);
targetables.add(newShip);
}
Camera Movement - Uses setPosition() function of the Entity Class in render()
We collaborated with Team 5 for the design of this ship and agreed on the ship design given below:
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files