Initial commit (1/2)
This commit is contained in:
commit
3411c5796d
66 changed files with 2261 additions and 0 deletions
49
modules/projectile.gd
Normal file
49
modules/projectile.gd
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
extends Node2D
|
||||
|
||||
class_name Projectile
|
||||
|
||||
@export var Speed : float = 300
|
||||
@export var RotationSpeed : float = 0
|
||||
@export var Damage : float = 1
|
||||
@export var Collider : Area2D
|
||||
@export var Lifetime : float = 10
|
||||
|
||||
var Fraction = "none"
|
||||
var DestinationAngle : 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 RotationSpeed == 0: DestinationAngle = global_rotation_degrees
|
||||
else: DestinationAngle = rad_to_deg(global_position.angle_to_point(Target.global_position))
|
||||
global_position += Speed * delta * global_transform.x
|
||||
var DestinationDifference : float
|
||||
if DestinationAngle - global_rotation_degrees == clamp(DestinationAngle - global_rotation_degrees, -180, 180):
|
||||
DestinationDifference = DestinationAngle - global_rotation_degrees
|
||||
else:
|
||||
DestinationDifference = global_rotation_degrees - DestinationAngle
|
||||
if DestinationDifference != clamp(DestinationDifference, -1, 1):
|
||||
global_rotation_degrees += sign(DestinationDifference) * RotationSpeed * delta
|
||||
else:
|
||||
global_rotation_degrees = DestinationAngle
|
||||
|
||||
func _on_collision(body):
|
||||
match body.collision_layer:
|
||||
1:
|
||||
if body.Fraction != Fraction:
|
||||
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