mirror of
https://codeberg.org/Melon-Bread/Comets.gd.git
synced 2024-11-24 21:18:21 -05:00
61 lines
1.7 KiB
GDScript
61 lines
1.7 KiB
GDScript
extends Area2D
|
|
|
|
# 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"
|
|
|
|
|
|
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
|
|
|
|
var rotation_speed : int
|
|
var rotaion_direction : int
|
|
|
|
|
|
func _ready() -> void:
|
|
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"]
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
$CollisionPolygon2D.rotate(deg_to_rad(rotaion_direction * rotation_speed * delta))
|
|
$Sprite2D.rotate(deg_to_rad(rotaion_direction * rotation_speed * delta))
|
|
|
|
position += movement_direciton.rotated(rotation) * movement_speed * delta
|
|
|
|
# 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)
|
|
|
|
func _on_body_entered(body: Node2D) -> void:
|
|
print(body)
|
|
if body.is_in_group("bullet"):
|
|
explode()
|
|
if body.is_in_group("ship"):
|
|
body.crash()
|
|
|
|
func explode() -> void:
|
|
queue_free()
|