Project Academic Red - My Code


Some highlights of my code…

Game loop

  • Press play / continue
  • Generate level
    • Place mountain range
    • Place rifts
    • Place health boxes
    • Place player
    • WFC the rest
  • Rifts spawn enemies
  • Player fights enemies
  • Player destroys rifts
  • Game Over <- Player dead or All rifts destroyed

3 Key MonoBehaviours

Wave Function Collapse This code is the main algorithm for the level generation. It hold all the parts of WFC (Collapsing the cell with the lowest entropy and propagating the updated tiles set). The level is generated from a base size and is larger with a higher number of rifts that need to be spawned.

The preprocessing is divided into several steps:

  • Placing the surrounding mountain range and collapsing those tiles.
  • Dividing the level into sectors, in each sector will be either one rift, one health box or the player spawn.
  • Placing the rifts and collapsing those tiles
  • Placing the health boxes (one less than rifts) and collapsing those tiles
  • Placing the player spawn and collapsing the tile. After which the WFC algorithm generates the rest. The compatibility of adjacent tiles is checked with binary operations, because all tiles have for the for sockets a flag field enum (binary mask).

Enemy Controller The Enemy Controller script holds the enemy stats scriptable object, part of it are also AI behaviours for the different states of the enemy. The controller chooses the best state depending on some external factors and acts on it using the enemy behaviours in the scriptable object. These AI Behaviour scriptable objects have three methods:

  • OnStateEnter: what to do when entering the AI state
  • Act: what to do when in the AI state
  • OnStateExit: what to do when exiting the AI state

Player Health The small but mighty Player Health script takes care of the health and shield status of the player. If the shield active the player doesn’t take permanent damage to the health. The shield regenerates after some time, when no damage is taken. The health doesn’t regenerate, to heal the player needs to pick up a health box. Each change triggers a tween on the respective bar. When the player dies, a tween is called on the dissolve coefficient property of the Shader Graph material on the player.

Best and Worst

Code I am the proudest of: Editor Extension - Enemy Stats

Code that should receive a complete overhaul: HiveMind Manager (AI)

Files

TRHLINA 23 (Android) 42 MB
34 days ago
TRHLINA 23 (Windows) 43 MB
34 days ago

Get TRHLINA 23

Leave a comment

Log in with itch.io to leave a comment.