Added PlasmaWeapon textures

This commit is contained in:
2025-11-23 19:04:34 +03:00
parent a6185d7ce1
commit 3e5e2dbe0f
15 changed files with 178 additions and 121 deletions
+1 -17
View File
@@ -9,7 +9,6 @@ enum Belonging { PLAYER, ENEMY }
@export_range(0, 360) var sector_angle : int = 0 @export_range(0, 360) var sector_angle : int = 0
@export var Projectile : PackedScene @export var Projectile : PackedScene
@export var reloaders : Array[AbstractReloader]
const PREFIXES := { const PREFIXES := {
@@ -23,21 +22,16 @@ const RELOAD_POSTFIX = "_reloading"
var _belonging: Belonging var _belonging: Belonging
var _current_projectile_position := 0
var _can_shoot := true var _can_shoot := true
func _physics_process(delta: float) -> void:
for reloader in reloaders:
reloader.process(delta)
func set_belonging(belonging: Belonging) -> void: func set_belonging(belonging: Belonging) -> void:
_belonging = belonging _belonging = belonging
func shoot(ship_velocity: Vector2) -> bool: 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): for i in range(bullet_per_shot):
var projectile := _create_projectile(ship_velocity) var projectile := _create_projectile(ship_velocity)
@@ -46,9 +40,6 @@ func shoot(ship_velocity: Vector2) -> bool:
get_tree().current_scene.add_child(projectile) get_tree().current_scene.add_child(projectile)
for reloader in reloaders:
reloader.shoot()
return true return true
@@ -75,10 +66,3 @@ func _create_projectile(ship_velocity: Vector2) -> AbstractProjectile:
projectile.direction = projectile.direction.rotated(random_angle) projectile.direction = projectile.direction.rotated(random_angle)
return projectile return projectile
func _reloaders_can_shoot() -> bool:
for reloader in reloaders:
if not reloader.can_shoot():
return false
return true
@@ -1,4 +1,4 @@
extends AbstractReloader extends Resource
class_name GatlingReloader class_name GatlingReloader
@@ -23,6 +23,10 @@ var _cooldown : float
var _last_delta : float var _last_delta : float
func _init() -> void:
resource_local_to_scene = true
func _ready() -> void: func _ready() -> void:
_calculate_delay() _calculate_delay()
@@ -1 +1,17 @@
extends AbstractWeapon 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
@@ -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="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="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="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/entities/weapons/gatling/gatling_reloader.gd" id="4_g81jq"]
[ext_resource type="Script" uid="uid://oslebeau3f4b" path="res://game/reloaders/gatling_reloader.gd" id="4_g81jq"]
[sub_resource type="Resource" id="Resource_kg6du"] [sub_resource type="Resource" id="Resource_oppha"]
script = ExtResource("4_g81jq") script = ExtResource("4_g81jq")
firerate = 600 firerate = 600
spin_out_time = 3 spin_out_time = 3
@@ -17,9 +16,9 @@ size = Vector2(10, 7)
[node name="GatlingWeapon" instance=ExtResource("1_gblx7")] [node name="GatlingWeapon" instance=ExtResource("1_gblx7")]
script = ExtResource("1_kg6du") script = ExtResource("1_kg6du")
reloader = SubResource("Resource_oppha")
sector_angle = 5 sector_angle = 5
Projectile = ExtResource("2_ylc0n") Projectile = ExtResource("2_ylc0n")
reloaders = Array[ExtResource("3_uucc4")]([SubResource("Resource_kg6du")])
[node name="Sprite2D" type="Sprite2D" parent="." index="0"] [node name="Sprite2D" type="Sprite2D" parent="." index="0"]
texture = SubResource("PlaceholderTexture2D_dra6h") texture = SubResource("PlaceholderTexture2D_dra6h")
@@ -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://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="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://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"] [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"] [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dra6h"]
size = Vector2(10, 7) size = Vector2(10, 7)
@@ -157,7 +150,6 @@ animations = [{
script = ExtResource("2_lbdvb") script = ExtResource("2_lbdvb")
bullet_per_shot = 2 bullet_per_shot = 2
Projectile = ExtResource("2_fecho") Projectile = ExtResource("2_fecho")
reloaders = Array[ExtResource("3_c1wcw")]([SubResource("Resource_fecho")])
[node name="Sprite2D" type="Sprite2D" parent="." index="0"] [node name="Sprite2D" type="Sprite2D" parent="." index="0"]
texture = SubResource("PlaceholderTexture2D_dra6h") texture = SubResource("PlaceholderTexture2D_dra6h")
@@ -1 +1,42 @@
extends AbstractWeapon 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
+101 -12
View File
@@ -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="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="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="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="Texture2D" uid="uid://6hh66k8s4a1e" path="res://images/weapons.png" id="6_u6d2q"]
[ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_gpth1"]
[sub_resource type="Resource" id="Resource_yluvp"] [sub_resource type="AtlasTexture" id="AtlasTexture_vj3ee"]
script = ExtResource("4_gpth1") atlas = ExtResource("6_u6d2q")
firerate = 150 region = Rect2(0, 48, 32, 16)
metadata/_custom_type_script = "uid://b255rb32vc6co"
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dra6h"] [sub_resource type="AtlasTexture" id="AtlasTexture_u6d2q"]
size = Vector2(10, 7) 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")] [node name="PlasmaWeapon" instance=ExtResource("1_pkk8e")]
script = ExtResource("2_fnsb7") script = ExtResource("2_fnsb7")
sector_angle = 2 sector_angle = 2
Projectile = ExtResource("2_yluvp") Projectile = ExtResource("2_yluvp")
reloaders = Array[ExtResource("3_fnsb7")]([SubResource("Resource_yluvp")])
[node name="Sprite2D" type="Sprite2D" parent="." index="0"] [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0"]
texture = SubResource("PlaceholderTexture2D_dra6h") 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"]
@@ -14,7 +14,6 @@ func shoot(ship_velocity: Vector2) -> bool:
var is_shot := super.shoot(ship_velocity) var is_shot := super.shoot(ship_velocity)
if is_shot: if is_shot:
sprite.play(PREFIXES[_belonging] + SHOT_POSTFIX) sprite.play(PREFIXES[_belonging] + SHOT_POSTFIX)
print(1, sprite.animation)
_can_shoot = false _can_shoot = false
return is_shot return is_shot
@@ -23,9 +22,6 @@ func shoot(ship_velocity: Vector2) -> bool:
func _on_animated_sprite_2d_animation_finished() -> void: func _on_animated_sprite_2d_animation_finished() -> void:
if sprite.animation.ends_with(SHOT_POSTFIX): if sprite.animation.ends_with(SHOT_POSTFIX):
sprite.play(PREFIXES[_belonging] + RELOAD_POSTFIX) sprite.play(PREFIXES[_belonging] + RELOAD_POSTFIX)
print(PREFIXES[_belonging] + RELOAD_POSTFIX)
print(2, sprite.animation)
else: else:
sprite.play(PREFIXES[_belonging] + IDLE_POSTFIX) sprite.play(PREFIXES[_belonging] + IDLE_POSTFIX)
print(3, sprite.animation)
_can_shoot = true _can_shoot = true
-27
View File
@@ -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
-1
View File
@@ -1 +0,0 @@
uid://ccpriilfr3kme
-43
View File
@@ -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
-1
View File
@@ -1 +0,0 @@
uid://b255rb32vc6co
BIN
View File
Binary file not shown.
+8
View File
@@ -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