Implementing new player data resource to help with guis and passing player information around
This commit is contained in:
parent
1c112630d1
commit
6b490ba7b4
19
lib/classes/player_data.gd
Normal file
19
lib/classes/player_data.gd
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
class_name PlayerData
|
||||||
|
extends Resource
|
||||||
|
|
||||||
|
|
||||||
|
# Declare member variables here. Examples:
|
||||||
|
var player_position: Vector2
|
||||||
|
var player_health: int
|
||||||
|
var player_stamina: int
|
||||||
|
var player_inventory: InventoryManager
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
#func _ready():
|
||||||
|
# pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
#func _process(delta):
|
||||||
|
# pass
|
||||||
|
|
@ -9,10 +9,23 @@ var player_health: int
|
||||||
var player_stamina: int
|
var player_stamina: int
|
||||||
var player_inventory: InventoryManager
|
var player_inventory: InventoryManager
|
||||||
|
|
||||||
|
## An array of player data objects
|
||||||
|
var _player_data :Array = []
|
||||||
|
|
||||||
# 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():
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
func register_player() -> int:
|
||||||
|
_player_data.append(PlayerData.new())
|
||||||
|
## Return the index of the player data
|
||||||
|
return (_player_data.size() - 1 )
|
||||||
|
|
||||||
|
func get_player_data(index :int) -> PlayerData:
|
||||||
|
if _player_data.size() > index:
|
||||||
|
return _player_data[index]
|
||||||
|
else:
|
||||||
|
return null
|
||||||
|
|
||||||
# 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):
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,11 @@ _global_script_classes=[ {
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://lib/classes/movement_state_receiver.gd"
|
"path": "res://lib/classes/movement_state_receiver.gd"
|
||||||
}, {
|
}, {
|
||||||
|
"base": "Resource",
|
||||||
|
"class": "PlayerData",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://lib/classes/player_data.gd"
|
||||||
|
}, {
|
||||||
"base": "Area2D",
|
"base": "Area2D",
|
||||||
"class": "Projectile",
|
"class": "Projectile",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
|
|
@ -162,6 +167,7 @@ _global_script_class_icons={
|
||||||
"Modifier_Receiver": "",
|
"Modifier_Receiver": "",
|
||||||
"MovementComponent": "",
|
"MovementComponent": "",
|
||||||
"Movement_StateReceiver": "",
|
"Movement_StateReceiver": "",
|
||||||
|
"PlayerData": "",
|
||||||
"Projectile": "",
|
"Projectile": "",
|
||||||
"SE_StateFrame": "",
|
"SE_StateFrame": "",
|
||||||
"StaminaComponent": "",
|
"StaminaComponent": "",
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,23 @@ const state_stamina_cost :Dictionary = {
|
||||||
"ledge_climb":10
|
"ledge_climb":10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var player_info_index :int
|
||||||
|
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_health = health_component.health
|
||||||
PlayerInfo.player_inventory = player_inventory
|
PlayerInfo.player_inventory = player_inventory
|
||||||
PlayerInfo.player_stamina = stamina_component.stamina
|
# PlayerInfo.player_stamina = stamina_component.stamina
|
||||||
|
|
||||||
|
player_info_index = PlayerInfo.register_player()
|
||||||
|
print ("Registered as player: ", player_info_index)
|
||||||
|
player_data = PlayerInfo.get_player_data(player_info_index)
|
||||||
|
PlayerInfo.get_player_data(player_info_index).player_health = health_component.health
|
||||||
|
print ("My health is: ", player_data.player_health)
|
||||||
|
player_data.player_inventory = player_inventory
|
||||||
|
player_data.player_stamina = stamina_component.stamina
|
||||||
|
|
||||||
# Set initial player position in world.
|
# Set initial player position in world.
|
||||||
global_position = LevelInfo.player_start_position
|
global_position = LevelInfo.player_start_position
|
||||||
|
|
||||||
|
|
@ -34,18 +46,21 @@ func _ready():
|
||||||
movement_component.state_stamina_cost = state_stamina_cost
|
movement_component.state_stamina_cost = state_stamina_cost
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#var stamina_recovery :float = 0.0
|
#var stamina_recovery :float = 0.0
|
||||||
|
|
||||||
# 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):
|
||||||
PlayerInfo.player_position = global_position.round()
|
#PlayerInfo.player_position = global_position.round()
|
||||||
|
player_data.player_position = global_position.round()
|
||||||
# stamina_recovery += delta
|
# stamina_recovery += delta
|
||||||
# if stamina_recovery > 1.0:
|
# if stamina_recovery > 1.0:
|
||||||
# stamina_component.recover(1)
|
# stamina_component.recover(1)
|
||||||
# stamina_recovery = 0.0
|
# stamina_recovery = 0.0
|
||||||
# #print("recover ", stamina_component.stamina)
|
# #print("recover ", stamina_component.stamina)
|
||||||
|
|
||||||
PlayerInfo.player_stamina = stamina_component.stamina
|
#PlayerInfo.player_stamina = stamina_component.stamina
|
||||||
|
player_data.player_stamina = stamina_component.stamina
|
||||||
|
|
||||||
|
|
||||||
match movement_state_machine.current_state.name:
|
match movement_state_machine.current_state.name:
|
||||||
|
|
@ -64,8 +79,10 @@ func hit_Receiver(damage):
|
||||||
health_component.take_damage(damage)
|
health_component.take_damage(damage)
|
||||||
if $Health_Component.health > 0:
|
if $Health_Component.health > 0:
|
||||||
movement_state_machine.change_to_known_state('hurt')
|
movement_state_machine.change_to_known_state('hurt')
|
||||||
PlayerInfo.player_health = health_component.health
|
#PlayerInfo.player_health = health_component.health
|
||||||
if PlayerInfo.player_health <= 0:
|
player_data.player_health = health_component.health
|
||||||
|
print ("Got Hurt, What happend: " , PlayerInfo.get_player_data(player_info_index).player_health, " vs ", player_data.player_health)
|
||||||
|
if health_component.health <= 0:
|
||||||
return
|
return
|
||||||
yield( get_tree().create_timer(2 + movement_state_machine.get_state_reference('hurt').timeout_seconds), "timeout")
|
yield( get_tree().create_timer(2 + movement_state_machine.get_state_reference('hurt').timeout_seconds), "timeout")
|
||||||
$Hurtbox_Component.set_hurtbox(true)
|
$Hurtbox_Component.set_hurtbox(true)
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ onready var health_bar = $PlayerHUD/HealthBar
|
||||||
onready var stamina_bar = $PlayerHUD/StaminaBar
|
onready var stamina_bar = $PlayerHUD/StaminaBar
|
||||||
|
|
||||||
## Cool I can bring this in with a ctrl drag
|
## Cool I can bring this in with a ctrl drag
|
||||||
onready var selected_inventory_items = $"%SelectedInventoryItems"
|
#onready var selected_inventory_items = $"%SelectedInventoryItems"
|
||||||
|
|
||||||
|
|
||||||
var current_pane
|
var current_pane
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,19 @@ extends TextureProgress
|
||||||
# var a = 2
|
# var a = 2
|
||||||
# var b = "text"
|
# var b = "text"
|
||||||
|
|
||||||
|
var _player_number :int
|
||||||
|
|
||||||
# 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():
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
func set_player_number(_player_num: int) -> void:
|
||||||
|
_player_number = _player_num
|
||||||
|
|
||||||
# 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):
|
||||||
value = PlayerInfo.player_health
|
if _player_number:
|
||||||
|
#value = PlayerInfo.player_health
|
||||||
|
var pd :PlayerData = PlayerInfo.get_player_data(_player_number - 1)
|
||||||
|
if pd:
|
||||||
|
value = pd.player_health
|
||||||
|
|
|
||||||
22
src/ui/PlayerHUD.gd
Normal file
22
src/ui/PlayerHUD.gd
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
extends Control
|
||||||
|
|
||||||
|
|
||||||
|
# Declare member variables here. Examples:
|
||||||
|
# var a = 2
|
||||||
|
# var b = "text"
|
||||||
|
export var player_number :int = 1
|
||||||
|
|
||||||
|
onready var health_bar = $"%HealthBar"
|
||||||
|
onready var stamina_bar = $"%StaminaBar"
|
||||||
|
onready var selected_inventory_items = $"%SelectedInventoryItems"
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
health_bar.set_player_number(1)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
#func _process(delta):
|
||||||
|
# pass
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=8 format=2]
|
[gd_scene load_steps=9 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://assets/Fonts/QuinqueFive.tres" type="DynamicFont" id=1]
|
[ext_resource path="res://assets/Fonts/QuinqueFive.tres" type="DynamicFont" id=1]
|
||||||
[ext_resource path="res://assets/UI/Staminabar-Indicator.png" type="Texture" id=2]
|
[ext_resource path="res://assets/UI/Staminabar-Indicator.png" type="Texture" id=2]
|
||||||
|
|
@ -7,12 +7,15 @@
|
||||||
[ext_resource path="res://src/ui/HealthBar.gd" type="Script" id=5]
|
[ext_resource path="res://src/ui/HealthBar.gd" type="Script" id=5]
|
||||||
[ext_resource path="res://src/ui/SelectedInventoryItems.gd" type="Script" id=6]
|
[ext_resource path="res://src/ui/SelectedInventoryItems.gd" type="Script" id=6]
|
||||||
[ext_resource path="res://src/ui/StaminaBar.gd" type="Script" id=7]
|
[ext_resource path="res://src/ui/StaminaBar.gd" type="Script" id=7]
|
||||||
|
[ext_resource path="res://src/ui/PlayerHUD.gd" type="Script" id=8]
|
||||||
|
|
||||||
[node name="PlayerHUD" type="Control"]
|
[node name="PlayerHUD" type="Control"]
|
||||||
margin_right = 320.0
|
margin_right = 320.0
|
||||||
margin_bottom = 180.0
|
margin_bottom = 180.0
|
||||||
|
script = ExtResource( 8 )
|
||||||
|
|
||||||
[node name="HealthBar" type="TextureProgress" parent="."]
|
[node name="HealthBar" type="TextureProgress" parent="."]
|
||||||
|
unique_name_in_owner = true
|
||||||
margin_left = 2.0
|
margin_left = 2.0
|
||||||
margin_top = 2.0
|
margin_top = 2.0
|
||||||
margin_right = 104.0
|
margin_right = 104.0
|
||||||
|
|
@ -24,6 +27,7 @@ texture_progress_offset = Vector2( 1, 1 )
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
|
|
||||||
[node name="StaminaBar" type="TextureProgress" parent="."]
|
[node name="StaminaBar" type="TextureProgress" parent="."]
|
||||||
|
unique_name_in_owner = true
|
||||||
margin_left = 2.0
|
margin_left = 2.0
|
||||||
margin_top = 14.0
|
margin_top = 14.0
|
||||||
margin_right = 104.0
|
margin_right = 104.0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user