# junieson/planegame architecture

> Architecture diagram of the GitHub repository junieson/planegame, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/junieson/planegame
- Repository: https://github.com/junieson/planegame

## Overview

##### Project type and purpose
- This is a single‐process, desktop 2D game built in Python using the Pygame library.
- It implements a classic “plane shooter” (“飞机大战”) where a player controls a hero aircraft, enemies spawn at intervals, power-ups (“buffs”) appear, and collisions trigger animations, sounds, score updates, and end‐game logic.

##### File structure
- Top‐level scripts:
- plane_main.py – the entry point, sets up the game loop, event handling, collision detection, and overall orchestration.
- plane_sprites.py – defines all sprite classes (Hero, Enemy, Boss, Bullet, Buff1/2/3, Background, etc.), plus helper classes (GameScore, bloodline, CanvasOver).
- Resource folders:
- images/ – PNG assets for backgrounds, planes, bullets, explosions, UI.
- music/ – WAV/OGG sound effects and background music.
- Configuration:
- requirements.txt lists dependencies (pygame).
- README.md describes features, gameplay mechanics, and the use of Pygame modules.

##### README for additional insights
- The README outlines the game loop phases: initialization, input handling, sprite updates, collision detection, rendering, and cleanup.
- It explains key Pygame concepts (Sprites, Groups, Event timers, Clock/tick, Rects, Blitting, and audio).

##### Essential details
- Timer IDs (CREATE_ENEMY_EVENT, HERO_FIRE_EVENT, etc.) feeding into the event handler.
- CanvasOver overlay and its event handling when game_over is true.
- Present the resource‐loading calls inside sprite constructors.

## Diagram (Mermaid)

```mermaid
flowchart TB
    main(("main()")):::engine
    main --> GameLoop(("Game Loop Controller")):::engine

    GameLoop --> Input["Input Handler"]:::logic
    GameLoop --> Timer["Event Timer Manager"]:::engine
    GameLoop --> Collision["Collision Detector"]:::logic
    GameLoop --> SpriteMgr["Sprite Manager"]:::logic
    GameLoop --> Renderer["Renderer"]:::rendering
    GameLoop --> Audio["Audio Manager"]:::rendering

    Timer -->|"spawn events"| SpriteMgr
    Input -->|"hero movement & bomb"| SpriteMgr
    Collision -->|"detect & update"| SpriteMgr
    SpriteMgr -->|"draw/update"| Renderer
    SpriteMgr -->|"state changes"| Audio
    SpriteMgr <--> Collision
    Collision -->|"game_over flag"| UI
    SpriteMgr --> UI

    ResourceLoader["Resource Loader"]:::assets
    ResourceLoader --> SpriteMgr

    UI["UI Overlay (CanvasOver)"]:::rendering

    AssetsImages["images/"]:::assets
    AssetsMusic["music/"]:::assets
    AssetsImages -.-> ResourceLoader
    AssetsMusic -.-> ResourceLoader

    click Input "https://github.com/junieson/planegame/blob/main/plane_main.py"
    click GameLoop "https://github.com/junieson/planegame/blob/main/plane_main.py"
    click Timer "https://github.com/junieson/planegame/blob/main/plane_main.py"
    click Collision "https://github.com/junieson/planegame/blob/main/plane_main.py"
    click Renderer "https://github.com/junieson/planegame/blob/main/plane_main.py"
    click ResourceLoader "https://github.com/junieson/planegame/tree/main/images/"
    click ResourceLoader "https://github.com/junieson/planegame/tree/main/music/"
    click SpriteMgr "https://github.com/junieson/planegame/blob/main/plane_sprites.py"
    click UI "https://github.com/junieson/planegame/blob/main/plane_sprites.py"
    click AssetsImages "https://github.com/junieson/planegame/tree/main/images/"
    click AssetsMusic "https://github.com/junieson/planegame/tree/main/music/"

    classDef engine fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef logic fill:#90EE90,stroke:#000,stroke-width:1px
    classDef rendering fill:#FFFFE0,stroke:#000,stroke-width:1px
    classDef assets fill:#D3D3D3,stroke:#000,stroke-width:1px
```
