Chapter 26 — Game Architecture and States
Part 2A — 2D Game Fundamentals · Chapter 26 of 62 · 8 hrs
Chapter 26 — Game Architecture and States
Level: intermediate Estimated time: 8 hrs Prerequisites: chapters 20 to 25 (game loop,
Canvas, sprites, physics, collisions, camera) and chapters 8 to 11 of PART 1A (OOP, inheritance, abstract classes, enums) What you will be able to do by the end: organize a complete game into separate entities, states, services, and files, instead of a single unreadablemain.dart.
26.0 — Chapter objectives
By the end of this chapter, you will be able to:
- explain why a 2000-line file always ends up blocking a project;
- separate a game's data, logic, and rendering;
- define precisely what an entity is;
- write an abstract
Entityclass and subclass it cleanly; - split the work between
update(double dt)andrender(Canvas canvas); - manage a list of entities and its update loop;
- diagnose and fix the concurrent modification bug;
- set up add and remove queues;
- control the render order with a
priorityfield; - build an
Entity → Character → Player / Enemyhierarchy and see its limits; - replace a deep inheritance chain with composition;
- explain the principle of an ECS (entity, component, system);
- compare ECS and classic OOP in a decision table;
- describe Flame's model, a component tree;
- define a game state and write the
GameStateenum; - draw the state machine of a complete game;
- implement menu, game, pause, game over, and victory;
- apply the State pattern: one class per screen;
- stack states to display a pause screen on top of the game;
- decouple the keyboard from actions with an input manager;
- offer key remapping;
- make objects communicate without coupling them through an event bus;
- centralize score, lives, and progress in a data service;
- recognize the dangers of the Singleton and practice simple dependency injection;
- organize the files of a game project;
- decide what to test in a game and write those tests;
- assemble the complete mini-engine of PART 2A;
- explain precisely what Flame will bring in chapter 27.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion