Post

Slay the Spire 2 Code Analysis: Uncovering Hidden Patterns in Game DevelopmentThis video analyzes the code of Slay the Spire 2, revealing interesting development patterns and architecture. From separating game logic and engine interactions to a flexible effect system based on abstract models, gain deep insights into game development.
Slay the Spire 2 Code Analysis: Uncovering Hidden Patterns in Game Development
1. 🎮 Deconstructing Slay the Spire 2 Code and Analyzing the Development Environment
· We've directly disassembled the code of Slay the Spire 2 to explore its inner workings and code patterns.
· The separation of game logic and engine interaction code demonstrates good development practices.
· The codebase reflects a history of development initially in Unity, later transitioning to the Godot engine. This creates a unique structure of 'a game within a game engine, built within a game engine.'
00:00 - 00:41
1. 🎮 Deconstructing Slay the Spire 2 Code and Analyzing the Development Environment
· We've directly disassembled the code of Slay the Spire 2 to explore its inner workings and code patterns.
· The separation of game logic and engine interaction code demonstrates good development practices.
· The codebase reflects a history of development initially in Unity, later transitioning to the Godot engine. This creates a unique structure of 'a game within a game engine, built within a game engine.'
00:42 - 01:41
2. 🃏 Flexible Item Effect Handling Based on Abstract Models
· All in-game objects like cards, relics, statuses, and potions share a common ancestor called an 'abstract model.'
· This abstract model defines empty trigger functions called 'hooks,' allowing for systematic application of various effects during gameplay.
· 'Hooks' are called at specific moments such as 'after attack,' 'before card use,' or 'before combat start,' providing a clean structure for items to define their effects.
· This extensive base class design is simple yet maximizes flexibility, offering an expandable design space not only for developers but also for modders.

Item ExampleDescription
Basic Attack CardExtends the card model to deal damage and grant the player Strength for the turn via the 'on use' function.
It uses a 'damage command object' for damage processing and a 'power command object' for granting Strength.
Temporary Strength PowerDefines the functionality to grant Strength and remove it at the end of the turn. Each power has a unique name and icon.
01:42 - 02:55
3. 🔗 Handling Inter-Item Dependencies: Direct Reference Method
· There are inter-item dependencies, such as Accelerate triggering additional Poison powers, or Debilitate increasing the damage multiplier of Vulnerable powers.
· Surprisingly, these interactions are implemented through direct references between items, without any separate abstraction layer.
· For example, the Vulnerable power directly checks for the existence of powers like 'Paper Frog,' 'Envenom,' or 'Debilitate' and modifies the damage multiplier accordingly.
· Similarly, the Accelerate power checks for the presence of Poison powers to determine the number of times it triggers.
02:56 - 04:06
4. 📈 Damage Modification Hook Order: Additive, Multiplicative, and Damage Cap
· Damage modification hooks are not monolithic; they are categorized into types like additive, multiplicative, and damage cap, and are calculated in a specific order.
· This order is consistently maintained, ensuring the same final damage output regardless of the order in which relic or status effects are applied.
· Example: Vigor's bonus damage (additive) is applied first, then the damage is increased by an enemy's flank attack (multiplicative), and finally, a status effect like Slippery caps the damage at 1.
· This approach guarantees deterministic outcomes in gameplay and provides a clear effect application method for both developers and modders.
04:07 - 04:31
5. 🔄 Event Hook Granularity: 'Early' and 'Late' Hooks
· Events like 'after card drawn' have more granular hooks, such as 'after card drawn early.'
· This allows specific items to trigger their effects before being influenced by other items.
· Example: The 'Hellraiser' power automatically plays cards containing 'strike.' It uses the 'after card drawn early' hook to play the card immediately, bypassing the effects of status effects like 'Chains of Binding' that lock cards.
04:32 - 05:07
6. 📜 Implementing Card Abilities Using Combat History
· Abilities like the 'Murder' card, where damage increases based on the number of cards drawn this combat, or 'Voltaic,' which generates orbs based on the number of lightning orbs channeled this combat, are implemented by querying the 'Combat History' via the 'Combat Manager' instead of using internal counters.
· Since 'Combat History' already exists for statistics tracking and replay file saving, this information can be reused to efficiently implement card abilities.
· This is a more efficient and integrated approach compared to implementing counters manually, as might be done in a game jam.
슬레이더스파이어게임개발코드분석프로그래밍게임아키텍처