Added player hull saving. Multiple fixes

This commit is contained in:
2025-12-13 22:42:40 +03:00
parent ab607c9e86
commit abb680ed53
11 changed files with 83 additions and 41 deletions
+4
View File
@@ -107,12 +107,16 @@ func _add_weapon(weapon: AbstractWeapon, weapon_position: Vector2) -> void:
func _on_shield_updated(value: int, max_value: int) -> void: func _on_shield_updated(value: int, max_value: int) -> void:
if shield_sprite == null: return
shield_sprite.visible = value != 0 shield_sprite.visible = value != 0
var intensity := value/float(max_value) if value != 0 else 0.0 var intensity := value/float(max_value) if value != 0 else 0.0
shield_sprite.material.set(SHADER_INTENSITY, intensity) shield_sprite.material.set(SHADER_INTENSITY, intensity)
func _on_armor_updated(value: int, max_value: int) -> void: func _on_armor_updated(value: int, max_value: int) -> void:
if armor_sprite == null: return
armor_sprite.visible = value != 0 armor_sprite.visible = value != 0
var intensity := value/float(max_value) if value != 0 else 0.0 var intensity := value/float(max_value) if value != 0 else 0.0
armor_sprite.material.set(SHADER_INTENSITY, intensity) armor_sprite.material.set(SHADER_INTENSITY, intensity)
+11
View File
@@ -69,6 +69,9 @@ func _set_player_data(new_data: PlayerData) -> void:
_weapons.clear() _weapons.clear()
_add_weapon_by_id(player_data.first_weapon_id, weapon_positions[0]) _add_weapon_by_id(player_data.first_weapon_id, weapon_positions[0])
_add_weapon_by_id(player_data.second_weapon_id, weapon_positions[1]) _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: 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_scene : PackedScene = load(WEAPON_SCENES[weapon_id])
var weapon : AbstractWeapon = weapon_scene.instantiate() var weapon : AbstractWeapon = weapon_scene.instantiate()
_add_weapon(weapon, weapon_position) _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
+19 -1
View File
@@ -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="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="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="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="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"] [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"] [sub_resource type="AtlasTexture" id="AtlasTexture_4mjo1"]
atlas = ExtResource("3_uf2n1") atlas = ExtResource("3_uf2n1")
region = Rect2(0, 0, 48, 32) 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"] [sub_resource type="AtlasTexture" id="AtlasTexture_uf2n1"]
atlas = ExtResource("3_uf2n1") atlas = ExtResource("3_uf2n1")
region = Rect2(0, 32, 48, 32) 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"] [sub_resource type="AtlasTexture" id="AtlasTexture_ui1ht"]
atlas = ExtResource("3_uf2n1") atlas = ExtResource("3_uf2n1")
region = Rect2(0, 64, 48, 32) region = Rect2(0, 64, 48, 32)
@@ -34,6 +49,7 @@ collision_layer = 3
collision_mask = 5 collision_mask = 5
script = ExtResource("2_625ti") script = ExtResource("2_625ti")
blink_range = 75 blink_range = 75
player_data = null
acceleration = 92 acceleration = 92
deceleration = 46 deceleration = 46
max_speed = 92 max_speed = 92
@@ -43,9 +59,11 @@ mass = 250
texture = SubResource("AtlasTexture_4mjo1") texture = SubResource("AtlasTexture_4mjo1")
[node name="ArmorSprite" parent="." index="1"] [node name="ArmorSprite" parent="." index="1"]
material = SubResource("ShaderMaterial_waejo")
texture = SubResource("AtlasTexture_uf2n1") texture = SubResource("AtlasTexture_uf2n1")
[node name="ShieldSprite" parent="." index="2"] [node name="ShieldSprite" parent="." index="2"]
material = SubResource("ShaderMaterial_5xifi")
texture = SubResource("AtlasTexture_ui1ht") texture = SubResource("AtlasTexture_ui1ht")
[node name="CollisionPolygon2D" parent="." index="3"] [node name="CollisionPolygon2D" parent="." index="3"]
@@ -4,7 +4,7 @@
[sub_resource type="CircleShape2D" id="CircleShape2D_4b2nh"] [sub_resource type="CircleShape2D" id="CircleShape2D_4b2nh"]
[node name="AbstrastProjectile" type="Area2D"] [node name="AbstrastProjectile" type="Area2D" groups=["projectiles"]]
z_index = 1 z_index = 1
script = ExtResource("1_4b2nh") script = ExtResource("1_4b2nh")
@@ -160,7 +160,7 @@ fixed_fps = 10
process_material = SubResource("ParticleProcessMaterial_ifsj2") process_material = SubResource("ParticleProcessMaterial_ifsj2")
[node name="CooldownTimer" type="Timer" parent="." index="2"] [node name="CooldownTimer" type="Timer" parent="." index="2"]
wait_time = 1.3 wait_time = 2.0
one_shot = true one_shot = true
[connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"] [connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"]
+4
View File
@@ -111,6 +111,10 @@ func _on_passage_player_died() -> void:
func _on_passage_completion() -> 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 current_sector = current_passage.next_sector
_update_data_indexes() _update_data_indexes()
_show_map() _show_map()
+27 -31
View File
@@ -12,65 +12,61 @@ signal depleted
@export_range(0, 5000) var max_shield: int = 0: @export_range(0, 5000) var max_shield: int = 0:
set(value): set(value):
max_shield = 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: @export_range(0, 5000) var max_armor: int = 0:
set(value): set(value):
max_armor = 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: @export_range(1, 5000) var max_hull: int = 1:
set(value): set(value):
max_hull = value max_hull = value
hull_updated.emit(_hull, max_hull) hull_updated.emit(hull, max_hull)
var shield: int: var shield: int:
get: return _shield set(value):
set(value): pass shield = value
shield_updated.emit(shield, max_shield)
var armor: int: var armor: int:
get: return _armor set(value):
set(value): pass armor = value
armor_updated.emit(armor, max_armor)
var hull: int: var hull: int:
get: return _hull set(value):
set(value): pass hull = value
hull_updated.emit(hull, max_hull)
@onready var shield_regen_delay_timer : Timer = $ShieldRegenDelayTimer @onready var shield_regen_delay_timer : Timer = $ShieldRegenDelayTimer
@onready var shield_regen_tick_timer : Timer = $ShieldRegenTickTimer @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) @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: func apply_damage(damage: AbstractDamage) -> void:
if _shield > 0: if shield > 0:
var damage_value := ceili(damage.value * damage.shield_damage_multiplier()) 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() shield_regen_delay_timer.start()
elif _armor > 0: elif armor > 0:
var damage_value := ceili(damage.value * damage.armor_damage_multiplier()) var damage_value := ceili(damage.value * damage.armor_damage_multiplier())
_armor = max(_armor - damage_value, 0) armor = max(armor - damage_value, 0)
else: else:
if _hull == 0: return if hull == 0: return
var damage_value := ceili(damage.value * damage.hull_damage_multiplier()) 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() depleted.emit()
if not shield_regen_delay_timer.is_stopped(): 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: 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: if new_shield_value >= max_shield:
new_shield_value = max_shield new_shield_value = max_shield
shield_regen_tick_timer.stop() shield_regen_tick_timer.stop()
_shield = new_shield_value shield = new_shield_value
+2
View File
@@ -4,3 +4,5 @@ extends Resource
@export var first_weapon_id: String @export var first_weapon_id: String
@export var second_weapon_id: String @export var second_weapon_id: String
@export var hull: int
+12 -7
View File
@@ -10,9 +10,10 @@ const GAME_AREA_INDEX = "current_area_index"
const GAME_STAGE_INDEX = "current_stage_index" const GAME_STAGE_INDEX = "current_stage_index"
const GAME_SECTOR_INDEX = "current_sector_index" const GAME_SECTOR_INDEX = "current_sector_index"
const CATEGORY_PLAYER = "game" const CATEGORY_PLAYER = "player"
const PLAYER_FIRST_WEAPON = "player_first_weapon_id" const PLAYER_FIRST_WEAPON = "first_weapon_id"
const PLAYER_SECOND_WEAPON = "player_second_weapon_id" const PLAYER_SECOND_WEAPON = "second_weapon_id"
const PLAYER_HULL = "hull"
var _save_file: ConfigFile var _save_file: ConfigFile
@@ -60,13 +61,14 @@ func _process_save_file() -> void:
func _set_game_values() -> 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_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_area_index)
_save_file.set_value(CATEGORY_GAME, GAME_AREA_INDEX, game_data.current_stage_index) _save_file.set_value(CATEGORY_GAME, GAME_STAGE_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_SECTOR_INDEX, game_data.current_sector_index)
func _set_player_values() -> void: 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_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_SECOND_WEAPON, player_data.second_weapon_id)
_save_file.set_value(CATEGORY_PLAYER, PLAYER_HULL, player_data.hull)
func _get_game_values() -> void: func _get_game_values() -> void:
@@ -77,10 +79,10 @@ func _get_game_values() -> void:
CATEGORY_GAME, GAME_AREA_INDEX, game_data.current_area_index CATEGORY_GAME, GAME_AREA_INDEX, game_data.current_area_index
) )
game_data.current_stage_index = _save_file.get_value( 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( 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( player_data.second_weapon_id = _save_file.get_value(
CATEGORY_PLAYER, PLAYER_SECOND_WEAPON, player_data.second_weapon_id CATEGORY_PLAYER, PLAYER_SECOND_WEAPON, player_data.second_weapon_id
) )
player_data.hull = _save_file.get_value(
CATEGORY_PLAYER, PLAYER_HULL, player_data.hull
)
+1
View File
@@ -29,6 +29,7 @@ func _on_main_menu_new_game() -> void:
SaveManager.player_data.first_weapon_id = _get_random_weapon_id() SaveManager.player_data.first_weapon_id = _get_random_weapon_id()
SaveManager.player_data.second_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") get_tree().change_scene_to_file("res://game/game.tscn")
+1
View File
@@ -39,6 +39,7 @@ window/stretch/scale_mode="integer"
enemies="" enemies=""
players="" players=""
projectiles=""
[input] [input]