AbstractProjectile reworked to Projectile
This commit is contained in:
@@ -7,7 +7,6 @@
|
|||||||
script = ExtResource("1_3a8sv")
|
script = ExtResource("1_3a8sv")
|
||||||
|
|
||||||
[node name="Ship" parent="." instance=ExtResource("2_ktqbp")]
|
[node name="Ship" parent="." instance=ExtResource("2_ktqbp")]
|
||||||
motion_mode = 1
|
|
||||||
size = Vector2(48, 32)
|
size = Vector2(48, 32)
|
||||||
acceleration = 46
|
acceleration = 46
|
||||||
deceleration = 23
|
deceleration = 23
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
@abstract
|
|
||||||
class_name AbstractProjectile
|
|
||||||
extends Node
|
|
||||||
|
|
||||||
|
|
||||||
@export var bullet_velocity : int
|
|
||||||
@export var bullet_acceleration : int
|
|
||||||
@export var distance : int
|
|
||||||
@export var bullet_max_livetime : int
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://cnoiv8hdgossf"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://ctmjb3nkxrepu" path="res://game/entities/weapons/projectiles/projectile.gd" id="1_2ltai"]
|
||||||
|
|
||||||
|
[node name="GatlingProjectile" type="CharacterBody2D"]
|
||||||
|
script = ExtResource("1_2ltai")
|
||||||
|
damage = 6
|
||||||
|
speed = 600
|
||||||
|
direction = Vector2(1, 0)
|
||||||
|
metadata/_custom_type_script = "uid://ctmjb3nkxrepu"
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
class_name ProjectileMover
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
|
signal destroyed
|
||||||
|
|
||||||
|
|
||||||
|
@export var damage : int
|
||||||
|
@export var speed : int
|
||||||
|
@export var direction : Vector2
|
||||||
|
@export var acceleration : int
|
||||||
|
@export var max_distance : int
|
||||||
|
@export var max_livetime : int
|
||||||
|
|
||||||
|
|
||||||
|
var velocity : Vector2:
|
||||||
|
set(value):
|
||||||
|
pass
|
||||||
|
get:
|
||||||
|
return _velocity
|
||||||
|
|
||||||
|
var _velocity : Vector2
|
||||||
|
var _traveled_distance: float
|
||||||
|
var _livetime: float
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
_velocity = direction.normalized() * speed
|
||||||
|
|
||||||
|
|
||||||
|
func process_acceleration(delta: float) -> void:
|
||||||
|
var current_acceleration := acceleration * delta
|
||||||
|
if current_acceleration > 0:
|
||||||
|
_velocity += _velocity.normalized() * current_acceleration
|
||||||
|
elif current_acceleration < 0:
|
||||||
|
if _velocity.length() > current_acceleration:
|
||||||
|
_velocity += _velocity.normalized() * current_acceleration
|
||||||
|
else:
|
||||||
|
_velocity = Vector2.ZERO
|
||||||
|
|
||||||
|
|
||||||
|
func process_distance(delta: float) -> void:
|
||||||
|
_traveled_distance += _velocity.length() * delta
|
||||||
|
if max_distance > 0 and _traveled_distance > max_distance:
|
||||||
|
destroyed.emit()
|
||||||
|
|
||||||
|
|
||||||
|
func process_livetime(delta: float) -> void:
|
||||||
|
_livetime += delta
|
||||||
|
if _livetime > max_livetime:
|
||||||
|
destroyed.emit()
|
||||||
Reference in New Issue
Block a user