66 lines
1.7 KiB
GDScript
66 lines
1.7 KiB
GDScript
extends Node2D
|
|
|
|
|
|
@export var sprite : Sprite2D
|
|
@export var label : Label
|
|
@export var wind_speed_label : Label
|
|
var wind_speed : float = 30
|
|
#var move_speed : float = 20
|
|
var wind_acceleration : float = 0.2
|
|
var wind_change : float = 0.2
|
|
|
|
var move_acceleration : Vector2 = Vector2(0,0)
|
|
var move_change : Vector2 = Vector2(0,0)
|
|
var velocity : Vector2 = Vector2(0,0)
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
label.text = get_category()
|
|
wind_speed_label.text = str(round(wind_speed*10)/10)
|
|
sprite.rotation_degrees += 40 * delta
|
|
if wind_speed <= 0:
|
|
end_cyclone()
|
|
wind_acceleration += wind_change * delta
|
|
wind_acceleration = clampf(wind_acceleration, -5, 5)
|
|
wind_speed += wind_acceleration * delta
|
|
move_acceleration += move_change * delta
|
|
move_acceleration.x = clampf(move_acceleration.x, -5, 5)
|
|
move_acceleration.y = clampf(move_acceleration.y, -5, 5)
|
|
velocity += move_acceleration * delta
|
|
velocity.x = clampf(velocity.x, -3, 3)
|
|
velocity.y = clampf(velocity.y, -3, 3)
|
|
position += velocity * delta
|
|
|
|
|
|
func do_something():
|
|
wind_change = randf_range(-1,1)
|
|
move_change = Vector2(randf_range(-1,1),randf_range(-1,1))
|
|
pass
|
|
|
|
func end_cyclone():
|
|
queue_free()
|
|
|
|
func get_category() -> String:
|
|
if wind_speed >= 250:
|
|
return "5"
|
|
elif wind_speed >= 210:
|
|
return "4"
|
|
elif wind_speed >= 178:
|
|
return "3"
|
|
elif wind_speed >= 154:
|
|
return "2"
|
|
elif wind_speed >= 119:
|
|
return "1"
|
|
elif wind_speed >= 63:
|
|
return "TS"
|
|
else:
|
|
return "TD"
|
|
|
|
|
|
func _on_timer_timeout() -> void:
|
|
do_something()
|