feat(teapot): add TeaPot with tap-to-pour tilt animation
This commit is contained in:
34
scenes/objects/TeaPot.tscn
Normal file
34
scenes/objects/TeaPot.tscn
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://cozypaw_teapot"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://scripts/objects/tea_pot.gd" id="1_teapot"]
|
||||||
|
|
||||||
|
[node name="TeaPot" type="Node2D"]
|
||||||
|
script = ExtResource("1_teapot")
|
||||||
|
|
||||||
|
[node name="PotBody" type="ColorRect" parent="."]
|
||||||
|
offset_left = -30.0
|
||||||
|
offset_top = -50.0
|
||||||
|
offset_right = 30.0
|
||||||
|
offset_bottom = 0.0
|
||||||
|
color = Color(0.96, 0.92, 0.84, 1)
|
||||||
|
|
||||||
|
[node name="PotLid" type="ColorRect" parent="."]
|
||||||
|
offset_left = -28.0
|
||||||
|
offset_top = -58.0
|
||||||
|
offset_right = 28.0
|
||||||
|
offset_bottom = -48.0
|
||||||
|
color = Color(0.74, 0.62, 0.50, 1)
|
||||||
|
|
||||||
|
[node name="PotSpout" type="ColorRect" parent="."]
|
||||||
|
offset_left = 26.0
|
||||||
|
offset_top = -38.0
|
||||||
|
offset_right = 46.0
|
||||||
|
offset_bottom = -22.0
|
||||||
|
color = Color(0.96, 0.92, 0.84, 1)
|
||||||
|
|
||||||
|
[node name="PotHandle" type="ColorRect" parent="."]
|
||||||
|
offset_left = -48.0
|
||||||
|
offset_top = -36.0
|
||||||
|
offset_right = -36.0
|
||||||
|
offset_bottom = -14.0
|
||||||
|
color = Color(0.96, 0.92, 0.84, 1)
|
||||||
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