Skip to content
bozar edited this page May 9, 2024 · 1 revision

Appendix A

This article shows the project folder structure (extracted from Chapter 0), and briefly explains the game loop.

Folder Structure

  • scene/: Store every scene in a separate folder, for example, 'scene/main/'.
  • sprite/: Everything you can see in the game, for example: PC, NPCs, grounds and buildings.
  • resource/: Images that are used to create sprites. Fonts. Icons. Text files for dungeon generation.
  • library/: Scripts that are not attached to a node.
  • autoload/: Scripts that are autoloaded.
  • user/: Files for players: help document and setting.json.
  • bin/: A private folder to store exported games for testing. Do not add a .gitkeep file to it.

The Game Loop

Below is the scene tree of the main screen.

MainScreen
    - SpriteRoot
    - PlayerInput
    - PcAction
        -- PcFov
    - InitWorld
    - SpriteCoord
    - SpriteTag
    - Schedule
    - ActorAction
    - Sidebar
        -- ...
    - RandomNumber
    - GameProgress
    - HelpScreen
        -- ...
    - DebugScreen
        -- ...

MainScreen is the root node of the scene tree. The game is initialized in MainScreen._ready().

func _ready() -> void:
    _connect_signals(NodeReference.SIGNAL_CONNECTIONS)
    _connect_nodes(NodeReference.NODE_CONNECTIONS)

    if TransferData.load_setting_file:
        SettingFile.load()
        TransferData.set_load_setting_file(false)

    VisualEffect.set_background_color()
    $RandomNumber.set_initial_seed(TransferData.rng_seed)
    $InitWorld.create_world()
    $Sidebar.init_gui()
    $HelpScreen.init_gui()
    $DebugScreen.init_gui()
    $Schedule.start_next_turn()

Firstly, call two private functions to connect signals and set node references based on the data in library/node_reference.gd.

autoload/transfer_data.gd contains data that will be shared between scenes. library/setting_file.gd provides a static public function to load custom settings from data/setting.json. If the file does not exist or is invalid, the game throws no error and uses default settings instead.

library/visual_effect.gd can change sprite/background color, switch sprites, and set sprite visibility.

RandomNumber is a direct child node of MainScreen, so do all the nodes below.

InitWorld generates a dungoen based on templates in resource/dungeon_prefab/. A sprite is created by autoload/sprite_factory.gd. All sprites are child nodes of MainScreen/SpriteRoot. Sprite data is stored in SpriteCoord and SpriteTag, and can be accessed by autoload/sprite_state.gd.

Sidebar, HelpScreen and DebugScreen are three GUI panels. They are the root nodes of their own scene trees.

Schedule lets PC and NPCs act in turn. All actor sprites are stored in a circular, doubly linked list.

When player presses a key, it is verified by PlayerInput and then sent to PcAction, HelpScreen or DebugScreen. PC's field of view is rendered by recursive shadow casting algorithm in PcFov. ActorAction guides NPCs to approach by Dijkstra pathfinding and hit PC. GameProgress decides when to spawn new NPCs or end the game if player wins/loses.

Clone this wiki locally