2025-09-04 05:48:51 +00:00
|
|
|
@tool
|
|
|
|
extends Event2D
|
|
|
|
|
|
|
|
# var prev_stage := 0
|
|
|
|
# var stage := 0
|
|
|
|
|
2025-09-05 08:35:57 +00:00
|
|
|
@onready var puppet1 = $"Pro木头人1" as ProAnimatedSprite2D
|
|
|
|
@onready var puppet2 = $"Pro木头人2" as ProAnimatedSprite2D
|
|
|
|
@onready var puppet3 = $"Pro木头人3" as ProAnimatedSprite2D
|
|
|
|
@onready var puppets = [puppet1, puppet2, puppet3]
|
|
|
|
|
2025-09-04 05:48:51 +00:00
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
super._ready()
|
|
|
|
if Engine.is_editor_hint():
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
func _on_global_stage_updated(e: StringName, s: int) -> void:
|
|
|
|
super._on_global_stage_updated(e, s)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_ground_ready(_ground: Ground2D) -> void:
|
2025-09-05 08:35:57 +00:00
|
|
|
_on_stage_updated()
|
2025-09-04 05:48:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_pre_stage_updated() -> void:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
func _on_stage_updated() -> void:
|
2025-09-05 08:35:57 +00:00
|
|
|
# c04_puppet_game: 0:初始化 1:开始游戏 2:游戏胜利
|
|
|
|
match stage:
|
|
|
|
0:
|
|
|
|
var ambush = $"Ambush木头人1" as Ambush2D
|
|
|
|
ambush.enabled = true
|
|
|
|
ambush.triggered.connect(_welcome_animation.bind(0, ambush))
|
|
|
|
1:
|
|
|
|
puppet1.animation = "木头人游戏1_进门动作"
|
|
|
|
puppet1.frame = puppet1.sprite_frames.get_frame_count("木头人游戏1_进门动作") - 1
|
|
|
|
puppet2.animation = "木头人游戏2_进门动作"
|
|
|
|
puppet2.frame = puppet2.sprite_frames.get_frame_count("木头人游戏2_进门动作") - 1
|
|
|
|
puppet3.animation = "木头人游戏3_进门动作"
|
|
|
|
puppet3.frame = puppet3.sprite_frames.get_frame_count("木头人游戏3_进门动作") - 1
|
|
|
|
# 玩家移动时,开启游戏
|
|
|
|
SceneManager.get_player().position_updated.connect(_on_player_position_updated)
|
|
|
|
2:
|
|
|
|
puppet1.animation = "木头人游戏1_胜利"
|
|
|
|
puppet1.frame = puppet1.sprite_frames.get_frame_count("木头人游戏1_胜利") - 1
|
|
|
|
puppet2.animation = "木头人游戏2_胜利"
|
|
|
|
puppet2.frame = puppet2.sprite_frames.get_frame_count("木头人游戏2_胜利") - 1
|
|
|
|
puppet3.animation = "木头人游戏3_胜利"
|
|
|
|
puppet3.frame = puppet3.sprite_frames.get_frame_count("木头人游戏3_胜利") - 1
|
|
|
|
|
|
|
|
|
|
|
|
# 邀请动作
|
|
|
|
func _welcome_animation(id: int, ambush) -> void:
|
|
|
|
ambush.enabled = false
|
|
|
|
puppets[id].play("木头人游戏%s_进门动作" % (id + 1))
|
|
|
|
|
|
|
|
|
|
|
|
# 0:not started yet; 1-3:started; 4:finished.
|
|
|
|
var game_stage := 0
|
|
|
|
|
|
|
|
|
|
|
|
func _on_player_position_updated(pos: Vector2) -> void:
|
|
|
|
if game_stage == 4:
|
|
|
|
return
|
|
|
|
if game_stage == 0:
|
|
|
|
# 开始游戏
|
|
|
|
game_stage = 1
|
|
|
|
# 所有 puppet 聚光
|
|
|
|
spot_light = 4
|
|
|
|
# 从第一个开始游戏
|
|
|
|
spot_light = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
######## 控制聚光灯
|
|
|
|
|
|
|
|
const SPOT_LIGHT_ENERGY = 0.3
|
|
|
|
const SPOT_LIGHT_TWEEN_DURATION = 0.5
|
|
|
|
|
|
|
|
# 控制聚光灯,哪个木头人被关注
|
|
|
|
# 0:无 1:一号 2:二号 3:三号 4:全部
|
|
|
|
var spot_light = 0:
|
|
|
|
set(val):
|
|
|
|
if spot_light != val:
|
|
|
|
# 从 4 到其他
|
|
|
|
var current_lighting: Array = _get_lighting_puppets(spot_light)
|
|
|
|
var target_lighting: Array = _get_lighting_puppets(spot_light)
|
|
|
|
for p in current_lighting:
|
|
|
|
if not target_lighting.has(p):
|
|
|
|
# turn off
|
|
|
|
create_tween().tween_property(
|
|
|
|
p.get_node("PointLight2D"), "energy", 0.0, SPOT_LIGHT_TWEEN_DURATION
|
|
|
|
)
|
|
|
|
for p in target_lighting:
|
|
|
|
if not current_lighting.has(p):
|
|
|
|
# turn on
|
|
|
|
create_tween().tween_property(
|
|
|
|
p.get_node("PointLight2D"),
|
|
|
|
"energy",
|
|
|
|
SPOT_LIGHT_ENERGY,
|
|
|
|
SPOT_LIGHT_TWEEN_DURATION
|
|
|
|
)
|
|
|
|
spot_light = val
|
|
|
|
|
|
|
|
|
|
|
|
func _get_lighting_puppets(mode: int) -> Array:
|
|
|
|
var arr = []
|
|
|
|
match mode:
|
|
|
|
4:
|
|
|
|
arr = [puppet1, puppet2, puppet3]
|
|
|
|
1:
|
|
|
|
arr = [puppet1]
|
|
|
|
2:
|
|
|
|
arr = [puppet2]
|
|
|
|
3:
|
|
|
|
arr = [puppet3]
|
|
|
|
return arr
|