mirror of
https://codeberg.org/Melon-Bread/Comets.gd.git
synced 2024-11-28 15:08:20 -05:00
61 lines
1.8 KiB
GDScript
61 lines
1.8 KiB
GDScript
extends Area2D
|
|
|
|
# TODO: Have like 1 in 4 different sprites (and maybe shapes) the comet can be
|
|
|
|
signal exploded (new_size: SIZE, current_position: Vector2)
|
|
|
|
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 = 50
|
|
var movement_speed_max : int = 250
|
|
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:
|
|
if body.is_in_group("ship"):
|
|
body.crash()
|
|
|
|
func _on_area_entered(area: Area2D) -> void:
|
|
if area.is_in_group("bullet"):
|
|
area.queue_free()
|
|
# TODO: Have some kind of (maybe) particle explosion happen when hit with bullet
|
|
$AnimationPlayer.play("explode")
|
|
|
|
func explode() -> void:
|
|
exploded.emit(current_size - 1, global_position)
|
|
queue_free()
|