Added GatlingReloader
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
[ext_resource type="Script" uid="uid://c1bsvmj7xhnxe" path="res://game/entities/weapons/gatling_gun/gatling_gun.gd" id="1_irb3o"]
|
||||
[ext_resource type="PackedScene" uid="uid://cnoiv8hdgossf" path="res://game/entities/weapons/gatling_gun/gatling_projectile.tscn" id="2_kifyy"]
|
||||
[ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/entities/weapons/reloaders/abstract_reloader.gd" id="3_lpe3m"]
|
||||
[ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/entities/weapons/reloaders/firerate_reloader.gd" id="4_uk8wm"]
|
||||
[ext_resource type="Script" uid="uid://oslebeau3f4b" path="res://game/entities/weapons/reloaders/gatling_reloader.gd" id="4_irb3o"]
|
||||
[ext_resource type="Script" uid="uid://d2gfhnlbqxsoq" path="res://game/entities/weapons/reloaders/magazine_reloader.gd" id="5_376q2"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_83oj5"]
|
||||
script = ExtResource("4_uk8wm")
|
||||
[sub_resource type="Resource" id="Resource_kifyy"]
|
||||
script = ExtResource("4_irb3o")
|
||||
firerate = 600
|
||||
metadata/_custom_type_script = "uid://b255rb32vc6co"
|
||||
spin_out_time = 3
|
||||
metadata/_custom_type_script = "uid://oslebeau3f4b"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_6px3v"]
|
||||
script = ExtResource("5_376q2")
|
||||
@@ -20,7 +21,7 @@ metadata/_custom_type_script = "uid://d2gfhnlbqxsoq"
|
||||
[node name="GatlingGun" type="Node2D"]
|
||||
script = ExtResource("1_irb3o")
|
||||
Projectile = ExtResource("2_kifyy")
|
||||
reloaders = Array[ExtResource("3_lpe3m")]([SubResource("Resource_83oj5"), SubResource("Resource_6px3v")])
|
||||
reloaders = Array[ExtResource("3_lpe3m")]([SubResource("Resource_kifyy"), SubResource("Resource_6px3v")])
|
||||
metadata/_custom_type_script = "uid://dpqxs8hlql2o0"
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
extends AbstractReloader
|
||||
class_name GatlingReloader
|
||||
|
||||
|
||||
@export var firerate : int:
|
||||
set(value):
|
||||
firerate = value
|
||||
_calculate_delay()
|
||||
|
||||
@export var spin_out_time : int:
|
||||
set(value):
|
||||
spin_out_time = value
|
||||
_calculate_delay()
|
||||
|
||||
|
||||
const INITIAL_DELAY = 1.0
|
||||
|
||||
|
||||
var _target_delay : float
|
||||
var _current_delay : float
|
||||
var _delay_decrement : float
|
||||
var _cooldown : float
|
||||
var _last_delta : float = 1
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_calculate_delay()
|
||||
|
||||
|
||||
func process(delta: float) -> void:
|
||||
if _cooldown > 0:
|
||||
_cooldown -= delta
|
||||
|
||||
if _current_delay < INITIAL_DELAY:
|
||||
_decrease_delay(_delay_decrement * -delta)
|
||||
|
||||
_last_delta = delta
|
||||
|
||||
|
||||
func can_shoot() -> bool:
|
||||
_decrease_delay(_delay_decrement * 2 * _last_delta)
|
||||
return _cooldown <= 0
|
||||
|
||||
|
||||
func shoot() -> void:
|
||||
_cooldown = _current_delay
|
||||
|
||||
|
||||
func reload() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func get_process_percent() -> int:
|
||||
return 100 - int(_cooldown * 100 / _current_delay)
|
||||
|
||||
|
||||
func _calculate_delay() -> void:
|
||||
_target_delay = 60.0 / firerate
|
||||
_delay_decrement = (INITIAL_DELAY - _target_delay)/spin_out_time
|
||||
|
||||
|
||||
func _decrease_delay(delay_decrement: float) -> void:
|
||||
_current_delay = _current_delay - delay_decrement
|
||||
_current_delay = clampf(_current_delay, _target_delay, INITIAL_DELAY)
|
||||
@@ -0,0 +1 @@
|
||||
uid://oslebeau3f4b
|
||||
Reference in New Issue
Block a user