Added player weapons saving
This commit is contained in:
@@ -5,21 +5,17 @@ extends CharacterBody2D
|
||||
signal destroyed
|
||||
|
||||
|
||||
const CANNON = preload("res://game/entities/weapons/cannon/cannon_weapon.tscn")
|
||||
const GATLING = preload("res://game/entities/weapons/gatling/gatling_weapon.tscn")
|
||||
const LASER = preload("res://game/entities/weapons/laser/laser_weapon.tscn")
|
||||
const LAUNCHER = preload("res://game/entities/weapons/launcher/launcher_weapon.tscn")
|
||||
const MINELAYER = preload("res://game/entities/weapons/minelayer/minelayer_weapon.tscn")
|
||||
const PLASMA = preload("res://game/entities/weapons/plasma/plasma_weapon.tscn")
|
||||
const RAILGUN = preload("res://game/entities/weapons/railgun/railgun_weapon.tscn")
|
||||
const SHRAPNEL = preload("res://game/entities/weapons/shrapnel/shrapnel_weapon.tscn")
|
||||
const TESLA = preload("res://game/entities/weapons/tesla/tesla_weapon.tscn")
|
||||
|
||||
const WEAPONS := [
|
||||
CANNON, GATLING, LASER,
|
||||
LAUNCHER, MINELAYER, PLASMA,
|
||||
RAILGUN, SHRAPNEL, TESLA,
|
||||
]
|
||||
const WEAPON_SCENES : Dictionary[String, String] = {
|
||||
"cannon": "res://game/entities/weapons/cannon/cannon_weapon.tscn",
|
||||
"gatling": "res://game/entities/weapons/gatling/gatling_weapon.tscn",
|
||||
"laser": "res://game/entities/weapons/laser/laser_weapon.tscn",
|
||||
"launcher": "res://game/entities/weapons/launcher/launcher_weapon.tscn",
|
||||
"minelayer": "res://game/entities/weapons/minelayer/minelayer_weapon.tscn",
|
||||
"plasma": "res://game/entities/weapons/plasma/plasma_weapon.tscn",
|
||||
"railgun": "res://game/entities/weapons/railgun/railgun_weapon.tscn",
|
||||
"shrapnel": "res://game/entities/weapons/shrapnel/shrapnel_weapon.tscn",
|
||||
"tesla": "res://game/entities/weapons/tesla/tesla_weapon.tscn",
|
||||
}
|
||||
|
||||
const SHADER_INTENSITY = "shader_parameter/intensity"
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ var weapon_type : AbstractWeapon.Type = AbstractWeapon.Type.NONE
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
|
||||
var weapon_scene : PackedScene = WEAPONS.pick_random()
|
||||
var weapon_id : String = WEAPON_SCENES.keys().pick_random()
|
||||
var weapon_scene : PackedScene = load(WEAPON_SCENES[weapon_id])
|
||||
for weapon_position in weapon_positions:
|
||||
var weapon : AbstractWeapon = weapon_scene.instantiate()
|
||||
weapon_type = weapon.type
|
||||
|
||||
@@ -8,6 +8,8 @@ const BLINK_CHARGE_MAXIMUM = 3.0
|
||||
|
||||
|
||||
@export_range(0, 200) var blink_range := 0
|
||||
@export var player_data : PlayerData:
|
||||
set = _set_player_data
|
||||
|
||||
|
||||
var blink_charge: float:
|
||||
@@ -26,10 +28,6 @@ func _ready() -> void:
|
||||
|
||||
blink_charge_indicator.maximum = BLINK_CHARGE_MAXIMUM
|
||||
blink_charge = BLINK_CHARGE_MAXIMUM
|
||||
|
||||
for weapon_position in weapon_positions:
|
||||
var weapon : AbstractWeapon = WEAPONS.pick_random().instantiate()
|
||||
_add_weapon(weapon, weapon_position)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
@@ -62,3 +60,20 @@ func _blink(direction: Vector2) -> void:
|
||||
collision_mask &= ~ENEMY_LAYER
|
||||
move_and_collide(direction * blink_range)
|
||||
collision_mask |= ENEMY_LAYER
|
||||
|
||||
|
||||
func _set_player_data(new_data: PlayerData) -> void:
|
||||
if new_data == null: return
|
||||
|
||||
player_data = new_data
|
||||
_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])
|
||||
|
||||
|
||||
func _add_weapon_by_id(weapon_id: String, weapon_position: Vector2) -> void:
|
||||
if weapon_id.is_empty() or not weapon_id in WEAPON_SCENES: return
|
||||
|
||||
var weapon_scene : PackedScene = load(WEAPON_SCENES[weapon_id])
|
||||
var weapon : AbstractWeapon = weapon_scene.instantiate()
|
||||
_add_weapon(weapon, weapon_position)
|
||||
|
||||
+2
-1
@@ -85,7 +85,8 @@ func _create_passage(passage_data: PassageData) -> void:
|
||||
_current_passage_scene = PASSAGE.instantiate()
|
||||
add_child(_current_passage_scene)
|
||||
|
||||
_current_passage_scene.data = passage_data
|
||||
_current_passage_scene.passage_data = passage_data
|
||||
_current_passage_scene.player_data = SaveManager.player_data
|
||||
_current_passage_scene.completed.connect(_on_passage_completion)
|
||||
_current_passage_scene.player_died.connect(_on_passage_player_died)
|
||||
|
||||
|
||||
+17
-7
@@ -6,13 +6,17 @@ signal player_died
|
||||
signal completed
|
||||
|
||||
|
||||
@export var data : PassageData:
|
||||
set = _set_data
|
||||
@export var passage_data : PassageData:
|
||||
set = _set_passage_data
|
||||
|
||||
@export var player_data : PlayerData:
|
||||
set = _set_player_data
|
||||
|
||||
|
||||
var _current_progress := 0.0
|
||||
|
||||
|
||||
@onready var player : PlayerShip = $PlayerShip
|
||||
@onready var enemy_swamp_controller : EnemySwampController = $EnemySwampController
|
||||
@onready var enemy_timer : Timer = $EnemyTimer
|
||||
@onready var progress_bar : TextureProgressBar = $ProgressBar
|
||||
@@ -21,19 +25,25 @@ var _current_progress := 0.0
|
||||
func _physics_process(delta: float) -> void:
|
||||
_current_progress += delta
|
||||
_update_progress_indicator()
|
||||
if _current_progress >= data.length:
|
||||
if _current_progress >= passage_data.length:
|
||||
completed.emit()
|
||||
|
||||
|
||||
func _set_data(new_data: PassageData) -> void:
|
||||
data = new_data
|
||||
if data and progress_bar:
|
||||
func _set_passage_data(new_data: PassageData) -> void:
|
||||
passage_data = new_data
|
||||
if passage_data and progress_bar:
|
||||
_update_progress_indicator()
|
||||
|
||||
|
||||
func _set_player_data(new_data: PlayerData) -> void:
|
||||
player_data = new_data
|
||||
if passage_data and player:
|
||||
player.player_data = player_data
|
||||
|
||||
|
||||
func _update_progress_indicator() -> void:
|
||||
progress_bar.value = _current_progress
|
||||
progress_bar.max_value = data.length
|
||||
progress_bar.max_value = passage_data.length
|
||||
|
||||
|
||||
func _on_enemy_timer_timeout() -> void:
|
||||
|
||||
@@ -47,6 +47,7 @@ one_way_collision = true
|
||||
|
||||
[node name="PlayerShip" parent="." instance=ExtResource("3_r3x05")]
|
||||
position = Vector2(100, 100)
|
||||
player_data = null
|
||||
|
||||
[node name="EnemySwampController" parent="." node_paths=PackedStringArray("passage") instance=ExtResource("2_72vqi")]
|
||||
passage = NodePath("..")
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class_name PlayerData
|
||||
extends Resource
|
||||
|
||||
|
||||
@export var first_weapon_id: String
|
||||
@export var second_weapon_id: String
|
||||
@@ -0,0 +1 @@
|
||||
uid://bc5bi1nr7845m
|
||||
+45
-15
@@ -5,26 +5,33 @@ const SAVE_FILE = "user://save.bin"
|
||||
const SAVE_FILE_PASS = "save_file_data"
|
||||
|
||||
const CATEGORY_GAME = "game"
|
||||
const PARAMETER_GAME_SEED = "seed"
|
||||
const PARAMETER_GAME_AREA_INDEX = "current_area_index"
|
||||
const PARAMETER_GAME_STAGE_INDEX = "current_stage_index"
|
||||
const PARAMETER_GAME_SECTOR_INDEX = "current_sector_index"
|
||||
const GAME_SEED = "seed"
|
||||
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"
|
||||
|
||||
|
||||
var _save_file: ConfigFile
|
||||
|
||||
var game_data : GameData
|
||||
var player_data : PlayerData
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_save_file = ConfigFile.new()
|
||||
game_data = GameData.new()
|
||||
player_data = PlayerData.new()
|
||||
|
||||
_load()
|
||||
|
||||
|
||||
func save() -> void:
|
||||
_save_file.set_value(CATEGORY_GAME, PARAMETER_GAME_SEED, game_data.game_seed)
|
||||
_save_file.set_value(CATEGORY_GAME, PARAMETER_GAME_AREA_INDEX, game_data.current_area_index)
|
||||
_save_file.set_value(CATEGORY_GAME, PARAMETER_GAME_AREA_INDEX, game_data.current_stage_index)
|
||||
_save_file.set_value(CATEGORY_GAME, PARAMETER_GAME_AREA_INDEX, game_data.current_sector_index)
|
||||
_set_game_values()
|
||||
_set_player_values()
|
||||
|
||||
_save_file.save_encrypted_pass(SAVE_FILE, SAVE_FILE_PASS)
|
||||
|
||||
@@ -39,9 +46,6 @@ func delete_game_data() -> void:
|
||||
|
||||
|
||||
func _load() -> void:
|
||||
_save_file = ConfigFile.new()
|
||||
game_data = GameData.new()
|
||||
|
||||
if _save_file.load_encrypted_pass(SAVE_FILE, SAVE_FILE_PASS) == OK:
|
||||
_process_save_file()
|
||||
|
||||
@@ -49,15 +53,41 @@ func _load() -> void:
|
||||
|
||||
|
||||
func _process_save_file() -> void:
|
||||
_get_game_values()
|
||||
_get_player_values()
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
func _get_game_values() -> void:
|
||||
game_data.game_seed = _save_file.get_value(
|
||||
CATEGORY_GAME, PARAMETER_GAME_SEED, game_data.game_seed
|
||||
CATEGORY_GAME, GAME_SEED, game_data.game_seed
|
||||
)
|
||||
game_data.current_area_index = _save_file.get_value(
|
||||
CATEGORY_GAME, PARAMETER_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(
|
||||
CATEGORY_GAME, PARAMETER_GAME_AREA_INDEX, game_data.current_stage_index
|
||||
CATEGORY_GAME, GAME_AREA_INDEX, game_data.current_stage_index
|
||||
)
|
||||
game_data.current_sector_index = _save_file.get_value(
|
||||
CATEGORY_GAME, PARAMETER_GAME_AREA_INDEX, game_data.current_sector_index
|
||||
CATEGORY_GAME, GAME_AREA_INDEX, game_data.current_sector_index
|
||||
)
|
||||
|
||||
|
||||
func _get_player_values() -> void:
|
||||
player_data.first_weapon_id = _save_file.get_value(
|
||||
CATEGORY_PLAYER, PLAYER_FIRST_WEAPON, player_data.first_weapon_id
|
||||
)
|
||||
player_data.second_weapon_id = _save_file.get_value(
|
||||
CATEGORY_PLAYER, PLAYER_SECOND_WEAPON, player_data.second_weapon_id
|
||||
)
|
||||
|
||||
@@ -31,13 +31,13 @@ var window_factor : int:
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_config = ConfigFile.new()
|
||||
|
||||
_load_settings()
|
||||
_apply_all_settings()
|
||||
|
||||
|
||||
func _load_settings() -> void:
|
||||
_config = ConfigFile.new()
|
||||
|
||||
if _config.load(CONFIG_FILE) == OK:
|
||||
_fullscreen = _config.get_value(CATEGORY_VIDEO, SETTING_FULLSCREEN, false)
|
||||
_window_factor = _config.get_value(CATEGORY_VIDEO, SETTING_WINDOW_FACTOR, 0)
|
||||
|
||||
@@ -26,9 +26,17 @@ func _on_main_menu_continue_game() -> void:
|
||||
|
||||
func _on_main_menu_new_game() -> void:
|
||||
SaveManager.new_game()
|
||||
|
||||
SaveManager.player_data.first_weapon_id = _get_random_weapon_id()
|
||||
SaveManager.player_data.second_weapon_id = _get_random_weapon_id()
|
||||
|
||||
get_tree().change_scene_to_file("res://game/game.tscn")
|
||||
|
||||
|
||||
func _get_random_weapon_id() -> String:
|
||||
return AbstractShip.WEAPON_SCENES.keys().pick_random()
|
||||
|
||||
|
||||
func _on_main_menu_quit_game() -> void:
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user