Tough_Crowd/godot/scenes/objects/bottle.gd

42 lines
1.2 KiB
GDScript3
Raw Normal View History

2024-01-27 14:50:20 +00:00
extends Sprite2D
2024-01-27 19:34:39 +00:00
signal hit_tim
2024-01-27 14:50:20 +00:00
@export var bottle_speed: float = 120;
var tim_global_position: Vector2
var is_hidding: bool
# Called when the node enters the scene tree for the first time.
func _ready():
2024-01-27 20:20:16 +00:00
tim_global_position = get_node("/root/IngameScene/Stage/Tim/ThrowPoint").global_position
2024-01-28 13:57:01 +00:00
tim_global_position += _random_inside_unit_circle() * 23
rotation_degrees += randf() * 360
func _random_inside_unit_circle() -> Vector2:
var theta : float = randf() * 2 * PI
return Vector2(cos(theta), sin(theta)) * sqrt(randf())
2024-01-27 14:50:20 +00:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
2024-01-27 20:20:16 +00:00
var t = create_tween().set_parallel()
t.tween_property(self, "global_position", tim_global_position, 3.0)
t.tween_property(self, "rotation_degrees", rotation_degrees + 270, 3.0)
t.tween_callback(remove_bottle).set_delay(3.05)
2024-01-27 14:50:20 +00:00
func _on_bottle_area_entered(area):
2024-01-27 20:20:16 +00:00
is_hidding = true
2024-01-27 14:50:20 +00:00
func _on_bottle_area_exited(area):
2024-01-27 20:20:16 +00:00
is_hidding = false
2024-01-27 14:50:20 +00:00
func _on_growth_timer_timeout():
2024-01-27 20:20:16 +00:00
var t = create_tween()
t.tween_property(self, "scale", self.scale + Vector2(0.01, 0.01), 0.02)
2024-01-27 14:50:20 +00:00
func remove_bottle():
2024-01-27 20:20:16 +00:00
if is_hidding:
print("Ouch")
Signals.hit_tim.emit()
queue_free()