diff --git a/game/entities/weapons/abstract_weapon.gd b/game/entities/weapons/abstract_weapon.gd index 4945262..7a7a0fb 100644 --- a/game/entities/weapons/abstract_weapon.gd +++ b/game/entities/weapons/abstract_weapon.gd @@ -13,12 +13,12 @@ enum Belonging { PLAYER, ENEMY } const PREFIXES := { - Belonging.PLAYER: "player_", - Belonging.ENEMY: "enemy_", + Belonging.PLAYER: "player", + Belonging.ENEMY: "enemy", } -const SHOT_POSTFIX = "shot" -const IDLE_POSTFIX = "idle" +const SHOT_POSTFIX = "_shot" +const IDLE_POSTFIX = "_idle" var _belonging: Belonging diff --git a/game/entities/weapons/laser/laser_projectile.gd b/game/entities/weapons/laser/laser_projectile.gd index 4440e79..05450b6 100644 --- a/game/entities/weapons/laser/laser_projectile.gd +++ b/game/entities/weapons/laser/laser_projectile.gd @@ -1,2 +1,19 @@ class_name LaserProjectile extends DirectHitProjectile + + +@onready var particles : GPUParticles2D = $GPUParticles2D + + +func _ready() -> void: + super._ready() + _update_sprite(_velocity) + + +func _update_sprite(velocity: Vector2) -> void: + var angle := posmod(floor(rad_to_deg(velocity.angle())), 360) + + if angle > 90 and angle < 270: + particles.process_material.direction = Vector3.RIGHT + else: + particles.process_material.direction = Vector3.LEFT diff --git a/game/entities/weapons/laser/laser_projectile.tscn b/game/entities/weapons/laser/laser_projectile.tscn index 1f9e424..60c181e 100644 --- a/game/entities/weapons/laser/laser_projectile.tscn +++ b/game/entities/weapons/laser/laser_projectile.tscn @@ -14,11 +14,14 @@ metadata/_custom_type_script = "uid://c27v705giygv4" radius = 1.0 [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_7dd03"] +resource_local_to_scene = true particle_flag_disable_z = true angle_min = -179.99998 angle_max = 180.00002 -inherit_velocity_ratio = 0.5 -spread = 15.0 +inherit_velocity_ratio = 1.0 +spread = 0.0 +initial_velocity_min = -250.0 +initial_velocity_max = -250.0 gravity = Vector3(0, 0, 0) [node name="LaserProjectile" instance=ExtResource("1_3a8fg")] @@ -32,7 +35,7 @@ speed = 500 shape = SubResource("CircleShape2D_ylokk") [node name="GPUParticles2D" type="GPUParticles2D" parent="." index="2"] -amount = 32 +amount = 64 texture = ExtResource("4_bytws") -lifetime = 0.05 +lifetime = 0.2 process_material = SubResource("ParticleProcessMaterial_7dd03") diff --git a/game/entities/weapons/laser/laser_weapon.gd b/game/entities/weapons/laser/laser_weapon.gd index b209331..9b97bde 100644 --- a/game/entities/weapons/laser/laser_weapon.gd +++ b/game/entities/weapons/laser/laser_weapon.gd @@ -1 +1,41 @@ extends AbstractWeapon + + +@onready var idle_sprite : AnimatedSprite2D = $IdleAnimatedSprite +@onready var firing_sprite : AnimatedSprite2D = $FiringAnimatedSprite +@onready var cooldown_timer : Timer = $CooldownTimer + + +func _ready() -> void: + _switch_sprite(false) + + +func set_belonging(belonging: Belonging) -> void: + super.set_belonging(belonging) + + idle_sprite.play(PREFIXES[_belonging]) + firing_sprite.play(PREFIXES[_belonging]) + + +func shoot(ship_velocity: Vector2) -> bool: + var is_shot := super.shoot(ship_velocity) + if is_shot: + _can_shoot = false + _switch_sprite(true) + cooldown_timer.start() + + return is_shot + + +func _on_cooldown_timer_timeout() -> void: + _can_shoot = true + _switch_sprite(false) + + +func _switch_sprite(firing: bool) -> void: + if firing: + idle_sprite.hide() + firing_sprite.show() + else: + idle_sprite.show() + firing_sprite.hide() diff --git a/game/entities/weapons/laser/laser_weapon.tscn b/game/entities/weapons/laser/laser_weapon.tscn index e839db2..0f9f8c7 100644 --- a/game/entities/weapons/laser/laser_weapon.tscn +++ b/game/entities/weapons/laser/laser_weapon.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=8 format=3 uid="uid://def1alrel4ioo"] +[gd_scene load_steps=27 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="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_c1wcw"] [ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_cl0br"] +[ext_resource type="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/weapons.png" id="6_c8tb4"] [sub_resource type="Resource" id="Resource_fecho"] script = ExtResource("4_cl0br") @@ -14,6 +15,144 @@ metadata/_custom_type_script = "uid://b255rb32vc6co" [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) + +[sub_resource type="AtlasTexture" id="AtlasTexture_n1iu2"] +atlas = ExtResource("6_c8tb4") +region = Rect2(32, 80, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_kgblc"] +atlas = ExtResource("6_c8tb4") +region = Rect2(64, 80, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_f2vvu"] +atlas = ExtResource("6_c8tb4") +region = Rect2(96, 80, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_7rt33"] +atlas = ExtResource("6_c8tb4") +region = Rect2(0, 64, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_n02tm"] +atlas = ExtResource("6_c8tb4") +region = Rect2(32, 64, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_7q2cb"] +atlas = ExtResource("6_c8tb4") +region = Rect2(64, 64, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_qatwk"] +atlas = ExtResource("6_c8tb4") +region = Rect2(96, 64, 32, 16) + +[sub_resource type="SpriteFrames" id="SpriteFrames_qjjka"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_4a3il") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_n1iu2") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_kgblc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_f2vvu") +}], +"loop": true, +"name": &"enemy", +"speed": 10.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_7rt33") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_n02tm") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_7q2cb") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_qatwk") +}], +"loop": true, +"name": &"player", +"speed": 10.0 +}] + +[sub_resource type="AtlasTexture" id="AtlasTexture_dggsl"] +atlas = ExtResource("6_c8tb4") +region = Rect2(128, 80, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gbu7x"] +atlas = ExtResource("6_c8tb4") +region = Rect2(160, 80, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_2prsi"] +atlas = ExtResource("6_c8tb4") +region = Rect2(192, 80, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_jgejx"] +atlas = ExtResource("6_c8tb4") +region = Rect2(224, 80, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_5c4fv"] +atlas = ExtResource("6_c8tb4") +region = Rect2(128, 64, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_2jgsd"] +atlas = ExtResource("6_c8tb4") +region = Rect2(160, 64, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_4n6qh"] +atlas = ExtResource("6_c8tb4") +region = Rect2(192, 64, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_amoq0"] +atlas = ExtResource("6_c8tb4") +region = Rect2(224, 64, 32, 16) + +[sub_resource type="SpriteFrames" id="SpriteFrames_c8tb4"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_dggsl") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_gbu7x") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_2prsi") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_jgejx") +}], +"loop": true, +"name": &"enemy", +"speed": 10.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_5c4fv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_2jgsd") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_4n6qh") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_amoq0") +}], +"loop": true, +"name": &"player", +"speed": 10.0 +}] + [node name="LaserWeapon" instance=ExtResource("1_pki4x")] script = ExtResource("2_lbdvb") bullet_per_shot = 2 @@ -22,3 +161,18 @@ reloaders = Array[ExtResource("3_c1wcw")]([SubResource("Resource_fecho")]) [node name="Sprite2D" type="Sprite2D" parent="." index="0"] texture = SubResource("PlaceholderTexture2D_dra6h") + +[node name="IdleAnimatedSprite" type="AnimatedSprite2D" parent="." index="1"] +sprite_frames = SubResource("SpriteFrames_qjjka") +animation = &"player" + +[node name="FiringAnimatedSprite" type="AnimatedSprite2D" parent="." index="2"] +sprite_frames = SubResource("SpriteFrames_c8tb4") +animation = &"player" + +[node name="CooldownTimer" type="Timer" parent="." index="3"] +process_callback = 0 +wait_time = 0.05 +one_shot = true + +[connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"]