From abb680ed53071d69b7bace5e948f5ed35d397c0a Mon Sep 17 00:00:00 2001 From: Ruslan Ignatov Date: Sat, 13 Dec 2025 22:42:40 +0300 Subject: [PATCH] Added player hull saving. Multiple fixes --- game/entities/ships/abstract_ship.gd | 4 ++ game/entities/ships/player/player_ship.gd | 11 ++++ game/entities/ships/player/player_ship.tscn | 20 ++++++- .../entities/weapons/abstract_projectile.tscn | 2 +- game/entities/weapons/tesla/tesla_weapon.tscn | 2 +- game/game.gd | 4 ++ game/health_system/health.gd | 58 +++++++++---------- game/world/data/player_data.gd | 2 + managers/save_manager.gd | 19 +++--- menu/title_screen.gd | 1 + project.godot | 1 + 11 files changed, 83 insertions(+), 41 deletions(-) diff --git a/game/entities/ships/abstract_ship.gd b/game/entities/ships/abstract_ship.gd index d1231f3..269bda3 100644 --- a/game/entities/ships/abstract_ship.gd +++ b/game/entities/ships/abstract_ship.gd @@ -107,12 +107,16 @@ func _add_weapon(weapon: AbstractWeapon, weapon_position: Vector2) -> void: func _on_shield_updated(value: int, max_value: int) -> void: + if shield_sprite == null: return + shield_sprite.visible = value != 0 var intensity := value/float(max_value) if value != 0 else 0.0 shield_sprite.material.set(SHADER_INTENSITY, intensity) func _on_armor_updated(value: int, max_value: int) -> void: + if armor_sprite == null: return + armor_sprite.visible = value != 0 var intensity := value/float(max_value) if value != 0 else 0.0 armor_sprite.material.set(SHADER_INTENSITY, intensity) diff --git a/game/entities/ships/player/player_ship.gd b/game/entities/ships/player/player_ship.gd index 8e65ac1..90c995c 100644 --- a/game/entities/ships/player/player_ship.gd +++ b/game/entities/ships/player/player_ship.gd @@ -69,6 +69,9 @@ func _set_player_data(new_data: PlayerData) -> void: _weapons.clear() _add_weapon_by_id(player_data.first_weapon_id, weapon_positions[0]) _add_weapon_by_id(player_data.second_weapon_id, weapon_positions[1]) + + if player_data.hull > 0: + health.hull = mini(player_data.hull, health.max_hull) func _add_weapon_by_id(weapon_id: String, weapon_position: Vector2) -> void: @@ -77,3 +80,11 @@ func _add_weapon_by_id(weapon_id: String, weapon_position: Vector2) -> void: var weapon_scene : PackedScene = load(WEAPON_SCENES[weapon_id]) var weapon : AbstractWeapon = weapon_scene.instantiate() _add_weapon(weapon, weapon_position) + + +func _on_hull_updated(value: int, max_value: int) -> void: + super._on_hull_updated(value, max_value) + + if player_data == null: return + + player_data.hull = value diff --git a/game/entities/ships/player/player_ship.tscn b/game/entities/ships/player/player_ship.tscn index 0259e9a..005b9b8 100644 --- a/game/entities/ships/player/player_ship.tscn +++ b/game/entities/ships/player/player_ship.tscn @@ -1,19 +1,34 @@ -[gd_scene load_steps=11 format=3 uid="uid://br074cqcnul3d"] +[gd_scene load_steps=14 format=3 uid="uid://br074cqcnul3d"] [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"] [ext_resource type="Texture2D" uid="uid://y2yfli24n51v" path="res://images/ships/player.png" id="3_uf2n1"] +[ext_resource type="Shader" uid="uid://dwh22f35u5qqi" path="res://game/entities/ships/shield.gdshader" id="4_ui1ht"] [ext_resource type="PackedScene" uid="uid://d20nvskf38vpo" path="res://game/entities/ships/player/blink_charge_indicator.tscn" id="5_uf2n1"] [sub_resource type="AtlasTexture" id="AtlasTexture_4mjo1"] atlas = ExtResource("3_uf2n1") region = Rect2(0, 0, 48, 32) +[sub_resource type="ShaderMaterial" id="ShaderMaterial_waejo"] +resource_local_to_scene = true +shader = ExtResource("4_ui1ht") +shader_parameter/speed = 0.0 +shader_parameter/scale = 20.0 +shader_parameter/intensity = 1.0 + [sub_resource type="AtlasTexture" id="AtlasTexture_uf2n1"] atlas = ExtResource("3_uf2n1") region = Rect2(0, 32, 48, 32) +[sub_resource type="ShaderMaterial" id="ShaderMaterial_5xifi"] +resource_local_to_scene = true +shader = ExtResource("4_ui1ht") +shader_parameter/speed = 5.0 +shader_parameter/scale = 20.0 +shader_parameter/intensity = 1.0 + [sub_resource type="AtlasTexture" id="AtlasTexture_ui1ht"] atlas = ExtResource("3_uf2n1") region = Rect2(0, 64, 48, 32) @@ -34,6 +49,7 @@ collision_layer = 3 collision_mask = 5 script = ExtResource("2_625ti") blink_range = 75 +player_data = null acceleration = 92 deceleration = 46 max_speed = 92 @@ -43,9 +59,11 @@ mass = 250 texture = SubResource("AtlasTexture_4mjo1") [node name="ArmorSprite" parent="." index="1"] +material = SubResource("ShaderMaterial_waejo") texture = SubResource("AtlasTexture_uf2n1") [node name="ShieldSprite" parent="." index="2"] +material = SubResource("ShaderMaterial_5xifi") texture = SubResource("AtlasTexture_ui1ht") [node name="CollisionPolygon2D" parent="." index="3"] diff --git a/game/entities/weapons/abstract_projectile.tscn b/game/entities/weapons/abstract_projectile.tscn index 789d480..2a14e35 100644 --- a/game/entities/weapons/abstract_projectile.tscn +++ b/game/entities/weapons/abstract_projectile.tscn @@ -4,7 +4,7 @@ [sub_resource type="CircleShape2D" id="CircleShape2D_4b2nh"] -[node name="AbstrastProjectile" type="Area2D"] +[node name="AbstrastProjectile" type="Area2D" groups=["projectiles"]] z_index = 1 script = ExtResource("1_4b2nh") diff --git a/game/entities/weapons/tesla/tesla_weapon.tscn b/game/entities/weapons/tesla/tesla_weapon.tscn index 4fa55b1..e53ea55 100644 --- a/game/entities/weapons/tesla/tesla_weapon.tscn +++ b/game/entities/weapons/tesla/tesla_weapon.tscn @@ -160,7 +160,7 @@ fixed_fps = 10 process_material = SubResource("ParticleProcessMaterial_ifsj2") [node name="CooldownTimer" type="Timer" parent="." index="2"] -wait_time = 1.3 +wait_time = 2.0 one_shot = true [connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"] diff --git a/game/game.gd b/game/game.gd index 80b56e5..82ff4e3 100644 --- a/game/game.gd +++ b/game/game.gd @@ -111,6 +111,10 @@ func _on_passage_player_died() -> void: func _on_passage_completion() -> void: + var projectiles := get_tree().get_nodes_in_group("projectiles") + for projectile in projectiles: + projectile.queue_free() + current_sector = current_passage.next_sector _update_data_indexes() _show_map() diff --git a/game/health_system/health.gd b/game/health_system/health.gd index 00f6979..8ce26cb 100644 --- a/game/health_system/health.gd +++ b/game/health_system/health.gd @@ -12,65 +12,61 @@ signal depleted @export_range(0, 5000) var max_shield: int = 0: set(value): max_shield = value - shield_updated.emit(_shield, max_shield) + shield_updated.emit(shield, max_shield) @export_range(0, 5000) var max_armor: int = 0: set(value): max_armor = value - armor_updated.emit(_armor, max_armor) + armor_updated.emit(armor, max_armor) @export_range(1, 5000) var max_hull: int = 1: set(value): max_hull = value - hull_updated.emit(_hull, max_hull) + hull_updated.emit(hull, max_hull) var shield: int: - get: return _shield - set(value): pass + set(value): + shield = value + shield_updated.emit(shield, max_shield) var armor: int: - get: return _armor - set(value): pass + set(value): + armor = value + armor_updated.emit(armor, max_armor) var hull: int: - get: return _hull - set(value): pass + set(value): + hull = value + hull_updated.emit(hull, max_hull) @onready var shield_regen_delay_timer : Timer = $ShieldRegenDelayTimer @onready var shield_regen_tick_timer : Timer = $ShieldRegenTickTimer -@onready var _shield := max_shield: - set(value): - _shield = value - shield_updated.emit(_shield, max_shield) -@onready var _armor := max_armor: - set(value): - _armor = value - armor_updated.emit(_armor, max_armor) -@onready var _hull := max_hull: - set(value): - _hull = value - hull_updated.emit(_hull, max_hull) - @onready var _shield_regen := floori(max_shield/30.0) +func _ready() -> void: + shield = max_shield + armor = max_armor + hull = max_hull + + func apply_damage(damage: AbstractDamage) -> void: - if _shield > 0: + if shield > 0: var damage_value := ceili(damage.value * damage.shield_damage_multiplier()) - _shield = max(_shield - damage_value, 0) + shield = max(shield - damage_value, 0) shield_regen_delay_timer.start() - elif _armor > 0: + elif armor > 0: var damage_value := ceili(damage.value * damage.armor_damage_multiplier()) - _armor = max(_armor - damage_value, 0) + armor = max(armor - damage_value, 0) else: - if _hull == 0: return + if hull == 0: return var damage_value := ceili(damage.value * damage.hull_damage_multiplier()) - _hull = max(_hull - damage_value, 0) + hull = max(hull - damage_value, 0) - if _hull == 0: + if hull == 0: depleted.emit() if not shield_regen_delay_timer.is_stopped(): @@ -83,8 +79,8 @@ func _on_shield_regen_delay_timer_timeout() -> void: func _on_shield_regen_tick_timer_timeout() -> void: - var new_shield_value := _shield + _shield_regen + var new_shield_value := shield + _shield_regen if new_shield_value >= max_shield: new_shield_value = max_shield shield_regen_tick_timer.stop() - _shield = new_shield_value + shield = new_shield_value diff --git a/game/world/data/player_data.gd b/game/world/data/player_data.gd index 4104a73..c8caa9a 100644 --- a/game/world/data/player_data.gd +++ b/game/world/data/player_data.gd @@ -4,3 +4,5 @@ extends Resource @export var first_weapon_id: String @export var second_weapon_id: String + +@export var hull: int diff --git a/managers/save_manager.gd b/managers/save_manager.gd index a2f3e79..cb0dca1 100644 --- a/managers/save_manager.gd +++ b/managers/save_manager.gd @@ -10,9 +10,10 @@ const GAME_AREA_INDEX = "current_area_index" const GAME_STAGE_INDEX = "current_stage_index" const GAME_SECTOR_INDEX = "current_sector_index" -const CATEGORY_PLAYER = "game" -const PLAYER_FIRST_WEAPON = "player_first_weapon_id" -const PLAYER_SECOND_WEAPON = "player_second_weapon_id" +const CATEGORY_PLAYER = "player" +const PLAYER_FIRST_WEAPON = "first_weapon_id" +const PLAYER_SECOND_WEAPON = "second_weapon_id" +const PLAYER_HULL = "hull" var _save_file: ConfigFile @@ -60,13 +61,14 @@ func _process_save_file() -> void: func _set_game_values() -> void: _save_file.set_value(CATEGORY_GAME, GAME_SEED, game_data.game_seed) _save_file.set_value(CATEGORY_GAME, GAME_AREA_INDEX, game_data.current_area_index) - _save_file.set_value(CATEGORY_GAME, GAME_AREA_INDEX, game_data.current_stage_index) - _save_file.set_value(CATEGORY_GAME, GAME_AREA_INDEX, game_data.current_sector_index) + _save_file.set_value(CATEGORY_GAME, GAME_STAGE_INDEX, game_data.current_stage_index) + _save_file.set_value(CATEGORY_GAME, GAME_SECTOR_INDEX, game_data.current_sector_index) func _set_player_values() -> void: _save_file.set_value(CATEGORY_PLAYER, PLAYER_FIRST_WEAPON, player_data.first_weapon_id) _save_file.set_value(CATEGORY_PLAYER, PLAYER_SECOND_WEAPON, player_data.second_weapon_id) + _save_file.set_value(CATEGORY_PLAYER, PLAYER_HULL, player_data.hull) func _get_game_values() -> void: @@ -77,10 +79,10 @@ func _get_game_values() -> void: CATEGORY_GAME, GAME_AREA_INDEX, game_data.current_area_index ) game_data.current_stage_index = _save_file.get_value( - CATEGORY_GAME, GAME_AREA_INDEX, game_data.current_stage_index + CATEGORY_GAME, GAME_STAGE_INDEX, game_data.current_stage_index ) game_data.current_sector_index = _save_file.get_value( - CATEGORY_GAME, GAME_AREA_INDEX, game_data.current_sector_index + CATEGORY_GAME, GAME_SECTOR_INDEX, game_data.current_sector_index ) @@ -91,3 +93,6 @@ func _get_player_values() -> void: player_data.second_weapon_id = _save_file.get_value( CATEGORY_PLAYER, PLAYER_SECOND_WEAPON, player_data.second_weapon_id ) + player_data.hull = _save_file.get_value( + CATEGORY_PLAYER, PLAYER_HULL, player_data.hull + ) diff --git a/menu/title_screen.gd b/menu/title_screen.gd index d3bfce9..0214c5b 100644 --- a/menu/title_screen.gd +++ b/menu/title_screen.gd @@ -29,6 +29,7 @@ func _on_main_menu_new_game() -> void: SaveManager.player_data.first_weapon_id = _get_random_weapon_id() SaveManager.player_data.second_weapon_id = _get_random_weapon_id() + SaveManager.player_data.hull = 0 get_tree().change_scene_to_file("res://game/game.tscn") diff --git a/project.godot b/project.godot index a9c951c..c03fcfe 100644 --- a/project.godot +++ b/project.godot @@ -39,6 +39,7 @@ window/stretch/scale_mode="integer" enemies="" players="" +projectiles="" [input]