Done refactoring
This commit is contained in:
parent
3a136ff215
commit
2176e9d798
88 changed files with 821 additions and 880 deletions
48
scripts/objects/projectile.gd
Normal file
48
scripts/objects/projectile.gd
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
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 = "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.faction != faction:
|
||||
if target != self:
|
||||
target.queue_free()
|
||||
body.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