2024-05-12 00:47:14 -04:00
|
|
|
extends Area2D
|
|
|
|
|
2024-05-12 01:17:58 -04:00
|
|
|
# TODO: Have speeds be determined on a rage based on its "size"
|
|
|
|
# TODO: Provide a specific score based on the "size"
|
|
|
|
# TODO: Have the comet spawn 2 of the next "size" when hit
|
|
|
|
# TODO: Have the comet disapear if shot at is smallest "size"
|
|
|
|
|
2024-05-12 18:54:18 -04:00
|
|
|
|
|
|
|
enum SIZE {SMALL, MEDIUM, LARGE}
|
|
|
|
|
|
|
|
@export var current_size : SIZE = SIZE.LARGE
|
|
|
|
|
|
|
|
var size_data = {
|
|
|
|
SIZE.SMALL : {"Scale": 0.5, "Speed-Multi": 1.5},
|
|
|
|
SIZE.MEDIUM : {"Scale": 1.0, "Speed-Multi": 1.0},
|
|
|
|
SIZE.LARGE : {"Scale": 2.5, "Speed-Multi": 0.5}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var movement_speed : int
|
|
|
|
var movement_speed_min : int = 100
|
|
|
|
var movement_speed_max : int = 500
|
|
|
|
var movement_direciton := Vector2.UP
|
2024-05-12 00:47:14 -04:00
|
|
|
|
|
|
|
var rotation_speed : int
|
|
|
|
var rotaion_direction : int
|
|
|
|
|
2024-05-12 18:54:18 -04:00
|
|
|
|
2024-05-12 00:47:14 -04:00
|
|
|
func _ready() -> void:
|
2024-05-12 18:54:18 -04:00
|
|
|
movement_speed = randi_range(movement_speed_min, movement_speed_max)
|
|
|
|
movement_speed *= size_data[current_size]["Speed-Multi"]
|
|
|
|
|
|
|
|
rotaion_direction = randi_range(0, 1)
|
|
|
|
if rotaion_direction < 1:
|
|
|
|
rotaion_direction = -1
|
|
|
|
rotation_speed = randi_range(50, 150)
|
|
|
|
rotate(randi_range(0, 360))
|
|
|
|
|
|
|
|
self.scale *= size_data[current_size]["Scale"]
|
2024-05-12 00:47:14 -04:00
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
2024-05-12 18:54:18 -04:00
|
|
|
$CollisionPolygon2D.rotate(deg_to_rad(rotaion_direction * rotation_speed * delta))
|
|
|
|
$Sprite2D.rotate(deg_to_rad(rotaion_direction * rotation_speed * delta))
|
2024-05-12 00:47:14 -04:00
|
|
|
|
2024-05-12 18:54:18 -04:00
|
|
|
position += movement_direciton.rotated(rotation) * movement_speed * delta
|
2024-05-12 01:03:18 -04:00
|
|
|
|
2024-05-12 01:17:58 -04:00
|
|
|
# Screen Wrap
|
|
|
|
var viewport_size := get_viewport_rect().size
|
|
|
|
position.x = wrap(position.x, 0, viewport_size.x)
|
|
|
|
position.y = wrap(position.y, 0,viewport_size.y)
|
2024-05-12 01:03:18 -04:00
|
|
|
|
|
|
|
func _on_body_entered(body: Node2D) -> void:
|
|
|
|
print(body)
|
2024-05-12 18:54:18 -04:00
|
|
|
if body.is_in_group("bullet"):
|
|
|
|
explode()
|
2024-05-12 01:03:18 -04:00
|
|
|
if body.is_in_group("ship"):
|
|
|
|
body.crash()
|
2024-05-12 18:54:18 -04:00
|
|
|
|
|
|
|
func explode() -> void:
|
|
|
|
queue_free()
|