A little cleanup
This commit is contained in:
parent
1cb2c7ebdb
commit
bedeee894a
15 changed files with 21 additions and 124 deletions
|
|
@ -1,48 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
class_name Projectile
|
||||
|
||||
@export var speed : float = 300
|
||||
@export var rotation_speed : float = 0
|
||||
@export var damage : float = 1
|
||||
@export var collider : Area2D
|
||||
@export var lifetime : float = 10
|
||||
|
||||
var faction: Game.Faction = Game.Faction.None
|
||||
var destination_angle : float
|
||||
var target : Node2D = self
|
||||
|
||||
func _ready():
|
||||
get_tree().create_timer(lifetime).timeout.connect(queue_free)
|
||||
collider.body_entered.connect(_on_collision)
|
||||
areyouready()
|
||||
|
||||
func _physics_process(delta):
|
||||
if rotation_speed == 0: destination_angle = global_rotation_degrees
|
||||
else: destination_angle = rad_to_deg(global_position.angle_to_point(target.global_position))
|
||||
global_position += speed * delta * global_transform.x
|
||||
var destination_difference : float
|
||||
if abs(destination_angle - global_rotation_degrees) <= 180:
|
||||
destination_difference = destination_angle - global_rotation_degrees
|
||||
else:
|
||||
destination_difference = global_rotation_degrees - destination_angle
|
||||
if destination_difference != clamp(destination_difference, -1, 1):
|
||||
global_rotation_degrees += sign(destination_difference) * rotation_speed * delta
|
||||
else:
|
||||
global_rotation_degrees = destination_angle
|
||||
|
||||
func _on_collision(body):
|
||||
match body.collision_layer:
|
||||
1:
|
||||
if body.ship.faction != faction:
|
||||
if target != self:
|
||||
target.queue_free()
|
||||
body.ship.shield.deal_damage(damage)
|
||||
queue_free()
|
||||
2:
|
||||
if target != self:
|
||||
target.queue_free()
|
||||
queue_free()
|
||||
|
||||
func areyouready():
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue