7 Separating asset data and logic

 

This chapter covers

  • Separating asset data from logic to reduce code complexity and speed up development.
  • Implementing a menu system using data-oriented design.

In this chapter, we’ll examine how separating the asset data from the logic can help reduce code complexity and speed up the development process. To do so, we’ll implement new menus in our survivor game and expand the existing ones.

To implement a menu, we need to work together with designers and artists. Before we can start writing the code for a menu, we need access to the asset data, specifically the dynamic parts of the asset that need to be set and updated every time the menu is called: from linking buttons to functions, to setting strings to specific values, to showing and hiding UI elements based on player actions.

What happens very often during menu development is that someone, be it art or engineering, misses a crucial part of the design. Maybe the engineer forgot to implement something, or art forgot to add a UI component. Then the asset needs to be passed back and forth multiple times, as shown in Figure 7.1.

Figure 7.1 A typical menu development flow, where assets need to be passed back and forth between art and engineering due to missing assets and code.

7.1 Separating menu data from logic

7.2 The main menu implementation

7.2.1 Understanding the asset data problem

7.2.2 Separating asset data from logic

7.2.3 Introducing the meta data

7.2.4 The main menu implementation

7.3 The game over menu implementation

7.3.1 Init()

7.3.2 Show()

7.3.3 Hide()

7.3.4 goToMainMenu()

7.4 The pause menu implementation

7.5 The in-game menu implementation

7.6 Connecting the menus in the game loop

7.6.1 Referencing the menus

7.7 Building complex menus

7.8 Conclusion

7.9 Summary