diff --git a/game/entities/weapons/abstract_weapon.gd b/game/entities/weapons/abstract_weapon.gd index a6f500b..b715a5b 100644 --- a/game/entities/weapons/abstract_weapon.gd +++ b/game/entities/weapons/abstract_weapon.gd @@ -9,7 +9,6 @@ enum Belonging { PLAYER, ENEMY } @export_range(0, 360) var sector_angle : int = 0 @export var Projectile : PackedScene -@export var reloaders : Array[AbstractReloader] const PREFIXES := { @@ -23,21 +22,16 @@ const RELOAD_POSTFIX = "_reloading" var _belonging: Belonging -var _current_projectile_position := 0 var _can_shoot := true -func _physics_process(delta: float) -> void: - for reloader in reloaders: - reloader.process(delta) - func set_belonging(belonging: Belonging) -> void: _belonging = belonging func shoot(ship_velocity: Vector2) -> bool: - if not _can_shoot or not _reloaders_can_shoot(): return false + if not _can_shoot: return false for i in range(bullet_per_shot): var projectile := _create_projectile(ship_velocity) @@ -46,9 +40,6 @@ func shoot(ship_velocity: Vector2) -> bool: get_tree().current_scene.add_child(projectile) - for reloader in reloaders: - reloader.shoot() - return true @@ -75,10 +66,3 @@ func _create_projectile(ship_velocity: Vector2) -> AbstractProjectile: projectile.direction = projectile.direction.rotated(random_angle) return projectile - - -func _reloaders_can_shoot() -> bool: - for reloader in reloaders: - if not reloader.can_shoot(): - return false - return true diff --git a/game/reloaders/gatling_reloader.gd b/game/entities/weapons/gatling/gatling_reloader.gd similarity index 94% rename from game/reloaders/gatling_reloader.gd rename to game/entities/weapons/gatling/gatling_reloader.gd index 0c6fc67..921b150 100644 --- a/game/reloaders/gatling_reloader.gd +++ b/game/entities/weapons/gatling/gatling_reloader.gd @@ -1,4 +1,4 @@ -extends AbstractReloader +extends Resource class_name GatlingReloader @@ -23,6 +23,10 @@ var _cooldown : float var _last_delta : float +func _init() -> void: + resource_local_to_scene = true + + func _ready() -> void: _calculate_delay() diff --git a/game/reloaders/gatling_reloader.gd.uid b/game/entities/weapons/gatling/gatling_reloader.gd.uid similarity index 100% rename from game/reloaders/gatling_reloader.gd.uid rename to game/entities/weapons/gatling/gatling_reloader.gd.uid diff --git a/game/entities/weapons/gatling/gatling_weapon.gd b/game/entities/weapons/gatling/gatling_weapon.gd index b209331..4ae15da 100644 --- a/game/entities/weapons/gatling/gatling_weapon.gd +++ b/game/entities/weapons/gatling/gatling_weapon.gd @@ -1 +1,17 @@ extends AbstractWeapon + + +@export var reloader : GatlingReloader + + +func _physics_process(delta: float) -> void: + reloader.process(delta) + + +func shoot(ship_velocity: Vector2) -> bool: + _can_shoot = reloader.can_shoot() + var is_shot := super.shoot(ship_velocity) + if is_shot: + reloader.shoot() + + return is_shot diff --git a/game/entities/weapons/gatling/gatling_weapon.tscn b/game/entities/weapons/gatling/gatling_weapon.tscn index c3ae4bb..0ece409 100644 --- a/game/entities/weapons/gatling/gatling_weapon.tscn +++ b/game/entities/weapons/gatling/gatling_weapon.tscn @@ -1,12 +1,11 @@ -[gd_scene load_steps=8 format=3 uid="uid://c4mlppn5i55bp"] +[gd_scene load_steps=7 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://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_uucc4"] -[ext_resource type="Script" uid="uid://oslebeau3f4b" path="res://game/reloaders/gatling_reloader.gd" id="4_g81jq"] +[ext_resource type="Script" uid="uid://oslebeau3f4b" path="res://game/entities/weapons/gatling/gatling_reloader.gd" id="4_g81jq"] -[sub_resource type="Resource" id="Resource_kg6du"] +[sub_resource type="Resource" id="Resource_oppha"] script = ExtResource("4_g81jq") firerate = 600 spin_out_time = 3 @@ -17,9 +16,9 @@ size = Vector2(10, 7) [node name="GatlingWeapon" instance=ExtResource("1_gblx7")] script = ExtResource("1_kg6du") +reloader = SubResource("Resource_oppha") sector_angle = 5 Projectile = ExtResource("2_ylc0n") -reloaders = Array[ExtResource("3_uucc4")]([SubResource("Resource_kg6du")]) [node name="Sprite2D" type="Sprite2D" parent="." index="0"] texture = SubResource("PlaceholderTexture2D_dra6h") diff --git a/game/entities/weapons/laser/laser_weapon.tscn b/game/entities/weapons/laser/laser_weapon.tscn index 0f9f8c7..f3eef1f 100644 --- a/game/entities/weapons/laser/laser_weapon.tscn +++ b/game/entities/weapons/laser/laser_weapon.tscn @@ -3,15 +3,8 @@ [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") -firerate = 1500 -metadata/_custom_type_script = "uid://b255rb32vc6co" - [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dra6h"] size = Vector2(10, 7) @@ -157,7 +150,6 @@ animations = [{ script = ExtResource("2_lbdvb") bullet_per_shot = 2 Projectile = ExtResource("2_fecho") -reloaders = Array[ExtResource("3_c1wcw")]([SubResource("Resource_fecho")]) [node name="Sprite2D" type="Sprite2D" parent="." index="0"] texture = SubResource("PlaceholderTexture2D_dra6h") diff --git a/game/entities/weapons/plasma/plasma_weapon.gd b/game/entities/weapons/plasma/plasma_weapon.gd index b209331..1cb1df7 100644 --- a/game/entities/weapons/plasma/plasma_weapon.gd +++ b/game/entities/weapons/plasma/plasma_weapon.gd @@ -1 +1,42 @@ extends AbstractWeapon + + +@onready var sprite : AnimatedSprite2D = $AnimatedSprite2D +@onready var cooldown_timer : Timer = $CooldownTimer + + +func set_belonging(belonging: Belonging) -> void: + super.set_belonging(belonging) + + sprite.play(PREFIXES[_belonging] + IDLE_POSTFIX) + + +func shoot(ship_velocity: Vector2) -> bool: + var is_shot := super.shoot(ship_velocity) + if is_shot: + sprite.play(PREFIXES[_belonging] + SHOT_POSTFIX) + _can_shoot = false + cooldown_timer.start() + + 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) + + +func _on_cooldown_timer_timeout() -> void: + sprite.play(PREFIXES[_belonging] + IDLE_POSTFIX) + _can_shoot = true diff --git a/game/entities/weapons/plasma/plasma_weapon.tscn b/game/entities/weapons/plasma/plasma_weapon.tscn index 14ca13a..f2ee626 100644 --- a/game/entities/weapons/plasma/plasma_weapon.tscn +++ b/game/entities/weapons/plasma/plasma_weapon.tscn @@ -1,24 +1,113 @@ -[gd_scene load_steps=8 format=3 uid="uid://cj1jclfterepm"] +[gd_scene load_steps=14 format=3 uid="uid://cj1jclfterepm"] [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_pkk8e"] [ext_resource type="Script" uid="uid://cu6ck2oqqdem8" path="res://game/entities/weapons/plasma/plasma_weapon.gd" id="2_fnsb7"] [ext_resource type="PackedScene" uid="uid://cgvb0hjrl5h4s" path="res://game/entities/weapons/plasma/plasma_projectile.tscn" id="2_yluvp"] -[ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_fnsb7"] -[ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_gpth1"] +[ext_resource type="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/weapons.png" id="6_u6d2q"] -[sub_resource type="Resource" id="Resource_yluvp"] -script = ExtResource("4_gpth1") -firerate = 150 -metadata/_custom_type_script = "uid://b255rb32vc6co" +[sub_resource type="AtlasTexture" id="AtlasTexture_vj3ee"] +atlas = ExtResource("6_u6d2q") +region = Rect2(0, 48, 32, 16) -[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dra6h"] -size = Vector2(10, 7) +[sub_resource type="AtlasTexture" id="AtlasTexture_u6d2q"] +atlas = ExtResource("6_u6d2q") +region = Rect2(96, 48, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ity8s"] +atlas = ExtResource("6_u6d2q") +region = Rect2(32, 48, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_dm1ox"] +atlas = ExtResource("6_u6d2q") +region = Rect2(64, 48, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_x71d5"] +atlas = ExtResource("6_u6d2q") +region = Rect2(0, 32, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_j64vb"] +atlas = ExtResource("6_u6d2q") +region = Rect2(96, 32, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_pevdi"] +atlas = ExtResource("6_u6d2q") +region = Rect2(32, 32, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_40asj"] +atlas = ExtResource("6_u6d2q") +region = Rect2(64, 32, 32, 16) + +[sub_resource type="SpriteFrames" id="SpriteFrames_hyw35"] +resource_local_to_scene = true +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_vj3ee") +}], +"loop": true, +"name": &"enemy_idle", +"speed": 10.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_u6d2q") +}], +"loop": true, +"name": &"enemy_reloading", +"speed": 10.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_ity8s") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_dm1ox") +}], +"loop": false, +"name": &"enemy_shot", +"speed": 10.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_x71d5") +}], +"loop": true, +"name": &"player_idle", +"speed": 10.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_j64vb") +}], +"loop": true, +"name": &"player_reloading", +"speed": 10.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_pevdi") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_40asj") +}], +"loop": false, +"name": &"player_shot", +"speed": 10.0 +}] [node name="PlasmaWeapon" instance=ExtResource("1_pkk8e")] script = ExtResource("2_fnsb7") sector_angle = 2 Projectile = ExtResource("2_yluvp") -reloaders = Array[ExtResource("3_fnsb7")]([SubResource("Resource_yluvp")]) -[node name="Sprite2D" type="Sprite2D" parent="." index="0"] -texture = SubResource("PlaceholderTexture2D_dra6h") +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0"] +sprite_frames = SubResource("SpriteFrames_hyw35") +animation = &"player_reloading" + +[node name="CooldownTimer" type="Timer" parent="." index="1"] +process_callback = 0 +wait_time = 0.4 +one_shot = true + +[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.gd b/game/entities/weapons/railgun/railgun_weapon.gd index f578236..1807b45 100644 --- a/game/entities/weapons/railgun/railgun_weapon.gd +++ b/game/entities/weapons/railgun/railgun_weapon.gd @@ -14,7 +14,6 @@ func shoot(ship_velocity: Vector2) -> bool: var is_shot := super.shoot(ship_velocity) if is_shot: sprite.play(PREFIXES[_belonging] + SHOT_POSTFIX) - print(1, sprite.animation) _can_shoot = false return is_shot @@ -23,9 +22,6 @@ func shoot(ship_velocity: Vector2) -> bool: func _on_animated_sprite_2d_animation_finished() -> void: if sprite.animation.ends_with(SHOT_POSTFIX): sprite.play(PREFIXES[_belonging] + RELOAD_POSTFIX) - print(PREFIXES[_belonging] + RELOAD_POSTFIX) - print(2, sprite.animation) else: sprite.play(PREFIXES[_belonging] + IDLE_POSTFIX) - print(3, sprite.animation) _can_shoot = true diff --git a/game/reloaders/abstract_reloader.gd b/game/reloaders/abstract_reloader.gd deleted file mode 100644 index 2e1f51c..0000000 --- a/game/reloaders/abstract_reloader.gd +++ /dev/null @@ -1,27 +0,0 @@ -@abstract -extends Resource -class_name AbstractReloader - - -func _init() -> void: - resource_local_to_scene = true - - -@abstract -func process(delta: float) -> void - - -@abstract -func can_shoot() -> bool - - -@abstract -func shoot() -> void - - -@abstract -func reload() -> void - - -@abstract -func get_process_percent() -> int diff --git a/game/reloaders/abstract_reloader.gd.uid b/game/reloaders/abstract_reloader.gd.uid deleted file mode 100644 index 1173951..0000000 --- a/game/reloaders/abstract_reloader.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://ccpriilfr3kme diff --git a/game/reloaders/firerate_reloader.gd b/game/reloaders/firerate_reloader.gd deleted file mode 100644 index b9e83d8..0000000 --- a/game/reloaders/firerate_reloader.gd +++ /dev/null @@ -1,43 +0,0 @@ -extends AbstractReloader -class_name FirerateReloader - - -@export_range(1, 1500) var firerate : int = 1: - set(value): - firerate = value - _calculate_delay() - - -var _delay : float -var _delay_tenth : float -var _cooldown : float - - -func _ready() -> void: - _calculate_delay() - - -func process(delta: float) -> void: - if _cooldown > 0: - _cooldown -= delta - - -func can_shoot() -> bool: - return _cooldown <= 0 - - -func shoot() -> void: - _cooldown = _delay - - -func reload() -> void: - pass - - -func get_process_percent() -> int: - return 100 - int(_cooldown * 100 / _delay) - - -func _calculate_delay() -> void: - _delay = 60.0 / firerate - _delay_tenth = _delay / 10 diff --git a/game/reloaders/firerate_reloader.gd.uid b/game/reloaders/firerate_reloader.gd.uid deleted file mode 100644 index fa8d9de..0000000 --- a/game/reloaders/firerate_reloader.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://b255rb32vc6co diff --git a/images/weapons.png b/images/weapons.png index a362c3e..9516530 100644 --- a/images/weapons.png +++ b/images/weapons.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e12bda13b3796cfff272c452a25865cd2ec269d98301b18a2bb279bbeff2c292 -size 4220 +oid sha256:b72d02804feb823482a05ec462b1d8e134dd1d8aeb7f8bae13d50a28e21dbcd0 +size 4254 diff --git a/particle_textures/energy.tres b/particle_textures/energy.tres new file mode 100644 index 0000000..28b629e --- /dev/null +++ b/particle_textures/energy.tres @@ -0,0 +1,8 @@ +[gd_resource type="GradientTexture1D" load_steps=2 format=3 uid="uid://dedca1d30igae"] + +[sub_resource type="Gradient" id="Gradient_ub67s"] +colors = PackedColorArray(0.4509804, 0.9372549, 0.96862745, 1, 0.25490198, 0.6509804, 0.9647059, 1) + +[resource] +gradient = SubResource("Gradient_ub67s") +width = 2