Skip to content

Commit

Permalink
绑定 R 按键和 esc 案件,实现关卡重置
Browse files Browse the repository at this point in the history
  • Loading branch information
ligen131 committed Jan 27, 2024
1 parent 34e6b86 commit 4d16180
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions levels/base_level/base_level.gd
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,13 @@ func _on_card_put() -> void:
block.call("shake")
else:
stage_clear()


func _input(event: InputEvent):
if event is InputEventKey:
if event.keycode == KEY_R and event.pressed:
_on_replay_button_pressed()
if event.keycode == KEY_ESCAPE and event.pressed:
_on_back_button_pressed()


func _on_back_button_pressed():
Expand All @@ -191,5 +197,5 @@ func _on_back_button_pressed():


func _on_replay_button_pressed():
print("TO-DO here to handle replay")
pass
for card_base: CardBase in $CardBases.get_children():
card_base.reset_all_card_position()
4 changes: 4 additions & 0 deletions levels/chapter_menu/level_menu/level_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func _on_button_enter_level(chap_id: int, lvl_id: int) -> void:
get_tree().root.add_child(base_level)
queue_free()

func _input(event: InputEvent):
if event is InputEventKey:
if event.keycode == KEY_ESCAPE and event.pressed:
_on_back_button_pressed()

func _on_back_button_pressed():
var ChapterMenu = load("res://levels/chapter_menu/chapter_menu.tscn")
Expand Down
4 changes: 4 additions & 0 deletions objects/card_base/card_base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func set_victory() -> void:
for card: Card in $Cards.get_children():
card.is_victory = true

func reset_all_card_position():
for card: Card in $Cards.get_children():
card.reset_position()

func _process(delta) -> void:
if fade_flag:
var offset = $FadeTimer.time_left / $FadeTimer.wait_time
Expand Down

0 comments on commit 4d16180

Please sign in to comment.