Initial commit (1/2)

This commit is contained in:
Алкесей Мирнеков 2023-11-05 16:23:18 +03:00 committed by GitHub
commit 3411c5796d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 2261 additions and 0 deletions

49
modules/projectile.gd Normal file
View 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