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 %% 기본 UI 레이아웃 (C1) class PixelScene { +Camera uiCamera +float minZoom +float maxZoom +void create() +void destroy() +void onBackPressed() +void update() } class GameScene { -SkinnedBlock water -DungeonTilemap tiles -FogOfWar fog -HeroSprite hero -Group terrain -Group customTiles -Group mobs -Group heaps -Group effects +void create() +void update() +void onBackPressed() +void cellClicked(int cell) } class Group { +ArrayList~Gizmo~ members +void add(Gizmo g) +void remove(Gizmo g) +void update() +void draw() } class Camera { +float zoom +PointF scroll +void update() +void center(float x, float y) } PixelScene <|-- GameScene GameScene --> Group : contains PixelScene --> Camera : uses %% 플레이어 상태 표시 UI (C2) class StatusPane { -Image avatar -HealthIndicator health -BuffIndicator buffs -Resource gold -Resource energy -Button btnInventory +void layout() +void update() } class HealthIndicator { -float health -float shield +void update() +void level(float value) +void health(float value) } class BuffIndicator { -ArrayList~BuffIcon~ buffIcons +void update() +void addBuff(Buff buff) +void removeBuff(Buff buff) } StatusPane --> HealthIndicator : contains StatusPane --> BuffIndicator : contains %% 인벤토리 UI (C3) class WndBag { +Mode mode +Listener listener +ArrayList~Item~ items +void updateItems() +void onItemClick(Item item) +enum Mode } class InventoryPane { -ArrayList~ItemSlot~ slots +void update() +void layout() +void onItemClick(Item item) } class ItemSlot { -Item item -ItemSprite sprite +void update() +void item(Item item) +void enable(boolean value) } WndBag --> ItemSlot : contains InventoryPane --> ItemSlot : contains %% 전투 피드백 UI (C4) class FloatingText { +void show(float x, float y, String text, int color) +void update() } class CharSprite { +void showStatus(int color, String text) +void showAlert(String text) +void blood(int from) +void die() } class EmoIcon { +Type type +void update() +enum Type } CharSprite --> FloatingText : uses CharSprite --> EmoIcon : contains %% 아이템 정보 UI (C5) class WndInfoItem { -ItemSprite image -RenderedTextBlock titleText -RenderedTextBlock descText +void onBackPressed() } class ItemSprite { -Item item -Glowing glowing +void view(Item item) +void update() } class Tooltip { +String text +void update() +void show(String text, int color) } WndInfoItem --> ItemSprite : contains ItemSprite --> Tooltip : uses %% 맵/미니맵 UI (C6) class Compass { +void update() +void visible(boolean value) } %% 메뉴 및 설정 UI (C7) class WndGame { +void createButtons() +void onBackPressed() } class WndSettings { +void createControls() +void onBackPressed() } class MenuPane { -Button btnMenu -Button btnSettings -Button btnInfo +void layout() +void update() } MenuPane --> WndGame : opens MenuPane --> WndSettings : opens %% 몬스터, 아이템, 장비, 보스 (C8-C11) class Mob { +int EXP +int defenseSkill +boolean hostile +CharSprite sprite +boolean act() +int attackSkill(Char target) +int damageRoll() +void die(Object cause) } class Item { +String name +String desc +int image +int quantity +boolean unique +void execute(Hero hero, String action) +ArrayList~String~ actions(Hero hero) +String info() } class EquipableItem { +boolean isEquipped(Hero hero) +boolean doEquip(Hero hero) +boolean doUnequip(Hero hero) } class MeleeWeapon { +int tier +int min() +int max() +int damageRoll(Char owner) +float accuracyFactor(Char owner) +float speedFactor(Char owner) } class Armor { +int tier +int DRMin() +int DRMax() +int DRRoll() +int defenseProc(Char attacker, Char defender, int damage) } class Boss { +int defenseSkill +int damageRoll() +void damage(int dmg, Object src) +void die(Object cause) +void notice() } Item <|-- EquipableItem EquipableItem <|-- MeleeWeapon EquipableItem <|-- Armor Mob <|-- Boss %% 상점 UI 및 시스템 (C12) class ShopRoom { +void paint(Level level) -void placeShopkeeper(Level level) -void placeItems(Level level) } class Shopkeeper { +void interact(Hero hero) +boolean act() } class WndTradeItem { -ItemSprite itemSprite -int price +void sell() +void buy() } ShopRoom --> Shopkeeper : places Shopkeeper --> WndTradeItem : opens %% 게임 튜토리얼 (C13) class WndStory { +void tell(String text) +void onBackPressed() } class Banner { +BannerSprites type +void show(BannerSprites type) +void update() } class Guidebook { +void execute(Hero hero, String action) +String info() } Item <|-- Guidebook

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 GameScene participant StatusPane participant InventoryPane participant WndBag participant ItemSlot participant WndInfoItem participant CharSprite participant FloatingText participant Shopkeeper participant WndTradeItem participant WndStory %% UI 초기화 및 레이아웃 프로세스 (C1, C2) GameScene->>GameScene: create() GameScene->>StatusPane: new StatusPane() StatusPane->>StatusPane: layout() StatusPane->>HealthIndicator: new HealthIndicator() StatusPane->>BuffIndicator: new BuffIndicator() GameScene->>InventoryPane: new InventoryPane() InventoryPane->>InventoryPane: layout() loop 각 아이템 슬롯에 대해 InventoryPane->>ItemSlot: new ItemSlot() ItemSlot->>ItemSlot: item(item) end %% 인벤토리 관리 프로세스 (C3) GameScene->>InventoryPane: onClick() InventoryPane->>WndBag: new WndBag(Mode.ALL) WndBag->>WndBag: updateItems() loop 각 아이템에 대해 WndBag->>ItemSlot: new ItemSlot(item) end WndBag->>WndBag: onItemClick(item) WndBag->>WndInfoItem: new WndInfoItem(item) WndInfoItem->>WndInfoItem: layout() %% 아이템 사용 및 장착 프로세스 (C5, C8-C11) WndBag->>Item: execute(hero, action) alt 장비 아이템인 경우 Item->>EquipableItem: doEquip(hero) EquipableItem->>Hero: belongings.equip(this) Hero->>StatusPane: update() else 소모품인 경우 Item->>Item: detach(hero.belongings.backpack) Item->>Item: onUse() end %% 상점 상호작용 프로세스 (C12) Hero->>Shopkeeper: interact() Shopkeeper->>WndTradeItem: new WndTradeItem(item, price) WndTradeItem->>WndTradeItem: layout() alt 구매하는 경우 WndTradeItem->>WndTradeItem: buy() WndTradeItem->>Hero: belongings.backpack.add(item) WndTradeItem->>Gold: spend(price) else 판매하는 경우 WndTradeItem->>WndTradeItem: sell() WndTradeItem->>Hero: belongings.backpack.remove(item) WndTradeItem->>Gold: collect(price) end %% 전투 피드백 표시 프로세스 (C4) Hero->>Mob: attack(mob) Mob->>Mob: damage(dmg, hero) Mob->>CharSprite: showStatus(color, damage) CharSprite->>FloatingText: show(x, y, text, color) alt 몹이 사망한 경우 Mob->>CharSprite: die() CharSprite->>CharSprite: play(deathAnim) end %% 튜토리얼 표시 프로세스 (C13) GameScene->>WndStory: new WndStory(text) WndStory->>WndStory: tell(text) alt 튜토리얼 아이템 사용 Hero->>Guidebook: execute(hero, action) Guidebook->>WndStory: new WndStory(chapter) end

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