Solution Samples
A collection of software architecture models and code samples used in my game projects, such as character behaviour state machines, inventory and procedural generated map systems.
Character Behaviour State Machine
Above is the UML representation of a C# Behaviour State Machine implementation. It was used in Kasoré and keeps being used to aid the implementation of different character mechanics.
Benefits:
State based modularization, easier maintenance.
Possibility of creating machines for different groups of characters with different states (i.e.: PlayerMachine [Walk, Fall, Jump] and EnemyMachine [Patrol, Hunt]).
The entry and exit methods are executed when a state begins and right before transitioning to the next one, which helps organizing when sfx and animations should play and stop.
The Behaviour classes contains the implementation for the functionality of each state, in which they are called.
Each State inherits the State’s Update method, which works just like Unity’s Update. In this method, called every frame, there are several checks to decide if the state should transition, in to which one.
2D Procedural Map Generation
A system to procedurally generate maps for 2D games based on the map generation of Spelunky.
Generates predefined square rooms separated by types. These types are defined by the location of the room’s exit or exits.
The height and width of the map needs to be defined beforehand
The Spawner class has the the abstract method Spawn, which is implemented by its children classes, responsible for instantiating rooms, various objects and enemies to populate the map. Each spawner needs to have access to an array or list of what is designed to instantiate.
The logic that determines if something can spawn or where it should spawn is contained within the Level Generation class.
Simple Inventory System
This diagram describes a simple inventory system with 2 basic mechanics:
The player can pick up items.
The player can drop items.
Items of the same kind are grouped up on the same slot, incrementing its item quantity.
This system was used on the Pirate Ship demo to aid in quest objectives.
Long-term Relationship Model Between the Player and NPC
This is the class diagram for an academic project, which goal was to describe and implement a new relationship model between the player and the NPCs. This new model can then be used to decide an NPC’s behaviour towards the player using as basis the empathy calculated between them. To calculate that empathy we capture the player’s personality in runtime inside the Big Five Personality Model using his answers to 10 dialogues with the NPCs. This method is known as BFGI-10 ( Big Five Game Inventory 10 ).
The Big Five Personality Model represents a personality as a set of 5 traits:
Openness to new experiences
Conscientiousness
Extraversion
Agreeableness
Neuroticism
Each trait has its own way of being determined, which is why the method CalculateTrait is overriden in each one.
The empathy model I developed consists of 5 levels of empathy between the player and the NPC, each defining how the NPC will behave in relation to the player ( i.e.: being helpful, neutral or actively trying to make the player’s objective harder ):
Sympathetic
Comprehensive
Neutral
Incomprehensive
Unsympathetic