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
+2
View File
@@ -31,6 +31,7 @@ signal destroyed
@export_range(0, 250) var max_speed : int = 0
@export_range(0, 1000) var mass : int = 0
@export_range(0, 360) var weapon_rotation : int = 0
@export var weapon_positions: Array[Vector2]
@@ -41,6 +42,7 @@ func _ready() -> void:
for pos in weapon_positions:
var weapon : AbstractWeapon = WEAPONS.pick_random().instantiate()
weapon.position = pos
weapon.rotation = deg_to_rad(weapon_rotation)
add_child(weapon)
_weapons.append(weapon)
@@ -8,6 +8,7 @@
collision_layer = 4
collision_mask = 2
script = ExtResource("2_fwvrd")
weapon_rotation = 180
[node name="EnemyController" parent="." index="4" node_paths=PackedStringArray("ship") instance=ExtResource("3_l8c0n")]
ship = NodePath("..")
+3 -5
View File
@@ -3,9 +3,7 @@
[ext_resource type="PackedScene" uid="uid://jvyagshykmgb" path="res://game/entities/ships/abstract_ship.tscn" id="1_6otxb"]
[ext_resource type="Script" uid="uid://ruxw1n03iq4i" path="res://game/entities/ships/player/player_ship.gd" id="2_625ti"]
[ext_resource type="PackedScene" uid="uid://dh1oj1w5wx4je" path="res://game/controllers/player_controller.tscn" id="3_4mjo1"]
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dj8f1"]
size = Vector2(48, 32)
[ext_resource type="Texture2D" uid="uid://y2yfli24n51v" path="res://images/ships/player.png" id="3_uf2n1"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_dj8f1"]
radius = 15.0
@@ -19,10 +17,10 @@ acceleration = 92
deceleration = 46
max_speed = 92
mass = 250
weapon_positions = Array[Vector2]([Vector2(0, 8), Vector2(0, -8)])
weapon_positions = Array[Vector2]([Vector2(-2, 18), Vector2(-2, -18)])
[node name="Sprite2D" parent="." index="0"]
texture = SubResource("PlaceholderTexture2D_dj8f1")
texture = ExtResource("3_uf2n1")
[node name="CollisionShape2D" parent="." index="1"]
rotation = 1.5707964
+5 -43
View File
@@ -7,57 +7,15 @@ 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:
super.set_belonging(belonging)
_init_particles()
sprite.play(PREFIXES[_belonging] + IDLE_POSTFIX)
func _init_particles() -> void:
const FRONT_OFFSET_X = 12
const SIDE_OFFSET_X = 6
const SIDE_OFFSET_Y = 5
const SHELL_OFFSET_X = -10
const SHELL_OFFSET_Y = 2
match _belonging:
Belonging.PLAYER:
front_particles.process_material.emission_shape_offset.x = FRONT_OFFSET_X
front_particles.process_material.direction = Vector3.RIGHT
left_particles.process_material.emission_shape_offset.x = SIDE_OFFSET_X
left_particles.process_material.emission_shape_offset.y = -SIDE_OFFSET_Y
left_particles.process_material.direction = Vector3.DOWN + Vector3.LEFT
right_particles.process_material.emission_shape_offset.x = SIDE_OFFSET_X
right_particles.process_material.emission_shape_offset.y = SIDE_OFFSET_Y
right_particles.process_material.direction = Vector3.UP + 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.UP
Belonging.ENEMY:
front_particles.process_material.emission_shape_offset.x = -FRONT_OFFSET_X
front_particles.process_material.direction = Vector3.LEFT
left_particles.process_material.emission_shape_offset.x = -SIDE_OFFSET_X
left_particles.process_material.emission_shape_offset.y = -SIDE_OFFSET_Y
left_particles.process_material.direction = Vector3.DOWN + Vector3.RIGHT
right_particles.process_material.emission_shape_offset.x = -SIDE_OFFSET_X
right_particles.process_material.emission_shape_offset.y = SIDE_OFFSET_Y
right_particles.process_material.direction = Vector3.UP + 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.DOWN
func shoot(ship_velocity: Vector2) -> bool:
var is_shot := super.shoot(ship_velocity)
if is_shot:
@@ -69,6 +27,10 @@ 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()
@@ -29,6 +29,7 @@ emission_sphere_radius = 2.0
angle_min = -179.99998
angle_max = 180.00002
inherit_velocity_ratio = 0.2
direction = Vector3(-1, -1, 0)
spread = 5.0
initial_velocity_min = 10.0
initial_velocity_max = 20.0
@@ -43,6 +44,7 @@ emission_sphere_radius = 2.0
angle_min = -179.99998
angle_max = 180.00002
inherit_velocity_ratio = 0.2
direction = Vector3(-1, 1, 0)
spread = 5.0
initial_velocity_min = 10.0
initial_velocity_max = 20.0
@@ -146,6 +148,7 @@ resource_local_to_scene = true
lifetime_randomness = 0.5
particle_flag_disable_z = true
inherit_velocity_ratio = 1.0
direction = Vector3(0, 1, 0)
spread = 15.0
initial_velocity_min = 5.0
initial_velocity_max = 15.0
@@ -160,6 +163,7 @@ type = 2
[node name="ShotParticles" type="Node2D" parent="." index="0"]
[node name="Front" type="GPUParticles2D" parent="ShotParticles" index="0"]
position = Vector2(22, 0)
emitting = false
amount = 32
texture = ExtResource("4_i0ica")
@@ -170,6 +174,7 @@ fixed_fps = 10
process_material = SubResource("ParticleProcessMaterial_377p4")
[node name="Left" type="GPUParticles2D" parent="ShotParticles" index="1"]
position = Vector2(17, -4)
emitting = false
texture = ExtResource("5_377p4")
lifetime = 0.4
@@ -178,6 +183,7 @@ fixed_fps = 10
process_material = SubResource("ParticleProcessMaterial_i0ica")
[node name="Right" type="GPUParticles2D" parent="ShotParticles" index="2"]
position = Vector2(17, 4)
emitting = false
texture = ExtResource("5_377p4")
lifetime = 0.4
@@ -186,11 +192,13 @@ fixed_fps = 10
process_material = SubResource("ParticleProcessMaterial_jfd4t")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="1"]
position = Vector2(9, 0)
sprite_frames = SubResource("SpriteFrames_kdf62")
animation = &"player_idle"
[node name="ShellParticles" type="GPUParticles2D" parent="." index="2"]
z_index = 1
position = Vector2(-1, 1)
emitting = false
amount = 1
texture = ExtResource("6_i0ica")
@@ -203,5 +211,8 @@ process_material = SubResource("ParticleProcessMaterial_nrbut")
wait_time = 1.2
one_shot = true
[node name="Muzzle" type="Node2D" parent="." index="4"]
position = Vector2(20, 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"]
@@ -4,10 +4,19 @@ extends AbstractWeapon
@export var reloader : GatlingReloader
@onready var sprite : AnimatedSprite2D = $AnimatedSprite2D
func _physics_process(delta: float) -> void:
reloader.process(delta)
func set_belonging(belonging: Belonging) -> void:
super.set_belonging(belonging)
sprite.play(PREFIXES[_belonging] + IDLE_POSTFIX)
func shoot(ship_velocity: Vector2) -> bool:
_can_shoot = reloader.can_shoot()
var is_shot := super.shoot(ship_velocity)
@@ -1,9 +1,10 @@
[gd_scene load_steps=7 format=3 uid="uid://c4mlppn5i55bp"]
[gd_scene load_steps=10 format=3 uid="uid://c4mlppn5i55bp"]
[ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_gblx7"]
[ext_resource type="Script" uid="uid://c1bsvmj7xhnxe" path="res://game/entities/weapons/gatling/gatling_weapon.gd" id="1_kg6du"]
[ext_resource type="PackedScene" uid="uid://yfvluap3uy1r" path="res://game/entities/weapons/gatling/gatling_projectile.tscn" id="2_ylc0n"]
[ext_resource type="Script" uid="uid://oslebeau3f4b" path="res://game/entities/weapons/gatling/gatling_reloader.gd" id="4_g81jq"]
[ext_resource type="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/weapons.png" id="5_ydc6p"]
[sub_resource type="Resource" id="Resource_oppha"]
script = ExtResource("4_g81jq")
@@ -11,8 +12,32 @@ firerate = 600
spin_out_time = 3
metadata/_custom_type_script = "uid://oslebeau3f4b"
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dra6h"]
size = Vector2(10, 7)
[sub_resource type="AtlasTexture" id="AtlasTexture_ydc6p"]
atlas = ExtResource("5_ydc6p")
region = Rect2(160, 176, 32, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_v064d"]
atlas = ExtResource("5_ydc6p")
region = Rect2(160, 160, 32, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_pjn33"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_ydc6p")
}],
"loop": true,
"name": &"enemy_idle",
"speed": 10.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_v064d")
}],
"loop": true,
"name": &"player_idle",
"speed": 10.0
}]
[node name="GatlingWeapon" instance=ExtResource("1_gblx7")]
script = ExtResource("1_kg6du")
@@ -20,5 +45,7 @@ reloader = SubResource("Resource_oppha")
sector_angle = 5
Projectile = ExtResource("2_ylc0n")
[node name="Sprite2D" type="Sprite2D" parent="." index="0"]
texture = SubResource("PlaceholderTexture2D_dra6h")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0"]
position = Vector2(6, 0)
sprite_frames = SubResource("SpriteFrames_pjn33")
animation = &"player_idle"
+6 -10
View File
@@ -1,13 +1,10 @@
[gd_scene load_steps=24 format=3 uid="uid://def1alrel4ioo"]
[gd_scene load_steps=23 format=3 uid="uid://def1alrel4ioo"]
[ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_pki4x"]
[ext_resource type="PackedScene" uid="uid://cmni0xrbbfcy5" path="res://game/entities/weapons/laser/laser_projectile.tscn" id="2_fecho"]
[ext_resource type="Script" uid="uid://bxr150at8ul2a" path="res://game/entities/weapons/laser/laser_weapon.gd" id="2_lbdvb"]
[ext_resource type="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/weapons.png" id="6_c8tb4"]
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dra6h"]
size = Vector2(10, 7)
[sub_resource type="AtlasTexture" id="AtlasTexture_4a3il"]
atlas = ExtResource("6_c8tb4")
region = Rect2(0, 80, 32, 16)
@@ -152,18 +149,17 @@ bullet_per_shot = 2
Projectile = ExtResource("2_fecho")
type = 2
[node name="Sprite2D" type="Sprite2D" parent="." index="0"]
texture = SubResource("PlaceholderTexture2D_dra6h")
[node name="IdleAnimatedSprite" type="AnimatedSprite2D" parent="." index="1"]
[node name="IdleAnimatedSprite" type="AnimatedSprite2D" parent="." index="0"]
position = Vector2(3, 0)
sprite_frames = SubResource("SpriteFrames_qjjka")
animation = &"player"
[node name="FiringAnimatedSprite" type="AnimatedSprite2D" parent="." index="2"]
[node name="FiringAnimatedSprite" type="AnimatedSprite2D" parent="." index="1"]
position = Vector2(3, 0)
sprite_frames = SubResource("SpriteFrames_c8tb4")
animation = &"player"
[node name="CooldownTimer" type="Timer" parent="." index="3"]
[node name="CooldownTimer" type="Timer" parent="." index="2"]
process_callback = 0
wait_time = 0.05
one_shot = true
@@ -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"]
BIN
View File
Binary file not shown.
+40
View File
@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://y2yfli24n51v"
path="res://.godot/imported/player.png-d16bf70f3ec5d02cd5daffcbae57946f.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://images/ships/player.png"
dest_files=["res://.godot/imported/player.png-d16bf70f3ec5d02cd5daffcbae57946f.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
BIN
View File
Binary file not shown.