Snake Train
Programmer
Programmed/Coded a Finite State Machine for NPC behavior.
Utilized “Object Pooler” design pattern for player and enemy projectiles.
Created Scriptable Objects to adjust attributes for game objects.
Team: 5
Unity / C#
Finite State machine
Implementation
GatlingStateMachine.cs — Encapsulates logic for NPC behavior states: Scanning, Firing, Throwing, and Reloading.
Execution
Scanning — Checks to see if the Player is in it’s detection radius using Vector2 distance formula.
Firing — Fires projectiles if Player is in range. Switches to Throwing after rounds have depleted.
Throwing — Tosses a Molotov after rounds have depleted. Switches to Reloading state.
Reloading — Reloads weapon on a timer using a coroutine. Switches to Scanning state.
Code Snippet(s)
Object Pooler
Object Pooler
Benefits from using an Object Pooler:
Performance Improvement
Reduces performance cost from instantiating and destroying objects and avoids garbage collection.
Memory Management
Uses memory more efficiently by reusing objects and allocating a fixed space in memory.
Scalability and Reusability
More objects and object types can be seamlessly added without having to refactor or add code.
Implementation
ObjectPooler.cs
Holds a two-dimensional list containing each reoccurring game object:
Bullet
Molotov
FloatingText (Damage Numbers)
Execution
AddObject<T> Method
Uses the GetPooledObject method to see if the specified object is in the list.
Adds the list of game objects at the start of runtime with a game object and its count as arguments.
GetPooledObject<T> Method
Implemented a generic method for readability and reusability.
Iterates through the 2D list.
Verifies the correct list by checking if the first element contains the specified component.
Returns the first element that is not active.
Scripts calling for a pooled object and the object itself handle its active state.