< Back

Rogueframe

Screenshot of gameplay

An extended generation of the 'Wrinkly' map type

An extended generation of the 'Islands' map type

Languages: C#

Technologies: Unity, Netcode for Gameobjects

Skills: Networking, Procedural Generation, UI

Overview

Summary of Gameplay

Rogueframe (better name pending) is a WIP vertical slice of a co-op class-based horde shooter. It aims to provide lots of mechanical character customisation alongside varied objectives, allowing for players to assume roles in groups and tailor their win conditions to their preferred playstyles. The concept is loosely inspired by systems and mechanics from Risk of Rain 2 and Warframe.

Technical Overview

Technical Details

Architecture

Scenes and Game Loop

The player can host/join a session from the main menu, which takes players to the Lobby scene. The lobby scene handles players joining and leaving, as well as their character selection and ready state through various RPCs. Once all players are ready, the game scene is loaded. Shared and otherwise persistent networked state, such as player character choices, is stored on a singleton PersistentStateManager. This singleton also handles the periphery of the game loop: the loading screen, generation of maps and changing of scenes. There is only a single game scene. The terrain is procedurally generated by an RPC call when players load the scene. The map is generated based on a seed and chosen generator stored in PersistentStateManager.mapState. This scene is then re-loaded when a new level is needed. The game scene contains an EnemySpawnManager and an ObjectiveManager, which handle those tasks respectively.

Data Objects

The game is almost entirely data driven, and is architected in a way to support dynamic addition of content (such as DLC or mods). To support this, there is a global “SODatabase”. This loads various other lists of content stored in ScriptableObjects (Unity’s preferred form of data asset), and builds a dictionary mapping them to string UUIDs. When joining a lobby, the hosts’s database is synced with the joining client’s via these UUIDs, constructing an identical list which allows more efficient communication over the network via integer indices. This is accessed through a static variable SODatabase.NetworkedDB. Characters, Abilities, Enemies and Maps are constructed and customised by ScriptableObjects. Characters have their health, speed, abilities and model determined by the SO. Enemies have their health pools and difficulty scaling set, and Abilities are constructed from IAbilityData objects stored in SOs.

Other OOP Structures

Character health and other resources (such as energy) are constructed as StatInstances. DefenseStatInstances are combined into a DefensePool. DefenseStatInstances can have DefenseGates (e.g. preventing damage from overflowing from one health type to another) as well as a ReductionStat. StatInstances can have StatModifiers, modifying the gain/loss of a stat; its maximum value; or providing it with regeneration (or a loss over time). CharacterStates store DefensePools, and also receive StatusEffects in the form of StatusInstances. Saving settings is done through SaveSystem, which consists of Registered Files -> Registered Categories -> Registered Values. These values can be referenced through the SaveSystem static methods, or by their ScriptableObjects.

Key Systems

Abilities

Abilities can be hard-coded, as is done with the Flamethrower ability, but they can also be constructed piecemeal as ICostCheckers, ITargetCheckers and ICastEffects. These are used in a hierarchical manner, with the first two determining whether an effect can happen, and if so which one, and the ICastEffect executes the logic. ITargetCheckers and ICastEffects have different logic on the owner, server and connected clients, allowing for owner anticipation of effects with server verification. These 3 components are linked together by a series of lists and dictionaries in the GenericAbility class. This allows for maximum re-use of components (which in turn minimises the potential for issues with inconsistency when upgrades are applied). Abilities can also have effects applied at the start of cast, while the cast is held and at the end of the cast. The flamethrower demonstrates all 3 of these, while the other abilities are all applied at end of cast. To allow generic ability communication across the network, objects inheriting from AbilityPayload are used. Classes derived from this class are gathered using reflection at startup in AbilityPayload.PopulateDeserializers, which is then used to provide a mapping at runtime. The struct AbilityNetworkPayload is used as a hack, since Netcode for Gameobjects cannot serialize polymorphic objects by default. Ability Casting is handled by the PlayerAbilityManager, which prevents overlapping ability casts and interfaces with Unity’s systems as well as providing a networking interface.

Map generation

Maps are generated by IMapGenerator implementations. My two generators (Islands and Wrinkly Mountains) use Perlin Noise provided by Mathf.PerlinNoise to generate a heightmap. They both use multiple layered octaves, as well as domain warping to provide their shapes. Since Unity’s noise function doesn’t use seeding, different octaves use randomised offsets instead. This heightmap is then fed into TerrainDrawer, which produces chunked meshes (allowing index magnitudes to stay below 16-bits). Each 4-point grid is split into 2 triangles, and these triangles are then checked against min and max height limits. If they are in violation then they are clipped using the Sutherland-Hodgman algorithm. Unity generates the normals for these meshes using built-in functions. To ensure border normals are correct, I generate the meshes with an extra ring on the outside, and then cut it off. This is not efficient, but it’s still performant enough for the use-case (and I did not want to differentiate the functions I made). Objectives are then placed into the map, with roughly one every 100m2. Islands can have more variety here, as it’s possible (though very unlikely) for an entire grid segment to be unsuitable. In this case, the space of valid positions slowly increases with failed iterations. Finally, a navmesh is built using unity’s AI package. Islands utilises two heightmaps, one for the top half of the islands and one for the bottom half. These both use the same base generation to ensure they match, and add their own more distinct effects when further away from the split point. They are both cropped below 0.5f.

Projectiles

Projectiles are handled by the ProjectileManager singleton. Clients anticipate their own projectiles being created, which is then verified or destroyed by the server, and propagated to other clients. “Dumb” projectiles are not synced beyond their start and end, with each client managing its own visual while the server handles collision logic. If the server determines the projectile should be destroyed, this is propagated to the clients with its exact location. The client’s visual is “fake”, spawning from a specified point such as the wizard’s staff. The real projectile is actually spawned from the camera, at the point where the fake point projects onto the ray. The fake slowly lerps between its trajectory and the true camera-based trajectory, with the lerp completing at the focus point determined by a raycast.

AI

Pathfinding and collision both use in-built Unity packages. The AI was implemented via customisable state machines, defined in SimpleMeleeState and SimpleProjectileState.