Roguelike Chibi

University project

Carlos Requena Doña avatar

Carlos Requena Doña

Artificial intelligence, 3D graphics and video games

Roguelike Chibi is a roguelike video game developed in Unity. The game features procedurally generated dungeons, characters and enemies with a Chibi aesthetic, an AI system based on Context Steering, and a modular architecture focused on object reuse and separation of concerns.

🚀 Key Features

  • Context Steering AI: Artificial intelligence for enemies based on weight vectors and danger/interest maps.
  • Two Enemy Types: Minions that chase directly and Warriors that maintain distance and flank the player.
  • Procedural Generation: Dungeons generated from presets based on the chosen character and difficulty.
  • Object Pool: Reuse system for weapon instances to optimize memory usage.
  • Animation System: IAnimatorUsaObjeto interface managing movement, attack, and item usage animations.
  • Character & Difficulty Selection: Available from the main menu before starting the game.
  • Controller Support: Options menu with key remapping and controller support.

🛠️ Tech Stack

  • Engine: Unity
  • Language: C#
  • Patterns: Singleton, Object Pool, Observer (static events), State Machine (State Enum)
  • Data Design: Scriptable Objects for potion buffs and item configurations
  • AI: Context Steering (based on specialized game AI literature)

🤖 Artificial Intelligence — Context Steering

The AI system is the technical core of the project. Each enemy evaluates an array of possible directions and assigns a weight to each one using the dot product between the candidate direction and the desired direction (usually towards the player).

Weights are adjusted based on:

  • Distance to player: Higher weight the closer they are.
  • Safety distance: Warriors penalize directions that bring them too close.
  • Danger and Interest Maps: Mask base weights to avoid collisions and adapt movement to the environment.

Enemy Types

TypeBehavior
MinionChases the player directly without advanced Context Steering.
WarriorMaintains distance and flanks the player using the full weight vector.

Both types attack when in range and respect a cooldown time between attacks. Enemy weapons are assigned randomly from the Object Pool.

📦 Object Pool

The Object Pool is a system for managing pre-created instances. At the start of the game, ~20 weapons are instantiated from a set of prefabs. When an enemy or chest needs a weapon, it retrieves one from the pool without creating new instances at runtime. When an enemy dies, the weapon is returned to the pool for reuse.

This pattern reduces Garbage Collector impact and stabilizes performance during gameplay.

🏺 Interactable Elements

Interactable elements follow a hierarchy based on interfaces and inheritance:

IInteractableElement
├── Item
│   ├── Weapon        ← Collision object vector, self-damage logic
│   └── Potion        ← Buff as Scriptable Object
├── Door              ← Normal door / Exit door
├── Key               ← Opens doors, stored in player's list
└── Container         ← Chests with animation

Weapons autonomously manage their own collision logic: they search for a Hitbox implementing IDamagable and apply damage, ensuring it isn’t applied twice to the same target in a single attack animation.

Items emit a golden glow when the player aims at them, providing immediate visual feedback.

🎨 User Interface (UI)

Player Health

Represented by five red hearts, each equivalent to 20% of total health. Hearts turn black proportionally as health is lost.

Pause Menu

Accessible anytime during gameplay, with three options:

  • Resume Game
  • Options (Volume + Key remapping for keyboard and controller)
  • Exit to Main Menu

Start screen with direct access to Character Selection, where the user can navigate between characters and choose difficulty before starting.

⚙️ Unity Architecture

The project is organized into three main scenes:

  1. Main Menu: Characters with animations, UI management, music, and clearing of static events between scenes.
  2. Loading Screen: Callback ensuring loading is complete before showing the new scene.
  3. Game Scene: Contains all game managers.

Main Managers

ManagerResponsibility
GameInputCaptures input and notifies movement, attack, and interaction via events.
GameManagerSingleton controlling game state (Playing / Paused / Victory / GameOver) and score.
SoundManagerSubscribes to events from other classes and plays centralized sound effects.
MusicManagerPlays background music and exposes volume control.
DungeonCreatorSelects dungeon preset based on chosen character and difficulty.
DamageFeedbackManagerChanges player and enemy materials upon taking damage for visual feedback.

State Management

Game state is managed as an ENUM with values Playing, Paused, Victory, and GameOver. Thanks to the Singleton pattern in GameManager, any game object can query or react to the current state easily.

📝 Highlighted Code Snippet

// Direction selection via Context Steering
float bestWeight = float.MinValue;
Vector2 bestDirection = Vector2.zero;

for (int i = 0; i < directions.Length; i++)
{
    // Dot product between candidate direction and direction to player
    float weight = Vector2.Dot(directions[i], toPlayer.normalized);

    // Adjustment by danger map
    weight -= dangerMap[i];

    // Adjustment by interest map
    weight += interestMap[i];

    if (weight > bestWeight)
    {
        bestWeight = weight;
        bestDirection = directions[i];
    }
}

🎓 Key Learnings

This project allowed me to:

  • Implement Context Steering, an AI technique from specialized video game literature.
  • Apply the Object Pool pattern to optimize real-time memory management.
  • Design a clean class hierarchy with interfaces and inheritance in C#.
  • Manage global game state with Singletons and state machines.
  • Centralize cross-cutting logic (sound, feedback, scoring) in independent managers.
  • Work with Unity Scriptable Objects for reusable item data.