Skip to content

Obstacle Minigame ‐ Sprint 3 and 4

Foref edited this page Oct 19, 2023 · 10 revisions

Summary

  1. Implemented Fuel, where each press of a movement button will reduce fuel by 1.
  2. Once Fuel runs out, the press of a button will not accelerate the ship.
  3. Implemented Health, where the ship will lose health by 1 for each collision with an asteroid
  4. There is a small knockback effect when the ship and an asteroid collide
  5. There are no Game Over scenario yet for debugging purposes, the label on the top left will simply show current health and additional text once health goes below or equal to 0
  6. All space obstacle minigame entity creation moved to MinigameObjectFactory from ObstacleFactory in entities/factories. Additional stuff added in Sprint 4:
  7. Retry button
  8. Access minigame through SpaceNavigationScreen
  9. Assets moved to assets/levels/obstacleGameAssets.json

Description

Stats such as fuel and health are modified in the ShipActions class. Here, they are initialized to be fuel=20 and health=1 for simpler testing purpose. Acceleration by default is 1. image

Fuel Mechanics

ship fuel indicator On the top left is the indicator for the amount of fuel and health left. ship fuel indicator2
  • After pressing movement keys, the ship will lose fuel.
FlyShipAction
  • Pressing movement keys will trigger the fly() method, which will reduce fuel by 1 for each trigger.
  • Once fuel reaches 0, the noFuel() method will be triggered instead, including subsequent press of movement keys, preventing the acceleration of the ship
Newsprint3methods
  • noFuel() and other fuel/health update method will call their respective events
Newsprint3methodsStatDisplay
  • The events will trigger relevant methods in ShipStatDisplay, which in turn will change the top left display of ship Stats

Health and Collision Mechanics

Ship will lose health when Hitbox Component of the ship collide with Hitbox component of the asteroid

shipCollidelose
  • In addition to losing health (health will reduce by 1 and label will display new text as shown above in Fuel Mechanics), a knockback effect will be applied to the ship, as can be seen in the image above.
asteroidentitycreafac
  • To have collision, the component SpaceCollideDamageComponent has to be added to the asteroid entities in the MinigameObjectFactory, with Hitbox Component and PhysicsComponent as prerequisites.
  • When creating a new SpaceCollideDamageComponent, the layer for the Hitbox component to detect the Ship entity has to be set to PhyiscsLayer.SHIP while the float number 0.5 is used to specify the knockback force
asteroidentitycolDetecc
  • Once collision is detected, hitOnce method will be called and handle the collision interaction, including
  1. Calling the ship entity's ShipActions hit() method
  2. Apply a knockback force on the ship

Additional Stuff added in Sprint 4

Retry Button

retry1
  • The retry button is on the top right. Once clicked, the minigame will restart with a new map (mainly new distribution for asteroids, enemies and exit goal)
retrydisplay
  • The button is created in components/maingame/ReturnToPlanetDisplay addActors() method
retryobsta
  • Once "restart" is triggered, it will call the ObstacleMiniGameActions restartGame() method

Access Minigame Through SpaceNavigationScreen

  • A button on the top left right corner can open the space minigame. The first idea about this implementation of this is spawning the minigame right after the use decide to move to next planet. However, the minigame was too laggy with this implementation and hard to control the ship. Therefore this was fixed into an optional mechanism, if player want to play the minigame they can click on the button. Complete the minigame will help players to move on the next planet.
ship button press
  1. First, press "F" key on keyboard near the ship
ship nav button
  1. Enter the space navigation screen, the top right will be the space minigame button. Press it and play the space minigame
ship exit
  1. Find the exit goal (by distance indicator on the bottom of screen), enter the exit goal to complete the minigame
ship new game
  1. Once the minigame is completed, the player will move on to the next map
  • Movement Buttons Reminder: WASD for movement and (Not recommended in current laggy state) "B" for break, "V" for release break.
  • Current fuel is adjusted to be 1000 for lowering the difficulty (required in current laggy state of the game)

Assets

  • Assets moved to assets/levels/obstacleGameAssets.json, which can be accessed by FileLoader loading into game/areas/map_config/MiniGameAssetsConfig.java
Clone this wiki locally