feat(teapot): add TeaPot with tap-to-pour tilt animation
This commit is contained in:
37
scripts/objects/tea_pot.gd
Normal file
37
scripts/objects/tea_pot.gd
Normal file
@@ -0,0 +1,37 @@
|
||||
## TeaPot — tap to pour: tilts 45 degrees, holds briefly, then returns to upright.
|
||||
class_name TeaPot extends Node2D
|
||||
|
||||
enum State { IDLE, POURING }
|
||||
|
||||
const TILT_ANGLE: float = 45.0
|
||||
const TILT_DURATION: float = 0.4
|
||||
const POUR_HOLD: float = 0.8
|
||||
const RETURN_DURATION: float = 0.4
|
||||
const BUTTON_HALF_SIZE: float = 40.0
|
||||
|
||||
var _state: State = State.IDLE
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if _state != State.IDLE:
|
||||
return
|
||||
if not event is InputEventScreenTouch:
|
||||
return
|
||||
var touch: InputEventScreenTouch = event as InputEventScreenTouch
|
||||
if not touch.pressed:
|
||||
return
|
||||
var local: Vector2 = to_local(touch.position)
|
||||
if abs(local.x) > BUTTON_HALF_SIZE or abs(local.y) > BUTTON_HALF_SIZE:
|
||||
return
|
||||
_start_pouring()
|
||||
|
||||
|
||||
func _start_pouring() -> void:
|
||||
_state = State.POURING
|
||||
var tween: Tween = create_tween()
|
||||
tween.set_ease(Tween.EASE_IN_OUT)
|
||||
tween.set_trans(Tween.TRANS_SINE)
|
||||
tween.tween_property(self, "rotation_degrees", TILT_ANGLE, TILT_DURATION)
|
||||
tween.tween_interval(POUR_HOLD)
|
||||
tween.tween_property(self, "rotation_degrees", 0.0, RETURN_DURATION)
|
||||
tween.finished.connect(func() -> void: _state = State.IDLE)
|
||||
Reference in New Issue
Block a user