diff --git a/game/entities/weapons/abstract_weapon.gd b/game/entities/weapons/abstract_weapon.gd index 87337c9..4945262 100644 --- a/game/entities/weapons/abstract_weapon.gd +++ b/game/entities/weapons/abstract_weapon.gd @@ -10,7 +10,6 @@ enum Belonging { PLAYER, ENEMY } @export var Projectile : PackedScene @export var reloaders : Array[AbstractReloader] -@export var projectile_positions : Array[Vector2] const PREFIXES := { @@ -42,11 +41,7 @@ func shoot(ship_velocity: Vector2) -> bool: for i in range(bullet_per_shot): var projectile := _create_projectile(ship_velocity) - if projectile_positions.size() > 0: - projectile.global_position = global_position + projectile_positions[_current_projectile_position] - _current_projectile_position += 1 - if _current_projectile_position >= projectile_positions.size(): - _current_projectile_position = 0 + projectile.global_position = global_position + _get_projectile_position() get_tree().current_scene.add_child(projectile) @@ -56,6 +51,10 @@ func shoot(ship_velocity: Vector2) -> bool: return true +func _get_projectile_position() -> Vector2: + return Vector2.ZERO + + func _create_projectile(ship_velocity: Vector2) -> AbstractProjectile: var projectile : AbstractProjectile = Projectile.instantiate() projectile.global_position = global_position diff --git a/game/entities/weapons/cannon/cannon_weapon.tscn b/game/entities/weapons/cannon/cannon_weapon.tscn index 88b5da4..45bb874 100644 --- a/game/entities/weapons/cannon/cannon_weapon.tscn +++ b/game/entities/weapons/cannon/cannon_weapon.tscn @@ -1,18 +1,12 @@ -[gd_scene load_steps=24 format=3 uid="uid://bccaoirwdkp7n"] +[gd_scene load_steps=23 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="Texture2D" uid="uid://leofxnlflrdn" path="res://particle_textures/flame.tres" id="4_jfd4t"] [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="Gradient" id="Gradient_jfd4t"] -colors = PackedColorArray(1, 0.8039216, 0.45882353, 1, 0.9372549, 0.49019608, 0.34117648, 1) - -[sub_resource type="GradientTexture1D" id="GradientTexture1D_i0ica"] -gradient = SubResource("Gradient_jfd4t") -width = 2 - [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_377p4"] resource_local_to_scene = true lifetime_randomness = 0.4 @@ -160,7 +154,7 @@ Projectile = ExtResource("2_2bjeu") [node name="Front" type="GPUParticles2D" parent="ShotParticles" index="0"] emitting = false amount = 32 -texture = SubResource("GradientTexture1D_i0ica") +texture = ExtResource("4_jfd4t") lifetime = 0.5 one_shot = true preprocess = 0.1 @@ -169,7 +163,7 @@ process_material = SubResource("ParticleProcessMaterial_377p4") [node name="Left" type="GPUParticles2D" parent="ShotParticles" index="1"] emitting = false -texture = SubResource("GradientTexture1D_i0ica") +texture = ExtResource("4_jfd4t") lifetime = 0.2 one_shot = true fixed_fps = 10 @@ -177,7 +171,7 @@ process_material = SubResource("ParticleProcessMaterial_i0ica") [node name="Right" type="GPUParticles2D" parent="ShotParticles" index="2"] emitting = false -texture = SubResource("GradientTexture1D_i0ica") +texture = ExtResource("4_jfd4t") lifetime = 0.2 one_shot = true fixed_fps = 10 diff --git a/game/entities/weapons/launcher/launcher_projectile.tscn b/game/entities/weapons/launcher/launcher_projectile.tscn index f327d5d..2c94ef9 100644 --- a/game/entities/weapons/launcher/launcher_projectile.tscn +++ b/game/entities/weapons/launcher/launcher_projectile.tscn @@ -1,10 +1,19 @@ -[gd_scene load_steps=16 format=3 uid="uid://dukgbg13ujkv2"] +[gd_scene load_steps=18 format=3 uid="uid://dukgbg13ujkv2"] [ext_resource type="PackedScene" uid="uid://betr5ry5tc75e" path="res://game/entities/weapons/blast_projectile.tscn" id="1_0mcat"] [ext_resource type="Script" uid="uid://dkvur5bdwg3sr" path="res://game/entities/weapons/launcher/launcher_projectile.gd" id="2_6hdsf"] +[ext_resource type="Texture2D" uid="uid://leofxnlflrdn" path="res://particle_textures/flame.tres" id="3_kos01"] [ext_resource type="Script" uid="uid://dftb7hg5f06b5" path="res://game/health_system/damage/explosion_damage.gd" id="3_ycnsk"] [ext_resource type="Texture2D" uid="uid://oj86smpsipw4" path="res://images/projectiles.png" id="4_kxgpk"] +[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_kxgpk"] +lifetime_randomness = 0.5 +particle_flag_disable_z = true +emission_shape = 1 +emission_sphere_radius = 2.0 +spread = 15.0 +gravity = Vector3(0, 0, 0) + [sub_resource type="AtlasTexture" id="AtlasTexture_kxgpk"] atlas = ExtResource("4_kxgpk") region = Rect2(0, 32, 16, 16) @@ -56,34 +65,40 @@ script = ExtResource("2_6hdsf") rotation_speed = 90 speed = 300 -[node name="Sprite2D_E" type="Sprite2D" parent="." index="0"] +[node name="GPUParticles2D" type="GPUParticles2D" parent="." index="0"] +amount = 16 +texture = ExtResource("3_kos01") +lifetime = 0.09999999999999999 +process_material = SubResource("ParticleProcessMaterial_kxgpk") + +[node name="Sprite2D_E" type="Sprite2D" parent="." index="1"] texture = SubResource("AtlasTexture_kxgpk") -[node name="Sprite2D_SE" type="Sprite2D" parent="." index="1"] +[node name="Sprite2D_SE" type="Sprite2D" parent="." index="2"] texture = SubResource("AtlasTexture_kos01") -[node name="Sprite2D_S" type="Sprite2D" parent="." index="2"] +[node name="Sprite2D_S" type="Sprite2D" parent="." index="3"] texture = SubResource("AtlasTexture_iqm85") -[node name="Sprite2D_SW" type="Sprite2D" parent="." index="3"] +[node name="Sprite2D_SW" type="Sprite2D" parent="." index="4"] texture = SubResource("AtlasTexture_rno65") -[node name="Sprite2D_W" type="Sprite2D" parent="." index="4"] +[node name="Sprite2D_W" type="Sprite2D" parent="." index="5"] texture = SubResource("AtlasTexture_f648y") -[node name="Sprite2D_NW" type="Sprite2D" parent="." index="5"] +[node name="Sprite2D_NW" type="Sprite2D" parent="." index="6"] texture = SubResource("AtlasTexture_she3g") -[node name="Sprite2D_N" type="Sprite2D" parent="." index="6"] +[node name="Sprite2D_N" type="Sprite2D" parent="." index="7"] texture = SubResource("AtlasTexture_4wwm4") -[node name="Sprite2D_NE" type="Sprite2D" parent="." index="7"] +[node name="Sprite2D_NE" type="Sprite2D" parent="." index="8"] texture = SubResource("AtlasTexture_dl8vu") -[node name="CollisionShape2D" parent="." index="8"] +[node name="CollisionShape2D" parent="." index="9"] shape = SubResource("CapsuleShape2D_6hdsf") -[node name="Blast" parent="." index="10"] +[node name="Blast" parent="." index="11"] collision_layer = 0 collision_mask = 0 damage = SubResource("Resource_kos01") diff --git a/game/entities/weapons/launcher/launcher_weapon.gd b/game/entities/weapons/launcher/launcher_weapon.gd index b209331..2ec7a5f 100644 --- a/game/entities/weapons/launcher/launcher_weapon.gd +++ b/game/entities/weapons/launcher/launcher_weapon.gd @@ -1 +1,89 @@ extends AbstractWeapon + + +@onready var player_sprite : Sprite2D = $PlayerSprite +@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, +] +var _particles_index := 0 + +const PLAYER_PROJECTILE_POSITIONS : Array[Vector2] = [ + Vector2(4, 3), Vector2(4, -3), +] +const ENEMY_PROJECTILE_POSITIONS : Array[Vector2] = [ + Vector2(-4, 3), Vector2(-4, -3), +] +var _projectile_position_index := 0 + + +func set_belonging(belonging: Belonging) -> void: + super.set_belonging(belonging) + + match _belonging: + Belonging.PLAYER: + player_sprite.show() + enemy_sprite.hide() + Belonging.ENEMY: + player_sprite.hide() + enemy_sprite.show() + + +func shoot(ship_velocity: Vector2) -> bool: + var is_shot := super.shoot(ship_velocity) + if is_shot: + _can_shoot = false + cooldown_timer.start() + _restart_particles() + + return is_shot + + +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) + + 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) + + return projectile_position + + +func _get_particle_from_array(array: Array[GPUParticles2D]) -> GPUParticles2D: + var particle := array[_particles_index] + _particles_index += 1 + if _particles_index >= array.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 diff --git a/game/entities/weapons/launcher/launcher_weapon.tscn b/game/entities/weapons/launcher/launcher_weapon.tscn index a1f4601..6e4c363 100644 --- a/game/entities/weapons/launcher/launcher_weapon.tscn +++ b/game/entities/weapons/launcher/launcher_weapon.tscn @@ -1,24 +1,116 @@ -[gd_scene load_steps=8 format=3 uid="uid://c3l866fdqt7pf"] +[gd_scene load_steps=12 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"] -[ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_1rkeb"] [ext_resource type="PackedScene" uid="uid://dukgbg13ujkv2" path="res://game/entities/weapons/launcher/launcher_projectile.tscn" id="3_fsoo2"] -[ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_fsoo2"] +[ext_resource type="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/weapons.png" id="6_3cw5x"] +[ext_resource type="Texture2D" uid="uid://leofxnlflrdn" path="res://particle_textures/flame.tres" id="7_u8eh0"] -[sub_resource type="Resource" id="Resource_8arbu"] -script = ExtResource("4_fsoo2") -firerate = 120 -metadata/_custom_type_script = "uid://b255rb32vc6co" +[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 +inherit_velocity_ratio = 0.5 +direction = Vector3(-1, 0, 0) +spread = 15.0 +initial_velocity_min = 30.0 +initial_velocity_max = 50.0 +gravity = Vector3(0, 0, 0) -[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dra6h"] -size = Vector2(10, 7) +[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 +inherit_velocity_ratio = 0.5 +direction = Vector3(-1, 0, 0) +spread = 15.0 +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 +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 +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, 112, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ylgjm"] +atlas = ExtResource("6_3cw5x") +region = Rect2(224, 128, 32, 16) [node name="LauncherWeapon" instance=ExtResource("1_sk5u1")] script = ExtResource("2_mxjpe") sector_angle = 5 Projectile = ExtResource("3_fsoo2") -reloaders = Array[ExtResource("3_1rkeb")]([SubResource("Resource_8arbu")]) -[node name="Sprite2D" type="Sprite2D" parent="." index="0"] -texture = SubResource("PlaceholderTexture2D_dra6h") +[node name="ShotProjectiles" type="Node2D" parent="." index="0"] + +[node name="PlayerLeftParticles" type="GPUParticles2D" parent="ShotProjectiles" index="0"] +emitting = false +amount = 16 +texture = ExtResource("7_u8eh0") +lifetime = 0.3 +one_shot = true +process_material = SubResource("ParticleProcessMaterial_u8eh0") + +[node name="PlayerRightParticles" type="GPUParticles2D" parent="ShotProjectiles" index="1"] +emitting = false +amount = 16 +texture = ExtResource("7_u8eh0") +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("7_u8eh0") +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("7_u8eh0") +lifetime = 0.3 +one_shot = true +process_material = SubResource("ParticleProcessMaterial_ylgjm") + +[node name="PlayerSprite" type="Sprite2D" parent="." index="1"] +texture = SubResource("AtlasTexture_u8eh0") + +[node name="EnemySprite" type="Sprite2D" parent="." index="2"] +texture = SubResource("AtlasTexture_ylgjm") + +[node name="CooldownTimer" type="Timer" parent="." index="3"] +wait_time = 0.5 +one_shot = true + +[connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"] diff --git a/particle_textures/flame.tres b/particle_textures/flame.tres new file mode 100644 index 0000000..17bc2cc --- /dev/null +++ b/particle_textures/flame.tres @@ -0,0 +1,8 @@ +[gd_resource type="GradientTexture1D" load_steps=2 format=3 uid="uid://leofxnlflrdn"] + +[sub_resource type="Gradient" id="Gradient_kxgpk"] +colors = PackedColorArray(0.9372549, 0.49019608, 0.34117648, 1, 1, 0.8039216, 0.45882353, 1) + +[resource] +gradient = SubResource("Gradient_kxgpk") +width = 2