PlayerInfo and playerE cleanup
This commit is contained in:
parent
ed9909ed7e
commit
d8a5107739
|
|
@ -1,13 +1,8 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
## PlayerInfo
|
||||||
|
# Tracks player info for other nodes
|
||||||
# Declare member variables here. Examples:
|
# and UI elements.
|
||||||
# var a = 2
|
# Manages PlayerData objects for inventory and maybe saving later.
|
||||||
# var b = "text"
|
|
||||||
var player_position: Vector2
|
|
||||||
var player_health: int
|
|
||||||
var player_stamina: int
|
|
||||||
var player_inventory: InventoryManager
|
|
||||||
|
|
||||||
## An array of player data objects
|
## An array of player data objects
|
||||||
var _player_data :Array = []
|
var _player_data :Array = []
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,12 @@ extends Actor
|
||||||
|
|
||||||
export var player_number: int = 1
|
export var player_number: int = 1
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
|
||||||
# var a = 2
|
|
||||||
# var b = "text"
|
|
||||||
|
|
||||||
onready var player_inventory :InventoryManager = InventoryManager.new()
|
onready var player_inventory :InventoryManager = InventoryManager.new()
|
||||||
onready var stamina_component = $"%Stamina_Component"
|
onready var stamina_component = $"%Stamina_Component"
|
||||||
onready var health_component = $"%Health_Component"
|
onready var health_component = $"%Health_Component"
|
||||||
|
|
||||||
var punch_item :Item = preload("res://assets/items/punch.tres")
|
|
||||||
|
|
||||||
const state_stamina_cost :Dictionary = {
|
const state_stamina_cost :Dictionary = {
|
||||||
"jump": 10,
|
"jump": 10,
|
||||||
|
|
@ -25,16 +22,19 @@ const state_damage_amount :Dictionary = {
|
||||||
"attack_punch":10,
|
"attack_punch":10,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const state_to_item_map :Dictionary = {
|
||||||
|
"sword": "attack_sword" ,
|
||||||
|
"gun": "attack_shoot",
|
||||||
|
"punch" : "attack_punch",
|
||||||
|
"mushroom" : "attack_shoot"
|
||||||
|
}
|
||||||
|
|
||||||
var player_info_index :int
|
var player_info_index :int
|
||||||
var player_data :PlayerData
|
var player_data :PlayerData
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
# PlayerInfo.player_health = health_component.health
|
|
||||||
PlayerInfo.player_inventory = player_inventory
|
|
||||||
# PlayerInfo.player_stamina = stamina_component.stamina
|
|
||||||
|
|
||||||
# I think we only want to do this for network master players now
|
# I think we only want to do this for network master players now
|
||||||
if is_network_master():
|
if is_network_master():
|
||||||
player_info_index = PlayerInfo.register_player()
|
player_info_index = PlayerInfo.register_player()
|
||||||
|
|
@ -50,6 +50,8 @@ func _ready():
|
||||||
# Set initial player position in world.
|
# Set initial player position in world.
|
||||||
global_position = LevelInfo.player_start_position
|
global_position = LevelInfo.player_start_position
|
||||||
|
|
||||||
|
## Give player punch ability at start.
|
||||||
|
var punch_item :Item = preload("res://assets/items/punch.tres")
|
||||||
player_inventory.add_to_inventory(punch_item)
|
player_inventory.add_to_inventory(punch_item)
|
||||||
player_inventory.select_primary(punch_item)
|
player_inventory.select_primary(punch_item)
|
||||||
|
|
||||||
|
|
@ -60,15 +62,8 @@ func _ready():
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if is_network_master():
|
if is_network_master():
|
||||||
#PlayerInfo.player_position = global_position.round()
|
## Update position and stamina in player data
|
||||||
player_data.player_position = global_position.round()
|
player_data.player_position = global_position.round()
|
||||||
# stamina_recovery += delta
|
|
||||||
# if stamina_recovery > 1.0:
|
|
||||||
# stamina_component.recover(1)
|
|
||||||
# stamina_recovery = 0.0
|
|
||||||
# #print("recover ", stamina_component.stamina)
|
|
||||||
|
|
||||||
#PlayerInfo.player_stamina = stamina_component.stamina
|
|
||||||
player_data.player_stamina = stamina_component.stamina
|
player_data.player_stamina = stamina_component.stamina
|
||||||
|
|
||||||
##TODO: well I'm not sure I like this but making a whole state receiver is silly
|
##TODO: well I'm not sure I like this but making a whole state receiver is silly
|
||||||
|
|
@ -134,20 +129,10 @@ func enough_stamina_for(_state_name :String) -> bool:
|
||||||
## Return true by default because we don't have a cost for this move
|
## Return true by default because we don't have a cost for this move
|
||||||
return true
|
return true
|
||||||
|
|
||||||
var state_to_item_map :Dictionary = {
|
|
||||||
"sword": "attack_sword" ,
|
|
||||||
"gun": "attack_shoot",
|
|
||||||
"punch" : "attack_punch",
|
|
||||||
"mushroom" : "attack_shoot"
|
|
||||||
}
|
|
||||||
|
|
||||||
##TODO: We need to find a way to 'use' the item.
|
##TODO: We need to find a way to 'use' the item.
|
||||||
func use_primary_item() -> String:
|
func use_primary_item() -> String:
|
||||||
# if player_inventory.primary_selection.consumable == false:
|
|
||||||
# if state_to_item_map.has(player_inventory.primary_selection.name):
|
|
||||||
# player_inventory.remove_from_inventory(player_inventory.primary_selection)
|
|
||||||
# return state_to_item_map[player_inventory.primary_selection.name]
|
|
||||||
|
|
||||||
if player_inventory.primary_selection != null: # Have to make sure we even have a second
|
if player_inventory.primary_selection != null: # Have to make sure we even have a second
|
||||||
var _item_name :String = player_inventory.primary_selection.name
|
var _item_name :String = player_inventory.primary_selection.name
|
||||||
if state_to_item_map.has(_item_name):
|
if state_to_item_map.has(_item_name):
|
||||||
|
|
@ -161,6 +146,7 @@ func use_primary_item() -> String:
|
||||||
## TODO: maybe some sort of 'fail' animation state
|
## TODO: maybe some sort of 'fail' animation state
|
||||||
#print("Nope: ", state_stamina_cost[state_name], "<=", stamina_component.stamina)
|
#print("Nope: ", state_stamina_cost[state_name], "<=", stamina_component.stamina)
|
||||||
return '' ## you can't use this
|
return '' ## you can't use this
|
||||||
|
## use item even if no stamina usage needed for it.
|
||||||
player_inventory.remove_from_inventory(player_inventory.primary_selection)
|
player_inventory.remove_from_inventory(player_inventory.primary_selection)
|
||||||
return state_to_item_map[_item_name]
|
return state_to_item_map[_item_name]
|
||||||
|
|
||||||
|
|
@ -177,23 +163,15 @@ func use_secondary_item() -> String:
|
||||||
else:
|
else:
|
||||||
## TODO: maybe some sort of 'fail' animation state
|
## TODO: maybe some sort of 'fail' animation state
|
||||||
return ''
|
return ''
|
||||||
return ''
|
## use item even if no stamina usage needed for it.
|
||||||
|
player_inventory.remove_from_inventory(player_inventory.secondary_selection)
|
||||||
|
return state_to_item_map[_item_name]
|
||||||
|
|
||||||
#func check_state_change(_new_state_name: String) -> bool:
|
return ''
|
||||||
# match _new_state_name:
|
|
||||||
# "attack_sword":
|
|
||||||
# print("nope.")
|
|
||||||
# return false
|
|
||||||
# "attack_shoot":
|
|
||||||
# return true
|
|
||||||
# _: # None
|
|
||||||
# return true
|
|
||||||
# return true
|
|
||||||
|
|
||||||
|
|
||||||
func _on_Movement_StateMachine_state_changed(old_state_name, new_state):
|
func _on_Movement_StateMachine_state_changed(old_state_name, new_state):
|
||||||
# if new_state.name == "jump":
|
## Reduce stamina if this state has a cost
|
||||||
# stamina_component.reduce_stamina(state_stamina_cost["jump"])
|
|
||||||
if state_stamina_cost.has(new_state.name):
|
if state_stamina_cost.has(new_state.name):
|
||||||
stamina_component.reduce_stamina(state_stamina_cost[new_state.name])
|
stamina_component.reduce_stamina(state_stamina_cost[new_state.name])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user