Pixel Dungeon Architecture Diagrams

Class Hierarchy and Game Flow Analysis

Class Diagram

The following diagram illustrates the core class hierarchy of Pixel Dungeon, including game structure, actors, items, and level generation systems.

classDiagram %% 타일맵 시스템 (S1) class DungeonTilemap { +int SIZE +create() +map(int cell) +screenToTile(int x, int y) +tileCenterToWorld(int pos) } class TerrainFeaturesTilemap { -Plant plants -Trap traps +discover(int pos) +plant(Plant plant, int pos) +trap(Trap trap, int pos) } DungeonTilemap <|-- DungeonTerrainTilemap DungeonTilemap <|-- TerrainFeaturesTilemap %% 턴 기반 시스템 (S2) class Actor { -float time #int actPriority +act() boolean #void spend(float time) +static void process() +static void add(Actor actor) +static void remove(Actor actor) +static Char findChar(int pos) } class Char { +int pos +int HP +int HT +string sprite +boolean act() +void spend(float time) +void move(int step) +void onMotionComplete() +int defenseSkill(Char enemy) +int attackSkill(Char target) +void damage(int dmg, Object src) +void die(Object cause) } class Blob { } Actor <|-- Char Actor <|-- Blob %% 카메라 시스템 (S3) class Camera { +float zoom +string scroll +void update() +void center(float x, float y) +void resize(int width, int height) +static void reset() } %% 마우스 입력 시스템 (S4) class CellSelector { +Listener listener +boolean enabled +boolean select(int cell) +void cancel() +interface Listener } class PointerEvent { +int button +int x +int y +boolean handled } CellSelector --> PointerEvent : processes %% 절차적 맵 생성 (S5, S6) class Level { +int width() +int height() +int length() +int[] map +boolean[] visited +boolean[] mapped +boolean[] passable +boolean[] losBlocking +void create() +void set(int cell, int terrain) +int pointToCell(int x, int y) +int cellToPoint(int cell) } class RegularLevel { -Room rooms +void create() -void createRooms() -void createMobs() -void createItems() } class Builder { +RegularLevel level -Room rooms +build() void +void connectRooms() +void assignRoomType() } Level <|-- RegularLevel RegularLevel --> Builder : uses %% 층간 이동 시스템 (S7) class LevelTransition { +int cell +int destLevel +int destCell +Type type +enum Type } class Dungeon { +static Hero hero +static Level level +static int depth +static void switchLevel(Level level, int pos) +static Level newLevel() } Dungeon --> Level : manages Dungeon --> LevelTransition : uses %% 특수 룸 생성 (S8) class Room { +string rect +Room neighbors +int distance +int price +paint(Level level) void +void connect(Room room) } class SpecialRoom { +paint(Level level) void +static runSpecials() void } class ShopRoom { +void paint(Level level) -void placeShopkeeper(Level level) -void placeItems(Level level) } Room <|-- SpecialRoom SpecialRoom <|-- ShopRoom %% 시야 및 탐색 시스템 (S10) class FogOfWar { +boolean[] visible +boolean[] visited +boolean[] mapped +void updateVisibility(boolean[] visible, boolean[] visited, boolean[] mapped) } class Awareness { +int duration +float distance +void update() } %% 함정 시스템 (S11) class Trap { +int pos +boolean visible +boolean active +trigger() void +void activate() +void disarm() } TerrainFeaturesTilemap --> Trap : displays

Note: The diagram shows the primary relationships between classes. Some simplifications were made for clarity. The PD-classes repository provides base classes while the pixel-dungeon repository contains the game implementation.

Sequence Diagram

The following sequence diagram illustrates the main game flow, including initialization, level generation, turn processing, and combat.

sequenceDiagram participant Game participant Dungeon participant Level participant Builder participant Room participant GameActor participant Char participant Trap participant FogOfWar %% 절차적 맵 생성 프로세스 (S5, S6) Game->>Dungeon: newLevel() Dungeon->>RegularLevel: new RegularLevel() RegularLevel->>RegularLevel: create() RegularLevel->>Builder: build() Builder->>Builder: createRooms() Builder->>Builder: connectRooms() Builder->>Builder: assignRoomType() loop 각 방에 대해 Builder->>Room: paint(level) opt 특수 방인 경우 Room->>SpecialRoom: paint(level) opt 상점인 경우 SpecialRoom->>ShopRoom: paint(level) ShopRoom->>ShopRoom: placeShopkeeper(level) ShopRoom->>ShopRoom: placeItems(level) end end end RegularLevel->>RegularLevel: createMobs() RegularLevel->>RegularLevel: createItems() RegularLevel->>RegularLevel: createTraps() %% 턴 처리 프로세스 (S2) Game->>Game: step() Game->>Game: update() Game->>GameActor: process() loop 각 액터에 대해 GameActor->>GameActor: act() opt 액터가 Char인 경우 GameActor->>Char: act() Char->>Char: spend(time) Char-->>GameActor: 행동 완료 end end %% 층간 이동 프로세스 (S7) Char->>Dungeon: newLevel() Dungeon->>Level: create() Dungeon->>Dungeon: switchLevel(level, pos) Dungeon->>GameActor: init() %% 시야 계산 프로세스 (S10) Char->>Level: updateFieldOfView() Level->>FogOfWar: updateVisibility(visible, visited, mapped) FogOfWar->>FogOfWar: updateTexture() %% 함정 작동 프로세스 (S11) Char->>Level: move(step) Level->>Trap: discover(pos) Level->>Trap: trigger() Trap->>Trap: activate() Trap->>Char: affect(Char)

Note: This sequence diagram illustrates the main game flow, focusing on initialization, level generation, and turn-based gameplay. The actual implementation may have additional complexity. The turn system in Pixel Dungeon is based on time units spent by each Actor.

Key Game Components

Actor System

The Actor system is the foundation of all entities that can take actions in the game. Actors are scheduled to act based on time spent. The main classes in this hierarchy are:

  • Actor: Base class with timing system
  • Char: Living entities with health and position
  • Mob: Enemies with AI states
  • Hero: Player-controlled character
  • Buff: Temporary effects on characters

Item System

The Item system handles all collectible objects in the game. Items can be used, equipped, or thrown. Major categories include:

  • Weapon: Melee weapons, missile weapons
  • Armor: Protective equipment with glyphs
  • Wand: Magical devices with charges
  • Potion: Consumable effects
  • Scroll: Single-use magical items
  • Ring: Passive effect items

Level Generation

Levels are procedurally generated using a room-based approach:

  • Level: Base class with map data
  • RegularLevel: Standard level with rooms
  • Room: Rectangular areas with various types
  • Painter: Renders room contents to the map

The generation process: initialize rooms → place doors → add items → add monsters → place traps.

Rendering System

The visual representation is handled by scene classes:

  • Scene: Base visual container
  • PixelScene: Pixel-art specific rendering
  • GameScene: Main gameplay screen
  • DungeonTilemap: Renders level tiles
  • CharSprite: Visual representation of characters