Skip to content

Obstacle Minigame ‐ Sprint 1

Anshul Dadhwal edited this page Oct 6, 2023 · 6 revisions

Sprint 1

Player Guide

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

Code Documentation

The spawnAsteroids method is used to spawn an asteroid in the obstacle minigame:

  1. Position: A GridPoint2 object, posAs, is set to coordinates (22, 10).
  2. Asteroid Creation: The ObstacleFactory.createAsteroid method creates an asteroid of size ASTEROID_SIZE for both width and height.
  3. Spawning: The spawnEntityAt method is called to place the created asteroid at the posAs position with two boolean flags set to false.

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:

  1. Base Case: If n is 0 or negative, the method exits.
  2. Asteroid Creation: An asteroid of size STATIC_ASTEROID_SIZE is spawned at the given pos.
  3. Position Update: The x-coordinate of pos is incremented by 1 for the next asteroid.
  4. 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:

  1. Position: Sets the goal's location to coordinates (24,10).
  2. Goal Creation: Uses the ObstacleFactory to create a game goal of size WORMHOLE_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:

  1. Ship Creation: Creates a new ship using ShipFactory.
  2. Spawning: Places the ship at the location defined by SHIP_SPAWN with two true flags.
  3. 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()
CameraBasic

Assets/Design Decisions

Design of Spaceship

We collaborated with Team 5 for the design of this ship and agreed on the ship design given below:

mainship03-2

Design of Asteroids

Asteroids

Design of Wormhole

Wormhole

Design of Map tile

Map

Design of Enemy

Obstacle-Enemy
Clone this wiki locally