godot-genre-simulation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGenre: Simulation / Tycoon
游戏类型:模拟/大亨类
Optimization, systems mastery, and satisfying feedback loops define management games.
优化、系统掌控和令人愉悦的反馈循环是管理类游戏的核心特质。
Available Scripts
可用脚本
sim_tick_manager.gd
sim_tick_manager.gd
Expert tick-based simulation with variable speed control and batch processing.
基于tick的专业模拟系统,支持变速控制和批量处理。
Core Loop
核心循环
Invest → Build/Manage → Generate Income → Optimize → Expand投资 → 建造/管理 → 产生收益 → 优化 → 扩张NEVER Do in Simulation Games
模拟游戏开发绝对禁忌
- NEVER process every simulated entity individually in — Batch updates in fixed ticks (e.g., once per second). Simulating 1000 businesses individually = 60k calls/second. Batch = 1k calls/second.
_process() - NEVER use floating-point for currency — accumulates rounding errors. $1.10 * 3 = $3.2999999. Use
floatcents:intcents = $33.00 exact.1100 * 3 = 3300 - NEVER let early game be dull waiting — Front-load decision points. First 5 minutes must hook players. Don't make them wait 10 real minutes for first unlock.
- NEVER use linear cost scaling — Buildings that cost break at level 100 (1000 cost). Use exponential:
10 * levelcreates meaningful trade-offs.BASE * pow(1.5, level) - NEVER hide critical numbers from players — Show income/expense breakdown, production rates, efficiency %. Optimization games require transparency.
- NEVER allow infinite resource stacking without consequence — Storage caps create interesting decisions. Unlimited resources remove strategy.
- NEVER update UI labels every frame — Updating 50 UI labels @60fps = 3000 updates/sec. Use signals: update only when value changes.
- 绝对不要在中单独处理每个模拟实体 —— 采用固定tick批量更新(例如每秒一次)。单独模拟1000个商家会导致每秒6万次调用,而批量处理仅需每秒1千次调用。
_process() - 绝对不要用浮点数处理货币 —— 会产生累计舍入误差。例如$1.10×3的计算结果会是$3.2999999。应使用整数表示美分:
float美分,即准确的$33.00。1100×3=3300 - 绝对不要让前期游戏枯燥等待 —— 前置关键决策点。前5分钟必须吸引玩家,不要让他们等待10分钟才能解锁第一个内容。
- 绝对不要使用线性成本缩放 —— 成本为的建筑在等级100时会崩溃(成本达1000)。使用指数增长:
10 * level能创造有意义的权衡选择。BASE * pow(1.5, level) - 绝对不要向玩家隐藏关键数据 —— 展示收支明细、生产速率、效率百分比。优化类游戏需要信息透明。
- 绝对不要允许资源无限堆叠而无后果 —— 存储上限能创造有趣的决策场景,无限资源会消除策略性。
- 绝对不要每帧更新UI标签 —— 每秒60帧更新50个UI标签会产生3000次更新/秒。应使用信号:仅在数值变化时更新。
Economy Design
经济系统设计
The heart of any tycoon game is its economy. Key principle: multiple interconnected resources that force trade-offs.
大亨类游戏的核心是经济系统。关键原则:多个相互关联的资源,迫使玩家做出权衡选择。
Multi-Resource System
多资源系统
gdscript
class_name TycoonEconomy
extends Node
signal resource_changed(resource_type: String, amount: float)
signal went_bankrupt
var resources: Dictionary = {
"money": 10000.0,
"reputation": 50.0, # 0-100
"workers": 0,
"materials": 100.0,
"energy": 100.0
}
var resource_caps: Dictionary = {
"reputation": 100.0,
"workers": 50,
"energy": 1000.0
}
func modify_resource(type: String, amount: float) -> bool:
if amount < 0 and resources[type] + amount < 0:
if type == "money":
went_bankrupt.emit()
return false # Can't go negative
resources[type] = clamp(
resources[type] + amount,
0,
resource_caps.get(type, INF)
)
resource_changed.emit(type, resources[type])
return truegdscript
class_name TycoonEconomy
extends Node
signal resource_changed(resource_type: String, amount: float)
signal went_bankrupt
var resources: Dictionary = {
"money": 10000.0,
"reputation": 50.0, # 0-100
"workers": 0,
"materials": 100.0,
"energy": 100.0
}
var resource_caps: Dictionary = {
"reputation": 100.0,
"workers": 50,
"energy": 1000.0
}
func modify_resource(type: String, amount: float) -> bool:
if amount < 0 and resources[type] + amount < 0:
if type == "money":
went_bankrupt.emit()
return false # Can't go negative
resources[type] = clamp(
resources[type] + amount,
0,
resource_caps.get(type, INF)
)
resource_changed.emit(type, resources[type])
return trueIncome/Expense Tracking
收支追踪
gdscript
class_name FinancialTracker
extends Node
var income_sources: Dictionary = {} # source_name: amount_per_tick
var expense_sources: Dictionary = {}
signal financial_update(profit: float, income: float, expenses: float)
func calculate_tick() -> float:
var total_income := 0.0
var total_expenses := 0.0
for source in income_sources.values():
total_income += source
for source in expense_sources.values():
total_expenses += source
var profit := total_income - total_expenses
financial_update.emit(profit, total_income, total_expenses)
return profitgdscript
class_name FinancialTracker
extends Node
var income_sources: Dictionary = {} # source_name: amount_per_tick
var expense_sources: Dictionary = {}
signal financial_update(profit: float, income: float, expenses: float)
func calculate_tick() -> float:
var total_income := 0.0
var total_expenses := 0.0
for source in income_sources.values():
total_income += source
for source in expense_sources.values():
total_expenses += source
var profit := total_income - total_expenses
financial_update.emit(profit, total_income, total_expenses)
return profitTime System
时间系统
Simulation games need controllable time:
gdscript
class_name SimulationTime
extends Node
signal time_tick(delta_game_hours: float)
signal day_changed(day: int)
signal speed_changed(new_speed: int)
enum Speed { PAUSED, NORMAL, FAST, ULTRA }
@export var seconds_per_game_hour := 30.0 # Real seconds
var current_speed := Speed.NORMAL
var speed_multipliers := {
Speed.PAUSED: 0.0,
Speed.NORMAL: 1.0,
Speed.FAST: 3.0,
Speed.ULTRA: 10.0
}
var current_hour := 8.0 # Start at 8 AM
var current_day := 1
func _process(delta: float) -> void:
if current_speed == Speed.PAUSED:
return
var game_delta := (delta / seconds_per_game_hour) * speed_multipliers[current_speed]
current_hour += game_delta
if current_hour >= 24.0:
current_hour -= 24.0
current_day += 1
day_changed.emit(current_day)
time_tick.emit(game_delta)
func set_speed(speed: Speed) -> void:
current_speed = speed
speed_changed.emit(speed)模拟游戏需要可控制的时间系统:
gdscript
class_name SimulationTime
extends Node
signal time_tick(delta_game_hours: float)
signal day_changed(day: int)
signal speed_changed(new_speed: int)
enum Speed { PAUSED, NORMAL, FAST, ULTRA }
@export var seconds_per_game_hour := 30.0 # Real seconds
var current_speed := Speed.NORMAL
var speed_multipliers := {
Speed.PAUSED: 0.0,
Speed.NORMAL: 1.0,
Speed.FAST: 3.0,
Speed.ULTRA: 10.0
}
var current_hour := 8.0 # Start at 8 AM
var current_day := 1
func _process(delta: float) -> void:
if current_speed == Speed.PAUSED:
return
var game_delta := (delta / seconds_per_game_hour) * speed_multipliers[current_speed]
current_hour += game_delta
if current_hour >= 24.0:
current_hour -= 24.0
current_day += 1
day_changed.emit(current_day)
time_tick.emit(game_delta)
func set_speed(speed: Speed) -> void:
current_speed = speed
speed_changed.emit(speed)Entity Management
实体管理
Workers/NPCs
工人/NPC
gdscript
class_name Worker
extends Node
enum State { IDLE, WORKING, RESTING, COMMUTING }
@export var wage_per_hour: float = 10.0
@export var skill_level: float = 1.0 # Productivity multiplier
@export var morale: float = 80.0 # 0-100
var current_state := State.IDLE
var assigned_workstation: Workstation
func update(game_hours: float) -> void:
match current_state:
State.WORKING:
if assigned_workstation:
var productivity := skill_level * (morale / 100.0)
assigned_workstation.work(game_hours * productivity)
morale -= game_hours * 0.5 # Working tires workers
State.RESTING:
morale = min(100.0, morale + game_hours * 2.0)
func calculate_hourly_cost() -> float:
return wage_per_hourgdscript
class_name Worker
extends Node
enum State { IDLE, WORKING, RESTING, COMMUTING }
@export var wage_per_hour: float = 10.0
@export var skill_level: float = 1.0 # Productivity multiplier
@export var morale: float = 80.0 # 0-100
var current_state := State.IDLE
var assigned_workstation: Workstation
func update(game_hours: float) -> void:
match current_state:
State.WORKING:
if assigned_workstation:
var productivity := skill_level * (morale / 100.0)
assigned_workstation.work(game_hours * productivity)
morale -= game_hours * 0.5 # Working tires workers
State.RESTING:
morale = min(100.0, morale + game_hours * 2.0)
func calculate_hourly_cost() -> float:
return wage_per_hourBuildings/Facilities
建筑/设施
gdscript
class_name Facility
extends Node3D
@export var build_cost: Dictionary # resource_type: amount
@export var operating_cost_per_hour: float = 5.0
@export var capacity: int = 5
@export var output_per_hour: Dictionary # resource_type: amount
var assigned_workers: Array[Worker] = []
var is_operational := true
var efficiency := 1.0
func calculate_output(game_hours: float) -> Dictionary:
if not is_operational or assigned_workers.is_empty():
return {}
var worker_efficiency := 0.0
for worker in assigned_workers:
worker_efficiency += worker.skill_level * (worker.morale / 100.0)
worker_efficiency /= capacity # Normalize to 0-1
var result := {}
for resource in output_per_hour:
result[resource] = output_per_hour[resource] * game_hours * worker_efficiency * efficiency
return resultgdscript
class_name Facility
extends Node3D
@export var build_cost: Dictionary # resource_type: amount
@export var operating_cost_per_hour: float = 5.0
@export var capacity: int = 5
@export var output_per_hour: Dictionary # resource_type: amount
var assigned_workers: Array[Worker] = []
var is_operational := true
var efficiency := 1.0
func calculate_output(game_hours: float) -> Dictionary:
if not is_operational or assigned_workers.is_empty():
return {}
var worker_efficiency := 0.0
for worker in assigned_workers:
worker_efficiency += worker.skill_level * (worker.morale / 100.0)
worker_efficiency /= capacity # Normalize to 0-1
var result := {}
for resource in output_per_hour:
result[resource] = output_per_hour[resource] * game_hours * worker_efficiency * efficiency
return resultCustomer/Demand System
顾客/需求系统
gdscript
class_name CustomerSimulation
extends Node
@export var base_customers_per_hour := 10.0
@export var demand_curve: Curve # Hour of day vs demand multiplier
var customer_queue: Array[Customer] = []
func generate_customers(game_hour: float, delta_hours: float) -> void:
var demand_mult := demand_curve.sample(game_hour / 24.0)
var reputation_mult := Economy.resources["reputation"] / 50.0 # 100 rep = 2x customers
var customers_to_spawn := base_customers_per_hour * delta_hours * demand_mult * reputation_mult
for i in int(customers_to_spawn):
spawn_customer()
func spawn_customer() -> void:
var customer := Customer.new()
customer.patience = randf_range(30.0, 120.0) # Seconds before leaving
customer.spending_budget = randf_range(10.0, 100.0)
customer_queue.append(customer)gdscript
class_name CustomerSimulation
extends Node
@export var base_customers_per_hour := 10.0
@export var demand_curve: Curve # Hour of day vs demand multiplier
var customer_queue: Array[Customer] = []
func generate_customers(game_hour: float, delta_hours: float) -> void:
var demand_mult := demand_curve.sample(game_hour / 24.0)
var reputation_mult := Economy.resources["reputation"] / 50.0 # 100 rep = 2x customers
var customers_to_spawn := base_customers_per_hour * delta_hours * demand_mult * reputation_mult
for i in int(customers_to_spawn):
spawn_customer()
func spawn_customer() -> void:
var customer := Customer.new()
customer.patience = randf_range(30.0, 120.0) # Seconds before leaving
customer.spending_budget = randf_range(10.0, 100.0)
customer_queue.append(customer)Feedback Systems
反馈系统
Visual Feedback
视觉反馈
gdscript
undefinedgdscript
undefinedMoney flying to bank, resources flowing, etc.
Money flying to bank, resources flowing, etc.
class_name ResourceFlowVisualizer
extends Node
func show_income(amount: float, from: Vector2, to: Vector2) -> void:
var coin := coin_scene.instantiate()
coin.position = from
add_child(coin)
var tween := create_tween()
tween.tween_property(coin, "position", to, 0.5)
tween.tween_callback(coin.queue_free)
var label := Label.new()
label.text = "+$" + str(int(amount))
label.position = from
add_child(label)
var label_tween := create_tween()
label_tween.tween_property(label, "position:y", label.position.y - 30, 0.5)
label_tween.parallel().tween_property(label, "modulate:a", 0.0, 0.5)
label_tween.tween_callback(label.queue_free)undefinedclass_name ResourceFlowVisualizer
extends Node
func show_income(amount: float, from: Vector2, to: Vector2) -> void:
var coin := coin_scene.instantiate()
coin.position = from
add_child(coin)
var tween := create_tween()
tween.tween_property(coin, "position", to, 0.5)
tween.tween_callback(coin.queue_free)
var label := Label.new()
label.text = "+$" + str(int(amount))
label.position = from
add_child(label)
var label_tween := create_tween()
label_tween.tween_property(label, "position:y", label.position.y - 30, 0.5)
label_tween.parallel().tween_property(label, "modulate:a", 0.0, 0.5)
label_tween.tween_callback(label.queue_free)undefinedStatistics Dashboard
统计面板
gdscript
class_name StatsDashboard
extends Control
@export var graph_history_hours := 24
var income_history: Array[float] = []
var expense_history: Array[float] = []
func record_financial_tick(income: float, expenses: float) -> void:
income_history.append(income)
expense_history.append(expenses)
# Keep last N entries
while income_history.size() > graph_history_hours:
income_history.pop_front()
expense_history.pop_front()
queue_redraw()
func _draw() -> void:
# Draw income/expense graph
draw_line_graph(income_history, Color.GREEN)
draw_line_graph(expense_history, Color.RED)gdscript
class_name StatsDashboard
extends Control
@export var graph_history_hours := 24
var income_history: Array[float] = []
var expense_history: Array[float] = []
func record_financial_tick(income: float, expenses: float) -> void:
income_history.append(income)
expense_history.append(expenses)
# Keep last N entries
while income_history.size() > graph_history_hours:
income_history.pop_front()
expense_history.pop_front()
queue_redraw()
func _draw() -> void:
# Draw income/expense graph
draw_line_graph(income_history, Color.GREEN)
draw_line_graph(expense_history, Color.RED)Progression & Unlocks
进度与解锁系统
gdscript
class_name UnlockSystem
extends Node
var unlocks: Dictionary = {
"basic_facility": true,
"advanced_facility": false,
"marketing": false,
"automation": false
}
var unlock_conditions: Dictionary = {
"advanced_facility": {"money_earned": 50000},
"marketing": {"reputation": 70},
"automation": {"workers_hired": 20}
}
var progress: Dictionary = {
"money_earned": 0.0,
"workers_hired": 0
}
func check_unlocks() -> Array[String]:
var newly_unlocked: Array[String] = []
for unlock in unlock_conditions:
if unlocks[unlock]:
continue # Already unlocked
var conditions := unlock_conditions[unlock]
var all_met := true
for condition in conditions:
if progress.get(condition, 0) < conditions[condition]:
all_met = false
break
if all_met:
unlocks[unlock] = true
newly_unlocked.append(unlock)
return newly_unlockedgdscript
class_name UnlockSystem
extends Node
var unlocks: Dictionary = {
"basic_facility": true,
"advanced_facility": false,
"marketing": false,
"automation": false
}
var unlock_conditions: Dictionary = {
"advanced_facility": {"money_earned": 50000},
"marketing": {"reputation": 70},
"automation": {"workers_hired": 20}
}
var progress: Dictionary = {
"money_earned": 0.0,
"workers_hired": 0
}
func check_unlocks() -> Array[String]:
var newly_unlocked: Array[String] = []
for unlock in unlock_conditions:
if unlocks[unlock]:
continue # Already unlocked
var conditions := unlock_conditions[unlock]
var all_met := true
for condition in conditions:
if progress.get(condition, 0) < conditions[condition]:
all_met = false
break
if all_met:
unlocks[unlock] = true
newly_unlocked.append(unlock)
return newly_unlockedCommon Pitfalls
常见陷阱
| Pitfall | Solution |
|---|---|
| Economy too easy to break | Extensive balancing, soft caps, diminishing returns |
| Boring early game | Front-load interesting decisions, quick early progression |
| Information overload | Progressive disclosure, collapsible UI panels |
| No clear goals | Milestones, achievements, scenarios |
| Tedious micromanagement | Automation unlocks, batch operations |
| 陷阱 | 解决方案 |
|---|---|
| 经济系统容易崩溃 | 广泛平衡、软上限、收益递减 |
| 前期游戏枯燥 | 前置有趣决策、快速前期进度 |
| 信息过载 | 渐进式披露、可折叠UI面板 |
| 目标不明确 | 里程碑、成就、场景模式 |
| 繁琐的微管理 | 自动化解锁、批量操作 |
Godot-Specific Tips
Godot专属技巧
- UI: Use nodes extensively,
Controlfor lists,Treefor connectionsGraphEdit - Performance: Process entities in batches, not every frame
- Save/Load: Convert all game state to Dictionary for JSON serialization
- Isometric view: Use with orthographic projection
Camera2D
- UI:大量使用节点,用
Control实现列表,用Tree实现连接GraphEdit - 性能:批量处理实体,而非每帧处理
- 存档/读档:将所有游戏状态转换为Dictionary以支持JSON序列化
- 等距视角:使用带正交投影的
Camera2D
Reference
参考
- Master Skill: godot-master
- 核心技能:godot-master