Trying to rework cannon, gatling, launcher

This commit is contained in:
2025-11-26 18:04:31 +03:00
parent 505f7beae8
commit c3c199a9f9
13 changed files with 143 additions and 154 deletions
@@ -5,21 +5,15 @@ extends AbstractWeapon
@onready var enemy_sprite : Sprite2D = $EnemySprite
@onready var cooldown_timer : Timer = $CooldownTimer
@onready var player_particles : Array[GPUParticles2D] = [
$ShotProjectiles/PlayerRightParticles, $ShotProjectiles/PlayerLeftParticles,
]
@onready var enemy_particles : Array[GPUParticles2D] = [
$ShotProjectiles/EnemyRightParticles, $ShotProjectiles/EnemyLeftParticles,
@onready var particles : Array[GPUParticles2D] = [
$RightParticles, $LeftParticles,
]
var _particles_index := 0
const PLAYER_PROJECTILE_POSITIONS : Array[Vector2] = [
Vector2(4, 3), Vector2(4, -3),
@onready var muzzles : Array[Node2D] = [
$RightMuzzle, $LeftMuzzle,
]
const ENEMY_PROJECTILE_POSITIONS : Array[Vector2] = [
Vector2(-4, 3), Vector2(-4, -3),
]
var _projectile_position_index := 0
var _muzzle_index := 0
func set_belonging(belonging: Belonging) -> void:
@@ -47,43 +41,27 @@ func shoot(ship_velocity: Vector2) -> bool:
func _restart_particles() -> void:
var particle : GPUParticles2D = null
match _belonging:
Belonging.PLAYER:
particle = _get_particle_from_array(player_particles)
Belonging.ENEMY:
particle = _get_particle_from_array(enemy_particles)
particle = _get_particle()
if particle != null:
particle.restart()
func _get_projectile_position() -> Vector2:
var projectile_position : Vector2
match _belonging:
Belonging.PLAYER:
projectile_position = _get_projectile_position_from_array(PLAYER_PROJECTILE_POSITIONS)
Belonging.ENEMY:
projectile_position = _get_projectile_position_from_array(ENEMY_PROJECTILE_POSITIONS)
var projectile_position := muzzles[_muzzle_index].position
_muzzle_index += 1
if _muzzle_index >= muzzles.size():
_muzzle_index = 0
return projectile_position
func _get_particle_from_array(array: Array[GPUParticles2D]) -> GPUParticles2D:
var particle := array[_particles_index]
func _get_particle() -> GPUParticles2D:
var particle := particles[_particles_index]
_particles_index += 1
if _particles_index >= array.size():
if _particles_index >= particles.size():
_particles_index = 0
return particle
func _get_projectile_position_from_array(array: Array[Vector2]) -> Vector2:
var projectile_position := array[_projectile_position_index]
_projectile_position_index += 1
if _projectile_position_index >= array.size():
_projectile_position_index = 0
return projectile_position
func _on_cooldown_timer_timeout() -> void:
_can_shoot = true
@@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=3 uid="uid://c3l866fdqt7pf"]
[gd_scene load_steps=10 format=3 uid="uid://c3l866fdqt7pf"]
[ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_sk5u1"]
[ext_resource type="Script" uid="uid://lauvvj5xhbud" path="res://game/entities/weapons/launcher/launcher_weapon.gd" id="2_mxjpe"]
@@ -9,7 +9,6 @@
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_u8eh0"]
lifetime_randomness = 0.5
particle_flag_disable_z = true
emission_shape_offset = Vector3(-8, -3.5, 0)
emission_shape = 1
emission_sphere_radius = 1.0
angle_min = -179.99998
@@ -24,7 +23,6 @@ gravity = Vector3(0, 0, 0)
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_0brql"]
lifetime_randomness = 0.5
particle_flag_disable_z = true
emission_shape_offset = Vector3(-8, 3.5, 0)
emission_shape = 1
emission_sphere_radius = 1.0
angle_min = -179.99998
@@ -36,34 +34,6 @@ initial_velocity_min = 30.0
initial_velocity_max = 50.0
gravity = Vector3(0, 0, 0)
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_3cw5x"]
lifetime_randomness = 0.5
particle_flag_disable_z = true
emission_shape_offset = Vector3(8, -3.5, 0)
emission_shape = 1
emission_sphere_radius = 1.0
angle_min = -179.99998
angle_max = 180.00002
inherit_velocity_ratio = 0.5
spread = 15.0
initial_velocity_min = 30.0
initial_velocity_max = 50.0
gravity = Vector3(0, 0, 0)
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_ylgjm"]
lifetime_randomness = 0.5
particle_flag_disable_z = true
emission_shape_offset = Vector3(8, 3.5, 0)
emission_shape = 1
emission_sphere_radius = 1.0
angle_min = -179.99998
angle_max = 180.00002
inherit_velocity_ratio = 0.5
spread = 15.0
initial_velocity_min = 30.0
initial_velocity_max = 50.0
gravity = Vector3(0, 0, 0)
[sub_resource type="AtlasTexture" id="AtlasTexture_u8eh0"]
atlas = ExtResource("6_3cw5x")
region = Rect2(224, 128, 32, 16)
@@ -78,9 +48,8 @@ sector_angle = 5
Projectile = ExtResource("3_fsoo2")
type = 3
[node name="ShotProjectiles" type="Node2D" parent="." index="0"]
[node name="PlayerLeftParticles" type="GPUParticles2D" parent="ShotProjectiles" index="0"]
[node name="LeftParticles" type="GPUParticles2D" parent="." index="0"]
position = Vector2(-4, -3)
emitting = false
amount = 16
texture = ExtResource("4_0brql")
@@ -88,7 +57,8 @@ lifetime = 0.3
one_shot = true
process_material = SubResource("ParticleProcessMaterial_u8eh0")
[node name="PlayerRightParticles" type="GPUParticles2D" parent="ShotProjectiles" index="1"]
[node name="RightParticles" type="GPUParticles2D" parent="." index="1"]
position = Vector2(-4, 3)
emitting = false
amount = 16
texture = ExtResource("4_0brql")
@@ -96,30 +66,22 @@ lifetime = 0.3
one_shot = true
process_material = SubResource("ParticleProcessMaterial_0brql")
[node name="EnemyLeftParticles" type="GPUParticles2D" parent="ShotProjectiles" index="2"]
emitting = false
amount = 16
texture = ExtResource("4_0brql")
lifetime = 0.3
one_shot = true
process_material = SubResource("ParticleProcessMaterial_3cw5x")
[node name="EnemyRightParticles" type="GPUParticles2D" parent="ShotProjectiles" index="3"]
emitting = false
amount = 16
texture = ExtResource("4_0brql")
lifetime = 0.3
one_shot = true
process_material = SubResource("ParticleProcessMaterial_ylgjm")
[node name="PlayerSprite" type="Sprite2D" parent="." index="1"]
[node name="PlayerSprite" type="Sprite2D" parent="." index="2"]
position = Vector2(4, 0)
texture = SubResource("AtlasTexture_u8eh0")
[node name="EnemySprite" type="Sprite2D" parent="." index="2"]
[node name="EnemySprite" type="Sprite2D" parent="." index="3"]
position = Vector2(4, 0)
texture = SubResource("AtlasTexture_ylgjm")
[node name="CooldownTimer" type="Timer" parent="." index="3"]
[node name="CooldownTimer" type="Timer" parent="." index="4"]
wait_time = 0.5
one_shot = true
[node name="LeftMuzzle" type="Node2D" parent="." index="5"]
position = Vector2(12, -3)
[node name="RightMuzzle" type="Node2D" parent="." index="6"]
position = Vector2(12, 3)
[connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"]