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)
|
||||
|
||||
Reference in New Issue
Block a user