diff --git a/game/entities/weapons/abstract_weapon.gd b/game/entities/weapons/abstract_weapon.gd index 9011ee0..87337c9 100644 --- a/game/entities/weapons/abstract_weapon.gd +++ b/game/entities/weapons/abstract_weapon.gd @@ -24,6 +24,7 @@ const IDLE_POSTFIX = "idle" var _belonging: Belonging var _current_projectile_position := 0 +var _can_shoot := true func _physics_process(delta: float) -> void: @@ -36,7 +37,7 @@ func set_belonging(belonging: Belonging) -> void: func shoot(ship_velocity: Vector2) -> bool: - if not _can_shoot(): return false + if not _can_shoot or not _reloaders_can_shoot(): return false for i in range(bullet_per_shot): var projectile := _create_projectile(ship_velocity) @@ -81,7 +82,7 @@ func reload() -> void: reloader.reload() -func _can_shoot() -> bool: +func _reloaders_can_shoot() -> bool: for reloader in reloaders: if not reloader.can_shoot(): return false diff --git a/game/entities/weapons/cannon/cannon_weapon.gd b/game/entities/weapons/cannon/cannon_weapon.gd index dfc9c6e..e7b12ce 100644 --- a/game/entities/weapons/cannon/cannon_weapon.gd +++ b/game/entities/weapons/cannon/cannon_weapon.gd @@ -6,6 +6,7 @@ extends AbstractWeapon @onready var left_particles : GPUParticles2D = $ShotParticles/Left @onready var right_particles : GPUParticles2D = $ShotParticles/Right @onready var shell_particles : GPUParticles2D = $ShellParticles +@onready var cooldown_timer : Timer = $CooldownTimer func set_belonging(belonging: Belonging) -> void: @@ -61,6 +62,8 @@ func shoot(ship_velocity: Vector2) -> bool: var is_shot := super.shoot(ship_velocity) if is_shot: sprite.play(PREFIXES[_belonging] + SHOT_POSTFIX) + _can_shoot = false + cooldown_timer.start() _restart_particles() return is_shot @@ -75,3 +78,7 @@ func _restart_particles() -> void: func _on_animated_sprite_2d_animation_finished() -> void: sprite.play(PREFIXES[_belonging] + IDLE_POSTFIX) + + +func _on_cooldown_timer_timeout() -> void: + _can_shoot = true diff --git a/game/entities/weapons/cannon/cannon_weapon.tscn b/game/entities/weapons/cannon/cannon_weapon.tscn index e57bee2..88b5da4 100644 --- a/game/entities/weapons/cannon/cannon_weapon.tscn +++ b/game/entities/weapons/cannon/cannon_weapon.tscn @@ -1,18 +1,11 @@ -[gd_scene load_steps=27 format=3 uid="uid://bccaoirwdkp7n"] +[gd_scene load_steps=24 format=3 uid="uid://bccaoirwdkp7n"] [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_xnbws"] [ext_resource type="PackedScene" uid="uid://cgi7wd84kjnyw" path="res://game/entities/weapons/cannon/cannon_projectile.tscn" id="2_2bjeu"] [ext_resource type="Script" uid="uid://db24dm76b1am7" path="res://game/entities/weapons/cannon/cannon_weapon.gd" id="2_ew5um"] -[ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_7e2aj"] -[ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_bv8g1"] [ext_resource type="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/weapons.png" id="6_jfd4t"] [ext_resource type="Texture2D" uid="uid://3w0itm7k5fxq" path="res://images/particles.png" id="7_i0ica"] -[sub_resource type="Resource" id="Resource_7e2aj"] -script = ExtResource("4_bv8g1") -firerate = 50 -metadata/_custom_type_script = "uid://b255rb32vc6co" - [sub_resource type="Gradient" id="Gradient_jfd4t"] colors = PackedColorArray(1, 0.8039216, 0.45882353, 1, 0.9372549, 0.49019608, 0.34117648, 1) @@ -161,7 +154,6 @@ gravity = Vector3(0, 0, 0) script = ExtResource("2_ew5um") sector_angle = 1 Projectile = ExtResource("2_2bjeu") -reloaders = Array[ExtResource("3_7e2aj")]([SubResource("Resource_7e2aj")]) [node name="ShotParticles" type="Node2D" parent="." index="0"] @@ -204,4 +196,9 @@ one_shot = true fixed_fps = 10 process_material = SubResource("ParticleProcessMaterial_nrbut") +[node name="CooldownTimer" type="Timer" parent="." index="3"] +wait_time = 1.2 +one_shot = true + [connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"] +[connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"] diff --git a/game/entities/weapons/minelayer/minelayer_weapon.gd b/game/entities/weapons/minelayer/minelayer_weapon.gd index 79444c7..913269f 100644 --- a/game/entities/weapons/minelayer/minelayer_weapon.gd +++ b/game/entities/weapons/minelayer/minelayer_weapon.gd @@ -13,6 +13,7 @@ func set_belonging(belonging: Belonging) -> void: func shoot(ship_velocity: Vector2) -> bool: var is_shot := super.shoot(ship_velocity) if is_shot: + _can_shoot = false sprite.play(PREFIXES[_belonging] + SHOT_POSTFIX) return is_shot @@ -20,3 +21,4 @@ func shoot(ship_velocity: Vector2) -> bool: func _on_animated_sprite_2d_animation_finished() -> void: sprite.play(PREFIXES[_belonging] + IDLE_POSTFIX) + _can_shoot = true diff --git a/game/entities/weapons/minelayer/minelayer_weapon.tscn b/game/entities/weapons/minelayer/minelayer_weapon.tscn index 613facc..52f06cd 100644 --- a/game/entities/weapons/minelayer/minelayer_weapon.tscn +++ b/game/entities/weapons/minelayer/minelayer_weapon.tscn @@ -1,17 +1,10 @@ -[gd_scene load_steps=21 format=3 uid="uid://j3yht6q4ru4e"] +[gd_scene load_steps=18 format=3 uid="uid://j3yht6q4ru4e"] [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_12l3k"] [ext_resource type="PackedScene" uid="uid://4mkklqt1g14f" path="res://game/entities/weapons/minelayer/minelayer_projectile.tscn" id="2_7y446"] [ext_resource type="Script" uid="uid://c3ckkpjaef5jn" path="res://game/entities/weapons/minelayer/minelayer_weapon.gd" id="2_mmhtn"] -[ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_uotj8"] -[ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_fbmxv"] [ext_resource type="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/weapons.png" id="6_ais8e"] -[sub_resource type="Resource" id="Resource_uotj8"] -script = ExtResource("4_fbmxv") -firerate = 40 -metadata/_custom_type_script = "uid://b255rb32vc6co" - [sub_resource type="AtlasTexture" id="AtlasTexture_ais8e"] atlas = ExtResource("6_ais8e") region = Rect2(0, 128, 32, 16) @@ -123,7 +116,6 @@ animations = [{ script = ExtResource("2_mmhtn") sector_angle = 10 Projectile = ExtResource("2_7y446") -reloaders = Array[ExtResource("3_uotj8")]([SubResource("Resource_uotj8")]) [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0"] sprite_frames = SubResource("SpriteFrames_wwpdh") diff --git a/game/entities/weapons/tesla/tesla_weapon.gd b/game/entities/weapons/tesla/tesla_weapon.gd index c14e647..d6c4d03 100644 --- a/game/entities/weapons/tesla/tesla_weapon.gd +++ b/game/entities/weapons/tesla/tesla_weapon.gd @@ -2,9 +2,23 @@ extends AbstractWeapon @onready var sprite : AnimatedSprite2D = $AnimatedSprite2D +@onready var cooldown_timer : Timer = $CooldownTimer func set_belonging(belonging: Belonging) -> void: super.set_belonging(belonging) sprite.play(PREFIXES[_belonging] + IDLE_POSTFIX) + + +func shoot(ship_velocity: Vector2) -> bool: + var is_shot := super.shoot(ship_velocity) + if is_shot: + _can_shoot = false + cooldown_timer.start() + + return is_shot + + +func _on_cooldown_timer_timeout() -> void: + _can_shoot = true diff --git a/game/entities/weapons/tesla/tesla_weapon.tscn b/game/entities/weapons/tesla/tesla_weapon.tscn index 8e997b4..6e39197 100644 --- a/game/entities/weapons/tesla/tesla_weapon.tscn +++ b/game/entities/weapons/tesla/tesla_weapon.tscn @@ -1,17 +1,10 @@ -[gd_scene load_steps=29 format=3 uid="uid://dyebeblayioji"] +[gd_scene load_steps=26 format=3 uid="uid://dyebeblayioji"] [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_rpud7"] [ext_resource type="PackedScene" uid="uid://bi64687wtxi4d" path="res://game/entities/weapons/tesla/tesla_projectile.tscn" id="2_1rrdy"] [ext_resource type="Script" uid="uid://ctv408wdwvttc" path="res://game/entities/weapons/tesla/tesla_weapon.gd" id="2_08si3"] -[ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_08si3"] -[ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_rqarv"] [ext_resource type="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/weapons.png" id="7_ub67s"] -[sub_resource type="Resource" id="Resource_1rrdy"] -script = ExtResource("4_rqarv") -firerate = 45 -metadata/_custom_type_script = "uid://b255rb32vc6co" - [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dra6h"] size = Vector2(10, 7) @@ -162,7 +155,6 @@ gravity = Vector3(0, 0, 0) script = ExtResource("2_08si3") sector_angle = 10 Projectile = ExtResource("2_1rrdy") -reloaders = Array[ExtResource("3_08si3")]([SubResource("Resource_1rrdy")]) [node name="Sprite2D" type="Sprite2D" parent="." index="0"] texture = SubResource("PlaceholderTexture2D_dra6h") @@ -174,6 +166,12 @@ animation = &"player_idle" [node name="GPUParticles2D" type="GPUParticles2D" parent="." index="2"] amount = 16 texture = SubResource("GradientTexture1D_ucdpq") -lifetime = 0.09999999999999999 +lifetime = 0.1 fixed_fps = 10 process_material = SubResource("ParticleProcessMaterial_ifsj2") + +[node name="CooldownTimer" type="Timer" parent="." index="3"] +wait_time = 1.3 +one_shot = true + +[connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"]