7c78a088a0
The three diamonds and both doors were painted as tiles in TerrainBase, which cannot act as pickups or triggers. Replaced them with real prefabs that reuse the same atlas tiles (diamond = (7,3), doors = (10,6) and (11,5)) and erase their placeholder tile on ready. Collecting all three diamonds unlocks the door; touching it fades to black, pauses the tree and shows the level-clear screen with a next-level button (currently reloads the level, as there is only one). HUD now shows the diamond count.
73 lines
2.1 KiB
GDScript
73 lines
2.1 KiB
GDScript
extends CanvasLayer
|
|
|
|
## 过关界面:集齐钻石后碰到门显示。
|
|
## 显示时把整棵树暂停,所以这一层的 process_mode 设成 ALWAYS(见 .tscn),
|
|
## 不然暂停后自己的动画和按钮也会停。
|
|
|
|
@export var fade_time: float = 0.8
|
|
@export var button_delay: float = 0.3
|
|
|
|
var _fade: ColorRect = null
|
|
var _center: CenterContainer = null
|
|
var _button: Button = null
|
|
var _title: Label = null
|
|
var _subtitle: Label = null
|
|
var _elapsed: float = 0.0
|
|
var _showing: bool = false
|
|
|
|
|
|
func _ready() -> void:
|
|
visible = false
|
|
_fade = get_node_or_null("Fade")
|
|
_center = get_node_or_null("Center")
|
|
_button = get_node_or_null("Center/VBox/NextButton")
|
|
_title = get_node_or_null("Center/VBox/Title")
|
|
_subtitle = get_node_or_null("Center/VBox/Subtitle")
|
|
if _button != null:
|
|
_button.pressed.connect(next_level)
|
|
if _fade != null:
|
|
_fade.color = Color(0.0, 0.0, 0.0, 0.0)
|
|
if _center != null:
|
|
_center.visible = false
|
|
|
|
|
|
func show_clear() -> void:
|
|
if _showing:
|
|
return
|
|
_showing = true
|
|
visible = true
|
|
_elapsed = 0.0
|
|
if _title != null:
|
|
_title.text = "过关!"
|
|
if _subtitle != null:
|
|
var player := get_tree().get_first_node_in_group("player")
|
|
var n: int = 0 if player == null else int(player.diamonds)
|
|
_subtitle.text = "钻石 %d / %d" % [n, n]
|
|
get_tree().paused = true
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
if not _showing:
|
|
return
|
|
_elapsed += delta
|
|
if _fade != null:
|
|
_fade.color = Color(0.0, 0.0, 0.0, clampf(_elapsed / maxf(fade_time, 0.01), 0.0, 1.0))
|
|
if _center != null and _elapsed >= fade_time + button_delay:
|
|
_center.visible = true
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if not _showing:
|
|
return
|
|
var key := event as InputEventKey
|
|
if key != null and key.pressed and not key.echo:
|
|
if key.physical_keycode == KEY_R or key.physical_keycode == KEY_ENTER:
|
|
next_level()
|
|
|
|
|
|
## 目前项目里只有一关,所以"下一关"先做成重新加载本关。
|
|
## 以后真加了第二关,把这里换成 change_scene_to_file("res://scenes/level2.tscn") 即可。
|
|
func next_level() -> void:
|
|
get_tree().paused = false
|
|
get_tree().reload_current_scene()
|