Tough_Crowd/godot/scenes/objects/bottle.gd

42 lines
1.2 KiB
GDScript

extends Sprite2D
signal hit_tim
@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():
tim_global_position = get_node("/root/IngameScene/Stage/Tim/ThrowPoint").global_position
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())
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
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)
func _on_bottle_area_entered(area):
is_hidding = true
func _on_bottle_area_exited(area):
is_hidding = false
func _on_growth_timer_timeout():
var t = create_tween()
t.tween_property(self, "scale", self.scale + Vector2(0.01, 0.01), 0.02)
func remove_bottle():
if is_hidding:
print("Ouch")
Signals.hit_tim.emit()
queue_free()