PlayerInfo and playerE cleanup
This commit is contained in:
parent
ed9909ed7e
commit
d8a5107739
|
|
@ -1,13 +1,8 @@
|
|||
extends Node
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
var player_position: Vector2
|
||||
var player_health: int
|
||||
var player_stamina: int
|
||||
var player_inventory: InventoryManager
|
||||
## PlayerInfo
|
||||
# Tracks player info for other nodes
|
||||
# and UI elements.
|
||||
# Manages PlayerData objects for inventory and maybe saving later.
|
||||
|
||||
## An array of player data objects
|
||||
var _player_data :Array = []
|
||||
|
|
|
|||
|
|
@ -2,15 +2,12 @@ extends Actor
|
|||
|
||||
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 stamina_component = $"%Stamina_Component"
|
||||
onready var health_component = $"%Health_Component"
|
||||
|
||||
var punch_item :Item = preload("res://assets/items/punch.tres")
|
||||
|
||||
|
||||
const state_stamina_cost :Dictionary = {
|
||||
"jump": 10,
|
||||
|
|
@ -25,16 +22,19 @@ const state_damage_amount :Dictionary = {
|
|||
"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_data :PlayerData
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
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
|
||||
if is_network_master():
|
||||
player_info_index = PlayerInfo.register_player()
|
||||
|
|
@ -50,6 +50,8 @@ func _ready():
|
|||
# Set initial player position in world.
|
||||
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.select_primary(punch_item)
|
||||
|
||||
|
|
@ -60,15 +62,8 @@ func _ready():
|
|||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
if is_network_master():
|
||||
#PlayerInfo.player_position = global_position.round()
|
||||
## Update position and stamina in player data
|
||||
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
|
||||
|
||||
##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
|
||||
|
||||
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.
|
||||
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
|
||||
var _item_name :String = player_inventory.primary_selection.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
|
||||
#print("Nope: ", state_stamina_cost[state_name], "<=", stamina_component.stamina)
|
||||
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)
|
||||
return state_to_item_map[_item_name]
|
||||
|
||||
|
|
@ -177,23 +163,15 @@ func use_secondary_item() -> String:
|
|||
else:
|
||||
## TODO: maybe some sort of 'fail' animation state
|
||||
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:
|
||||
# match _new_state_name:
|
||||
# "attack_sword":
|
||||
# print("nope.")
|
||||
# return false
|
||||
# "attack_shoot":
|
||||
# return true
|
||||
# _: # None
|
||||
# return true
|
||||
# return true
|
||||
return ''
|
||||
|
||||
|
||||
func _on_Movement_StateMachine_state_changed(old_state_name, new_state):
|
||||
# if new_state.name == "jump":
|
||||
# stamina_component.reduce_stamina(state_stamina_cost["jump"])
|
||||
## Reduce stamina if this state has a cost
|
||||
if state_stamina_cost.has(new_state.name):
|
||||
stamina_component.reduce_stamina(state_stamina_cost[new_state.name])
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user