feat(home-button): add HomeButton component for hospital/garden navigation
This commit is contained in:
21
scripts/objects/home_button.gd
Normal file
21
scripts/objects/home_button.gd
Normal file
@@ -0,0 +1,21 @@
|
||||
## HomeButton — tappable button that navigates between the hospital and the garden area.
|
||||
class_name HomeButton extends Node2D
|
||||
|
||||
const BUTTON_HALF_SIZE: float = 32.0
|
||||
|
||||
@export var go_to_garden: bool = true
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not event is InputEventScreenTouch:
|
||||
return
|
||||
if not (event as InputEventScreenTouch).pressed:
|
||||
return
|
||||
var touch_pos: Vector2 = (event as InputEventScreenTouch).position
|
||||
var local: Vector2 = to_local(touch_pos)
|
||||
if abs(local.x) > BUTTON_HALF_SIZE or abs(local.y) > BUTTON_HALF_SIZE:
|
||||
return
|
||||
if go_to_garden:
|
||||
RoomNavigator.go_to_home()
|
||||
else:
|
||||
RoomNavigator.go_to_hospital()
|
||||
Reference in New Issue
Block a user