godot-game-loop-collection

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Collection Game Loops

收集游戏循环

Overview

概述

This skill provides a standardized framework for "Collection Loops" – gameplay objectives where the player must find and gather a specific set of items (e.g., hidden eggs, data logs, coins).
本Skill为“收集循环”提供了标准化框架——这类玩法目标要求玩家寻找并收集一组特定物品(例如:隐藏彩蛋、数据日志、金币)。

Core Components

核心组件

1. Collection Manager (
collection_manager.gd
)

1. 收集管理器(
collection_manager.gd

The central brain of the hunt.
  • Role: Tracks progress (
    current / target
    ).
  • Behavior: Listens for
    item_collected(id)
    -> Updates items -> Signals
    collection_completed
    on valid count.
  • Tip: Use
    collection_id
    strings to run multiple hunts simultaneously (e.g., "red_eggs" vs "blue_eggs").
寻宝系统的核心大脑。
  • 作用:追踪进度(
    当前数量/目标数量
    )。
  • 行为:监听
    item_collected(id)
    信号 -> 更新物品状态 -> 当数量达标时发送
    collection_completed
    信号。
  • 提示:使用
    collection_id
    字符串可同时运行多个寻宝任务(例如:“red_eggs”与“blue_eggs”)。

2. Collectible Item (
collectible_item.gd
)

2. 可收集物品(
collectible_item.gd

The physical object in the world.
  • Role: Handles interaction and self-destruction.
  • Behavior: On Interact -> Play VFX -> Emit Signal -> Queue Free.
游戏世界中的实体对象。
  • 作用:处理交互与自销毁逻辑。
  • 行为:当触发交互时 -> 播放视觉特效(VFX) -> 发送信号 -> 调用Queue Free销毁自身。

3. Hidden Item Spawner (
hidden_item_spawner.gd
)

3. 隐藏物品生成器(
hidden_item_spawner.gd

Automates the placement of items.
  • Role: Populates the level.
  • Behavior: Instantiates the item scene at:
    • Hand-placed
      Marker3D
      nodes (Deterministic).
    • Random points within a
      CollisionShape
      volume (Procedural).
自动放置物品的工具。
  • 作用:填充关卡内容。
  • 行为:在以下位置实例化物品场景:
    • 手动放置的
      Marker3D
      节点(确定性生成)。
    • CollisionShape
      体积内的随机点(程序化生成)。

Usage Example

使用示例

gdscript
undefined
gdscript
undefined

In a Level Script or Game Mode

In a Level Script or Game Mode

@onready var manager = $CollectionManager
func _ready(): manager.start_collection("easter_egg_2024", 10) manager.collection_completed.connect(_on_all_eggs_found)
func _on_all_eggs_found(): print("You found all the eggs! Here is a bunny hat.") # Unlock reward
undefined
@onready var manager = $CollectionManager
func _ready(): manager.start_collection("easter_egg_2024", 10) manager.collection_completed.connect(_on_all_eggs_found)
func _on_all_eggs_found(): print("You found all the eggs! Here is a bunny hat.") # Unlock reward
undefined

Best Practices

最佳实践

  • Persistence: Combine with
    godot-mechanic-secrets
    to save which specific IDs have been found if the player needs to quit and resume.
  • NEVER hardcode spawn positions in code: Always use
    Marker3D
    or
    CollisionShape3D
    nodes in the scene so designers can adjust layout without touching code.
  • Avoid "God Objects": The
    CollectionManager
    shouldn't handle input, UI, AND audio. Let it emit signals and let other systems react.
  • Juice: Always spawn particles or play a sound before the item disappears. Immediate
    queue_free()
    feels dry.
  • 持久化:结合
    godot-mechanic-secrets
    ,可保存玩家已找到的特定物品ID,支持玩家退出后继续游戏。
  • 绝对不要在代码中硬编码生成位置:始终在场景中使用
    Marker3D
    CollisionShape3D
    节点,这样设计师无需修改代码即可调整布局。
  • 避免“上帝对象”
    CollectionManager
    不应同时处理输入、UI和音频。让它发送信号,由其他系统响应即可。
  • 增加趣味性(Juice):物品消失前务必生成粒子特效或播放音效。直接调用
    queue_free()
    会让体验显得枯燥。