Reworked weapons and projectiles
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
extends Node
|
||||
|
||||
|
||||
const WEAPONS : Array[WeaponData] = [
|
||||
preload("res://game/data/weapons/cannon_data.tres"),
|
||||
preload("res://game/data/weapons/gatling_data.tres"),
|
||||
preload("res://game/data/weapons/laser_data.tres"),
|
||||
preload("res://game/data/weapons/launcher_data.tres"),
|
||||
preload("res://game/data/weapons/minelayer_data.tres"),
|
||||
preload("res://game/data/weapons/plasma_data.tres"),
|
||||
preload("res://game/data/weapons/railgun_data.tres"),
|
||||
preload("res://game/data/weapons/shrapnel_data.tres"),
|
||||
preload("res://game/data/weapons/tesla_data.tres"),
|
||||
]
|
||||
|
||||
const SAVE_FILE = "user://save.bin"
|
||||
const SAVE_FILE_PASS = "save_file_data"
|
||||
|
||||
const CATEGORY_GAME = "game"
|
||||
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 = "player"
|
||||
const PLAYER_WEAPONS = "weapon_ids"
|
||||
const PLAYER_HULL = "hull"
|
||||
|
||||
|
||||
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()
|
||||
|
||||
|
||||
static func get_weapon_data(weapon_id: String) -> WeaponData:
|
||||
for weapon in WEAPONS:
|
||||
if weapon.id == weapon_id:
|
||||
return weapon
|
||||
|
||||
return null
|
||||
|
||||
|
||||
func save() -> void:
|
||||
_set_game_values()
|
||||
_set_player_values()
|
||||
|
||||
_save_file.save_encrypted_pass(SAVE_FILE, SAVE_FILE_PASS)
|
||||
|
||||
|
||||
func new_game(game_seed: String) -> void:
|
||||
game_data.reset()
|
||||
player_data.reset()
|
||||
game_data.game_seed = game_seed
|
||||
|
||||
|
||||
func delete_game_data() -> void:
|
||||
game_data = GameData.new()
|
||||
save()
|
||||
|
||||
|
||||
func _load() -> void:
|
||||
if _save_file.load_encrypted_pass(SAVE_FILE, SAVE_FILE_PASS) == OK:
|
||||
_process_save_file()
|
||||
|
||||
save()
|
||||
|
||||
|
||||
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_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:
|
||||
var weapon_ids : Array[String] = []
|
||||
for weapon in player_data.weapons:
|
||||
weapon_ids.append(weapon.id)
|
||||
|
||||
|
||||
_save_file.set_value(CATEGORY_PLAYER, PLAYER_WEAPONS, weapon_ids)
|
||||
_save_file.set_value(CATEGORY_PLAYER, PLAYER_HULL, player_data.hull)
|
||||
|
||||
|
||||
func _get_game_values() -> void:
|
||||
game_data.game_seed = _save_file.get_value(
|
||||
CATEGORY_GAME, GAME_SEED, game_data.game_seed
|
||||
)
|
||||
game_data.current_area_index = _save_file.get_value(
|
||||
CATEGORY_GAME, GAME_AREA_INDEX, game_data.current_area_index
|
||||
)
|
||||
game_data.current_stage_index = _save_file.get_value(
|
||||
CATEGORY_GAME, GAME_STAGE_INDEX, game_data.current_stage_index
|
||||
)
|
||||
game_data.current_sector_index = _save_file.get_value(
|
||||
CATEGORY_GAME, GAME_SECTOR_INDEX, game_data.current_sector_index
|
||||
)
|
||||
|
||||
|
||||
func _get_player_values() -> void:
|
||||
var weapon_ids : Array[String] = _save_file.get_value(
|
||||
CATEGORY_PLAYER, PLAYER_WEAPONS, []
|
||||
)
|
||||
for weapon_id in weapon_ids:
|
||||
var weapon := get_weapon_data(weapon_id)
|
||||
if weapon != null:
|
||||
player_data.weapons.append(weapon)
|
||||
|
||||
player_data.hull = _save_file.get_value(
|
||||
CATEGORY_PLAYER, PLAYER_HULL, player_data.hull
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
uid://calwg6oh6lv0r
|
||||
@@ -0,0 +1,105 @@
|
||||
extends Node
|
||||
|
||||
|
||||
const CONFIG_FILE = "user://settings.cfg"
|
||||
const BASE_SIZE = Vector2i(640, 360)
|
||||
|
||||
const CATEGORY_VIDEO = "video"
|
||||
const SETTING_FULLSCREEN = "fullscreen"
|
||||
const SETTING_WINDOW_FACTOR = "window_factor"
|
||||
|
||||
|
||||
var _config: ConfigFile
|
||||
|
||||
var _fullscreen := false
|
||||
var fullscreen : bool:
|
||||
get:
|
||||
return _fullscreen
|
||||
set(value):
|
||||
_fullscreen = value
|
||||
_apply_video_settings()
|
||||
_save_settings()
|
||||
|
||||
var _window_factor := 0
|
||||
var window_factor : int:
|
||||
get:
|
||||
return _window_factor
|
||||
set(value):
|
||||
_window_factor = value
|
||||
_apply_video_settings()
|
||||
_save_settings()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_config = ConfigFile.new()
|
||||
|
||||
_load_settings()
|
||||
_apply_all_settings()
|
||||
|
||||
|
||||
func _load_settings() -> void:
|
||||
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)
|
||||
|
||||
_save_settings()
|
||||
|
||||
|
||||
func _save_settings() -> void:
|
||||
if _config == null:
|
||||
_config = ConfigFile.new()
|
||||
|
||||
_config.set_value(CATEGORY_VIDEO, SETTING_FULLSCREEN, _fullscreen)
|
||||
_config.set_value(CATEGORY_VIDEO, SETTING_WINDOW_FACTOR, _window_factor)
|
||||
|
||||
_config.save(CONFIG_FILE)
|
||||
|
||||
|
||||
func _apply_all_settings() -> void:
|
||||
_apply_video_settings()
|
||||
|
||||
|
||||
func _apply_video_settings() -> void:
|
||||
if _fullscreen:
|
||||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
|
||||
else:
|
||||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
|
||||
_apply_window_scale()
|
||||
|
||||
|
||||
func _apply_window_scale() -> void:
|
||||
if _fullscreen: return
|
||||
|
||||
var factors := [1, 2, 3, 4, 5, 6]
|
||||
|
||||
var factor_index := _window_factor
|
||||
if factor_index >= factors.size():
|
||||
factor_index = 0
|
||||
|
||||
var scale : int = factors[factor_index]
|
||||
var new_size := BASE_SIZE * scale
|
||||
|
||||
var current_position := DisplayServer.window_get_position()
|
||||
var current_size := DisplayServer.window_get_size()
|
||||
|
||||
var current_center := current_position + current_size / 2
|
||||
var new_position := current_center - new_size / 2
|
||||
|
||||
DisplayServer.window_set_size(new_size)
|
||||
DisplayServer.window_set_position(new_position)
|
||||
|
||||
_ensure_window_on_screen()
|
||||
|
||||
|
||||
func _ensure_window_on_screen() -> void:
|
||||
if _fullscreen: return
|
||||
|
||||
var window_position := DisplayServer.window_get_position()
|
||||
var window_size := DisplayServer.window_get_size()
|
||||
var screen_size := DisplayServer.screen_get_size()
|
||||
|
||||
var new_x : int = clamp(window_position.x, 0, screen_size.x - window_size.x)
|
||||
var new_y : int = clamp(window_position.y, 0, screen_size.y - window_size.y)
|
||||
|
||||
if new_x != window_position.x or new_y != window_position.y:
|
||||
DisplayServer.window_set_position(Vector2i(new_x, new_y))
|
||||
@@ -0,0 +1 @@
|
||||
uid://d2k5y0xd4hl22
|
||||
Reference in New Issue
Block a user