From 79d942b8038e7f420e3505fbe517a23e3dad538a Mon Sep 17 00:00:00 2001 From: Ruslan Ignatov Date: Wed, 26 Nov 2025 21:29:57 +0300 Subject: [PATCH] Reworked other weapons --- game/entities/ships/abstract_ship.gd | 10 ++++++-- game/entities/ships/abstract_ship.tscn | 2 ++ .../ships/enemies/heavy/heavy_enemy_ship.tscn | 9 ++++++- .../enemies/medium/medium_enemy_ship.tscn | 7 +++++- .../ships/enemies/small/small_enemy_ship.tscn | 4 ++- game/entities/ships/player/player_ship.tscn | 8 +++++- game/entities/weapons/abstract_weapon.gd | 5 +++- game/entities/weapons/abstract_weapon.tscn | 2 ++ game/entities/weapons/cannon/cannon_weapon.gd | 5 ---- .../weapons/cannon/cannon_weapon.tscn | 2 +- .../weapons/gatling/gatling_weapon.tscn | 3 +++ .../weapons/launcher/launcher_weapon.gd | 6 ++--- .../weapons/launcher/launcher_weapon.tscn | 8 +++--- .../weapons/minelayer/minelayer_weapon.tscn | 1 + game/entities/weapons/plasma/plasma_weapon.gd | 12 --------- .../weapons/plasma/plasma_weapon.tscn | 4 +++ .../weapons/railgun/railgun_weapon.tscn | 14 +++++------ .../weapons/shrapnel/shrapnel_weapon.gd | 25 ------------------- .../weapons/shrapnel/shrapnel_weapon.tscn | 9 ++++++- game/entities/weapons/tesla/tesla_weapon.tscn | 14 +++-------- 20 files changed, 74 insertions(+), 76 deletions(-) diff --git a/game/entities/ships/abstract_ship.gd b/game/entities/ships/abstract_ship.gd index 4d1b0d4..e8a35eb 100644 --- a/game/entities/ships/abstract_ship.gd +++ b/game/entities/ships/abstract_ship.gd @@ -32,17 +32,23 @@ signal destroyed @export_range(0, 1000) var mass : int = 0 @export_range(0, 360) var weapon_rotation : int = 0 -@export var weapon_positions: Array[Vector2] + + +var weapon_positions: Array[Vector2] var _weapons : Array[AbstractWeapon] func _ready() -> void: + for slot in $WeaponSlots.get_children(): + if slot is Node2D: + weapon_positions.append(slot.global_position - global_position) + for pos in weapon_positions: var weapon : AbstractWeapon = WEAPONS.pick_random().instantiate() weapon.position = pos - weapon.rotation = deg_to_rad(weapon_rotation) + weapon.rotation_degrees = weapon_rotation add_child(weapon) _weapons.append(weapon) diff --git a/game/entities/ships/abstract_ship.tscn b/game/entities/ships/abstract_ship.tscn index dd7a69c..7dc2891 100644 --- a/game/entities/ships/abstract_ship.tscn +++ b/game/entities/ships/abstract_ship.tscn @@ -22,4 +22,6 @@ shape = SubResource("CircleShape2D_xxtvk") [node name="HeathBar" parent="." node_paths=PackedStringArray("health") instance=ExtResource("3_l62e5")] health = NodePath("../Health") +[node name="WeaponSlots" type="Node2D" parent="."] + [connection signal="depleted" from="Health" to="." method="_on_health_depleted"] diff --git a/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn b/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn index 2db979d..ade8f60 100644 --- a/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn +++ b/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn @@ -16,7 +16,6 @@ acceleration = 30 deceleration = 18 max_speed = 60 mass = 600 -weapon_positions = Array[Vector2]([Vector2(0, 16), Vector2(0, 0), Vector2(0, -16)]) [node name="Sprite2D" parent="." index="0"] texture = SubResource("PlaceholderTexture2D_cuapu") @@ -34,3 +33,11 @@ offset_bottom = 30.0 [node name="VisibleOnScreenNotifier2D" parent="." index="5"] rect = Rect2(-29, -21, 58, 42) + +[node name="First" type="Node2D" parent="WeaponSlots" index="0"] +position = Vector2(0, -13) + +[node name="Second" type="Node2D" parent="WeaponSlots" index="1"] + +[node name="Third" type="Node2D" parent="WeaponSlots" index="2"] +position = Vector2(0, 13) diff --git a/game/entities/ships/enemies/medium/medium_enemy_ship.tscn b/game/entities/ships/enemies/medium/medium_enemy_ship.tscn index fabdf7e..232826c 100644 --- a/game/entities/ships/enemies/medium/medium_enemy_ship.tscn +++ b/game/entities/ships/enemies/medium/medium_enemy_ship.tscn @@ -16,7 +16,6 @@ acceleration = 92 deceleration = 46 max_speed = 92 mass = 250 -weapon_positions = Array[Vector2]([Vector2(0, 10), Vector2(0, -10)]) [node name="Sprite2D" parent="." index="0"] texture = SubResource("PlaceholderTexture2D_4jmkv") @@ -33,3 +32,9 @@ offset_bottom = 30.0 [node name="VisibleOnScreenNotifier2D" parent="." index="5"] rect = Rect2(-13, -21, 26, 42) + +[node name="First" type="Node2D" parent="WeaponSlots" index="0"] +position = Vector2(0, -10) + +[node name="Second" type="Node2D" parent="WeaponSlots" index="1"] +position = Vector2(0, 10) diff --git a/game/entities/ships/enemies/small/small_enemy_ship.tscn b/game/entities/ships/enemies/small/small_enemy_ship.tscn index c455ce0..e5cda83 100644 --- a/game/entities/ships/enemies/small/small_enemy_ship.tscn +++ b/game/entities/ships/enemies/small/small_enemy_ship.tscn @@ -15,7 +15,6 @@ acceleration = 180 deceleration = 80 max_speed = 120 mass = 100 -weapon_positions = Array[Vector2]([Vector2(0, 0)]) [node name="Sprite2D" parent="." index="0"] texture = SubResource("PlaceholderTexture2D_bw04d") @@ -33,3 +32,6 @@ offset_bottom = 14.0 [node name="VisibleOnScreenNotifier2D" parent="." index="5"] rect = Rect2(-13, -5, 26, 10) + +[node name="First" type="Node2D" parent="WeaponSlots" index="0"] +position = Vector2(6, 0) diff --git a/game/entities/ships/player/player_ship.tscn b/game/entities/ships/player/player_ship.tscn index 8eadcb2..6c4d672 100644 --- a/game/entities/ships/player/player_ship.tscn +++ b/game/entities/ships/player/player_ship.tscn @@ -17,7 +17,7 @@ acceleration = 92 deceleration = 46 max_speed = 92 mass = 250 -weapon_positions = Array[Vector2]([Vector2(-2, 18), Vector2(-2, -18)]) +weapon_rotation = null [node name="Sprite2D" parent="." index="0"] texture = ExtResource("3_uf2n1") @@ -35,5 +35,11 @@ offset_bottom = 22.0 [node name="PlayerController" parent="." index="4" instance=ExtResource("3_4mjo1")] +[node name="First" type="Node2D" parent="WeaponSlots" index="0"] +position = Vector2(-2, 8) + +[node name="Second" type="Node2D" parent="WeaponSlots" index="1"] +position = Vector2(-2, -8) + [connection signal="accelerate" from="PlayerController" to="." method="accelerate"] [connection signal="shoot" from="PlayerController" to="." method="_on_player_controller_shoot"] diff --git a/game/entities/weapons/abstract_weapon.gd b/game/entities/weapons/abstract_weapon.gd index 11cc200..2ee4bac 100644 --- a/game/entities/weapons/abstract_weapon.gd +++ b/game/entities/weapons/abstract_weapon.gd @@ -13,6 +13,9 @@ enum Type { SHORT_RANGE, MEDIUM_RANGE, LONG_RANGE, HOMING, MINES } @export var type := Type.MEDIUM_RANGE +@onready var muzzle : Node2D = $Muzzle + + const PREFIXES := { Belonging.PLAYER: "player", Belonging.ENEMY: "enemy", @@ -46,7 +49,7 @@ func shoot(ship_velocity: Vector2) -> bool: func _get_projectile_position() -> Vector2: - return Vector2.ZERO + return muzzle.global_position - global_position func _create_projectile(ship_velocity: Vector2) -> AbstractProjectile: diff --git a/game/entities/weapons/abstract_weapon.tscn b/game/entities/weapons/abstract_weapon.tscn index 94cb925..49a349f 100644 --- a/game/entities/weapons/abstract_weapon.tscn +++ b/game/entities/weapons/abstract_weapon.tscn @@ -5,3 +5,5 @@ [node name="AbstractWeapon" type="Node2D"] z_index = 2 script = ExtResource("1_x30ps") + +[node name="Muzzle" type="Node2D" parent="."] diff --git a/game/entities/weapons/cannon/cannon_weapon.gd b/game/entities/weapons/cannon/cannon_weapon.gd index 97a4543..c036f75 100644 --- a/game/entities/weapons/cannon/cannon_weapon.gd +++ b/game/entities/weapons/cannon/cannon_weapon.gd @@ -7,7 +7,6 @@ extends AbstractWeapon @onready var right_particles : GPUParticles2D = $ShotParticles/Right @onready var shell_particles : GPUParticles2D = $ShellParticles @onready var cooldown_timer : Timer = $CooldownTimer -@onready var muzzle : Node2D = $Muzzle func set_belonging(belonging: Belonging) -> void: @@ -27,10 +26,6 @@ func shoot(ship_velocity: Vector2) -> bool: return is_shot -func _get_projectile_position() -> Vector2: - return muzzle.position - - func _restart_particles() -> void: front_particles.restart() left_particles.restart() diff --git a/game/entities/weapons/cannon/cannon_weapon.tscn b/game/entities/weapons/cannon/cannon_weapon.tscn index 772b4cd..e5de283 100644 --- a/game/entities/weapons/cannon/cannon_weapon.tscn +++ b/game/entities/weapons/cannon/cannon_weapon.tscn @@ -211,7 +211,7 @@ process_material = SubResource("ParticleProcessMaterial_nrbut") wait_time = 1.2 one_shot = true -[node name="Muzzle" type="Node2D" parent="." index="4"] +[node name="Muzzle" parent="." index="4"] position = Vector2(20, 0) [connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"] diff --git a/game/entities/weapons/gatling/gatling_weapon.tscn b/game/entities/weapons/gatling/gatling_weapon.tscn index 43ff54a..98764c8 100644 --- a/game/entities/weapons/gatling/gatling_weapon.tscn +++ b/game/entities/weapons/gatling/gatling_weapon.tscn @@ -49,3 +49,6 @@ Projectile = ExtResource("2_ylc0n") position = Vector2(6, 0) sprite_frames = SubResource("SpriteFrames_pjn33") animation = &"player_idle" + +[node name="Muzzle" parent="." index="1"] +position = Vector2(14, 0) diff --git a/game/entities/weapons/launcher/launcher_weapon.gd b/game/entities/weapons/launcher/launcher_weapon.gd index e63da64..2b5b08c 100644 --- a/game/entities/weapons/launcher/launcher_weapon.gd +++ b/game/entities/weapons/launcher/launcher_weapon.gd @@ -6,12 +6,12 @@ extends AbstractWeapon @onready var cooldown_timer : Timer = $CooldownTimer @onready var particles : Array[GPUParticles2D] = [ - $RightParticles, $LeftParticles, + $LeftParticles, $RightParticles, ] var _particles_index := 0 @onready var muzzles : Array[Node2D] = [ - $RightMuzzle, $LeftMuzzle, + $Muzzle, $SecondMuzzle, ] var _muzzle_index := 0 @@ -48,7 +48,7 @@ func _restart_particles() -> void: func _get_projectile_position() -> Vector2: - var projectile_position := muzzles[_muzzle_index].position + var projectile_position := muzzles[_muzzle_index].global_position - global_position _muzzle_index += 1 if _muzzle_index >= muzzles.size(): _muzzle_index = 0 diff --git a/game/entities/weapons/launcher/launcher_weapon.tscn b/game/entities/weapons/launcher/launcher_weapon.tscn index 1dac21a..128ac8b 100644 --- a/game/entities/weapons/launcher/launcher_weapon.tscn +++ b/game/entities/weapons/launcher/launcher_weapon.tscn @@ -78,10 +78,10 @@ texture = SubResource("AtlasTexture_ylgjm") wait_time = 0.5 one_shot = true -[node name="LeftMuzzle" type="Node2D" parent="." index="5"] -position = Vector2(12, -3) +[node name="Muzzle" parent="." index="5"] +position = Vector2(11, -3) -[node name="RightMuzzle" type="Node2D" parent="." index="6"] -position = Vector2(12, 3) +[node name="SecondMuzzle" type="Node2D" parent="." index="6"] +position = Vector2(11, 3) [connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"] diff --git a/game/entities/weapons/minelayer/minelayer_weapon.tscn b/game/entities/weapons/minelayer/minelayer_weapon.tscn index c7972f5..6ee4e4d 100644 --- a/game/entities/weapons/minelayer/minelayer_weapon.tscn +++ b/game/entities/weapons/minelayer/minelayer_weapon.tscn @@ -119,6 +119,7 @@ Projectile = ExtResource("2_7y446") type = 4 [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0"] +position = Vector2(-7, 0) sprite_frames = SubResource("SpriteFrames_wwpdh") animation = &"player_shot" diff --git a/game/entities/weapons/plasma/plasma_weapon.gd b/game/entities/weapons/plasma/plasma_weapon.gd index 1cb1df7..8d70d70 100644 --- a/game/entities/weapons/plasma/plasma_weapon.gd +++ b/game/entities/weapons/plasma/plasma_weapon.gd @@ -21,18 +21,6 @@ func shoot(ship_velocity: Vector2) -> bool: return is_shot -func _get_projectile_position() -> Vector2: - var projectile_position : Vector2 - - match _belonging: - Belonging.PLAYER: - projectile_position = Vector2(-5, 2) - Belonging.ENEMY: - projectile_position = Vector2(5, -2) - - return projectile_position - - func _on_animated_sprite_2d_animation_finished() -> void: sprite.play(PREFIXES[_belonging] + RELOAD_POSTFIX) diff --git a/game/entities/weapons/plasma/plasma_weapon.tscn b/game/entities/weapons/plasma/plasma_weapon.tscn index f2ee626..03cd912 100644 --- a/game/entities/weapons/plasma/plasma_weapon.tscn +++ b/game/entities/weapons/plasma/plasma_weapon.tscn @@ -101,6 +101,7 @@ sector_angle = 2 Projectile = ExtResource("2_yluvp") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0"] +position = Vector2(8, 0) sprite_frames = SubResource("SpriteFrames_hyw35") animation = &"player_reloading" @@ -109,5 +110,8 @@ process_callback = 0 wait_time = 0.4 one_shot = true +[node name="Muzzle" parent="." index="2"] +position = Vector2(9, 2) + [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/railgun/railgun_weapon.tscn b/game/entities/weapons/railgun/railgun_weapon.tscn index 7f31763..66667b9 100644 --- a/game/entities/weapons/railgun/railgun_weapon.tscn +++ b/game/entities/weapons/railgun/railgun_weapon.tscn @@ -1,13 +1,10 @@ -[gd_scene load_steps=23 format=3 uid="uid://do6h77gmnreho"] +[gd_scene load_steps=22 format=3 uid="uid://do6h77gmnreho"] [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_0nxvu"] [ext_resource type="Script" uid="uid://drnofu4ium56e" path="res://game/entities/weapons/railgun/railgun_weapon.gd" id="1_5nhwg"] [ext_resource type="PackedScene" uid="uid://bab3bopsw74cb" path="res://game/entities/weapons/railgun/railgun_projectile.tscn" id="2_cbsia"] [ext_resource type="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/weapons.png" id="4_qxcog"] -[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dra6h"] -size = Vector2(10, 7) - [sub_resource type="AtlasTexture" id="AtlasTexture_qxcog"] atlas = ExtResource("4_qxcog") region = Rect2(0, 112, 32, 16) @@ -159,11 +156,12 @@ script = ExtResource("1_5nhwg") Projectile = ExtResource("2_cbsia") type = 2 -[node name="Sprite2D" type="Sprite2D" parent="." index="0"] -texture = SubResource("PlaceholderTexture2D_dra6h") - -[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="1"] +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0"] +position = Vector2(5, 0) sprite_frames = SubResource("SpriteFrames_caa1b") animation = &"enemy_reloading" +[node name="Muzzle" parent="." index="1"] +position = Vector2(11, 0) + [connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"] diff --git a/game/entities/weapons/shrapnel/shrapnel_weapon.gd b/game/entities/weapons/shrapnel/shrapnel_weapon.gd index 611f3fc..f0a513b 100644 --- a/game/entities/weapons/shrapnel/shrapnel_weapon.gd +++ b/game/entities/weapons/shrapnel/shrapnel_weapon.gd @@ -10,8 +10,6 @@ extends AbstractWeapon func set_belonging(belonging: Belonging) -> void: super.set_belonging(belonging) - _init_particles() - sprite.play(PREFIXES[_belonging] + IDLE_POSTFIX) @@ -26,29 +24,6 @@ func shoot(ship_velocity: Vector2) -> bool: return is_shot -func _init_particles() -> void: - const SHOT_OFFSET_X = 11 - const SHELL_OFFSET_X = -8 - const SHELL_OFFSET_Y = 1 - - - match _belonging: - Belonging.PLAYER: - shot_particles.process_material.emission_shape_offset.x = SHOT_OFFSET_X - shot_particles.process_material.direction = Vector3.RIGHT - - shell_particles.process_material.emission_shape_offset.x = SHELL_OFFSET_X - shell_particles.process_material.emission_shape_offset.y = SHELL_OFFSET_Y - shell_particles.process_material.direction = Vector3.UP - Belonging.ENEMY: - shot_particles.process_material.emission_shape_offset.x = -SHOT_OFFSET_X - shot_particles.process_material.direction = Vector3.LEFT - - shell_particles.process_material.emission_shape_offset.x = -SHELL_OFFSET_X - shell_particles.process_material.emission_shape_offset.y = -SHELL_OFFSET_Y - shell_particles.process_material.direction = Vector3.DOWN - - func _restart_particles() -> void: shot_particles.restart() shell_particles.restart() diff --git a/game/entities/weapons/shrapnel/shrapnel_weapon.tscn b/game/entities/weapons/shrapnel/shrapnel_weapon.tscn index 166628e..2bf1c31 100644 --- a/game/entities/weapons/shrapnel/shrapnel_weapon.tscn +++ b/game/entities/weapons/shrapnel/shrapnel_weapon.tscn @@ -104,9 +104,10 @@ animations = [{ resource_local_to_scene = true particle_flag_disable_z = true inherit_velocity_ratio = 1.0 +direction = Vector3(0, 1, 0) spread = 15.0 initial_velocity_min = 15.0 -initial_velocity_max = 50.0 +initial_velocity_max = 25.0 gravity = Vector3(0, 0, 0) [node name="ShrapnelWeapon" instance=ExtResource("1_xk300")] @@ -117,6 +118,7 @@ Projectile = ExtResource("2_xvd4y") type = 0 [node name="ShotParticles" type="GPUParticles2D" parent="." index="0"] +position = Vector2(17, 0) emitting = false amount = 32 texture = ExtResource("4_0tw2i") @@ -125,6 +127,7 @@ one_shot = true process_material = SubResource("ParticleProcessMaterial_a22j7") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="1"] +position = Vector2(7, 0) sprite_frames = SubResource("SpriteFrames_he4pe") animation = &"player_shot" @@ -134,6 +137,7 @@ one_shot = true [node name="ShellParticles" type="GPUParticles2D" parent="." index="3"] z_index = 1 +position = Vector2(-1, 1) emitting = false amount = 1 texture = ExtResource("6_gdolk") @@ -141,5 +145,8 @@ lifetime = 2.0 one_shot = true process_material = SubResource("ParticleProcessMaterial_t57yr") +[node name="Muzzle" parent="." index="4"] +position = Vector2(14, 0) + [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/tesla/tesla_weapon.tscn b/game/entities/weapons/tesla/tesla_weapon.tscn index ec5f90b..4a3065e 100644 --- a/game/entities/weapons/tesla/tesla_weapon.tscn +++ b/game/entities/weapons/tesla/tesla_weapon.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=25 format=3 uid="uid://dyebeblayioji"] +[gd_scene load_steps=24 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"] @@ -6,9 +6,6 @@ [ext_resource type="Texture2D" uid="uid://c6aixtu6lbfud" path="res://particle_textures/energy_small.tres" id="5_dhfvk"] [ext_resource type="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/weapons.png" id="7_ub67s"] -[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dra6h"] -size = Vector2(10, 7) - [sub_resource type="AtlasTexture" id="AtlasTexture_ucdpq"] atlas = ExtResource("7_ub67s") region = Rect2(0, 16, 32, 16) @@ -151,21 +148,18 @@ sector_angle = 10 Projectile = ExtResource("2_1rrdy") type = 3 -[node name="Sprite2D" type="Sprite2D" parent="." index="0"] -texture = SubResource("PlaceholderTexture2D_dra6h") - -[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="1"] +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0"] sprite_frames = SubResource("SpriteFrames_ckvhw") animation = &"player_idle" -[node name="GPUParticles2D" type="GPUParticles2D" parent="." index="2"] +[node name="GPUParticles2D" type="GPUParticles2D" parent="." index="1"] amount = 16 texture = ExtResource("5_dhfvk") lifetime = 0.1 fixed_fps = 10 process_material = SubResource("ParticleProcessMaterial_ifsj2") -[node name="CooldownTimer" type="Timer" parent="." index="3"] +[node name="CooldownTimer" type="Timer" parent="." index="2"] wait_time = 1.3 one_shot = true