Two Players!

This commit is contained in:
Dustin 2025-04-12 14:01:12 -07:00
parent 6b490ba7b4
commit b5d9e9268c
6 changed files with 81 additions and 29 deletions

View File

@ -52,6 +52,10 @@ __meta__ = {
[node name="PlayerE" parent="ViewportContainer/Viewport" instance=ExtResource( 1 )] [node name="PlayerE" parent="ViewportContainer/Viewport" instance=ExtResource( 1 )]
position = Vector2( 112, 56 ) position = Vector2( 112, 56 )
[node name="PlayerE2" parent="ViewportContainer/Viewport" instance=ExtResource( 1 )]
position = Vector2( 112, 56 )
player_number = 2
[node name="UI_Layer" parent="ViewportContainer/Viewport" instance=ExtResource( 3 )] [node name="UI_Layer" parent="ViewportContainer/Viewport" instance=ExtResource( 3 )]
[node name="CameraGuide" type="KinematicBody2D" parent="ViewportContainer/Viewport"] [node name="CameraGuide" type="KinematicBody2D" parent="ViewportContainer/Viewport"]

View File

@ -29,16 +29,18 @@ func _physics_process(delta):
#pos = lerp(pos, PlayerInfo.player_position, delta ) #pos = lerp(pos, PlayerInfo.player_position, delta )
var dir_to = Vector2(0,0) var dir_to = Vector2(0,0)
var player_position = PlayerInfo.get_player_data(0).player_position
# Calculate how far the player is from object # Calculate how far the player is from object
var diff_to = (PlayerInfo.player_position - pos) var diff_to = (player_position - pos)
var dist_to = (PlayerInfo.player_position - pos).length() var dist_to = (player_position - pos).length()
# Determine the chase direction of player is past the threshold # Determine the chase direction of player is past the threshold
# Try to prevent bounce # Try to prevent bounce
if (is_on_wall() or is_on_floor() or is_on_ceiling()) and abs(diff_to.x) > 10: if (is_on_wall() or is_on_floor() or is_on_ceiling()) and abs(diff_to.x) > 10:
dir_to = pos.direction_to(PlayerInfo.player_position) dir_to = pos.direction_to(player_position)
elif !(is_on_wall() or is_on_floor() or is_on_ceiling()) and abs(diff_to.y) > 10: elif !(is_on_wall() or is_on_floor() or is_on_ceiling()) and abs(diff_to.y) > 10:
dir_to = pos.direction_to(PlayerInfo.player_position) dir_to = pos.direction_to(player_position)
# UiManager.debug_text = ( UiManager.debug_text + # UiManager.debug_text = ( UiManager.debug_text +

View File

@ -59,3 +59,29 @@ text = "Foo"
align = 2 align = 2
[node name="PlayerHUD" parent="." instance=ExtResource( 4 )] [node name="PlayerHUD" parent="." instance=ExtResource( 4 )]
[node name="PlayerHUD2" parent="." instance=ExtResource( 4 )]
player_number = 2
[node name="HealthBar" parent="PlayerHUD2" index="0"]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -102.0
margin_right = 0.0
margin_bottom = 12.0
[node name="StaminaBar" parent="PlayerHUD2" index="1"]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -102.0
margin_right = 0.0
margin_bottom = 12.0
[node name="SelectedInventoryItems" parent="PlayerHUD2" index="2"]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -46.0
margin_right = 0.0
[editable path="PlayerHUD"]
[editable path="PlayerHUD2"]

View File

@ -13,9 +13,9 @@ onready var selected_inventory_items = $"%SelectedInventoryItems"
# 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():
health_bar.set_player_number(1) health_bar.set_player_number(player_number)
pass stamina_bar.set_player_number(player_number)
selected_inventory_items.set_player_number(player_number)
# 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):

View File

@ -10,6 +10,8 @@ onready var secondary_item = $SecondaryItem
onready var _primary_item_count = $PrimaryItem/Label onready var _primary_item_count = $PrimaryItem/Label
onready var _secondary_item_count = $SecondaryItem/Label onready var _secondary_item_count = $SecondaryItem/Label
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():
if primary_item == null: if primary_item == null:
@ -19,25 +21,31 @@ func _ready():
pass pass
#secondary_item.texture = PlayerInfo.player_inventory.secondary_selection.inventory_icon #secondary_item.texture = PlayerInfo.player_inventory.secondary_selection.inventory_icon
func _process(delta): func set_player_number(_player_num: int) -> void:
if (PlayerInfo.player_inventory.primary_selection): _player_number = _player_num
primary_item.texture = PlayerInfo.player_inventory.primary_selection.inventory_icon
var count = PlayerInfo.player_inventory.get_item_inventory_count(PlayerInfo.player_inventory.primary_selection)
if count > 1:
_primary_item_count.text = str(count)
else:
_primary_item_count.text = ''
else:
primary_item.texture = null
_primary_item_count.text = ''
if (PlayerInfo.player_inventory.secondary_selection): func _process(delta):
secondary_item.texture = PlayerInfo.player_inventory.secondary_selection.inventory_icon if _player_number:
var count = PlayerInfo.player_inventory.get_item_inventory_count(PlayerInfo.player_inventory.secondary_selection) var pd :PlayerData = PlayerInfo.get_player_data(_player_number - 1)
if count > 1: if pd:
_secondary_item_count.text = str(count) if (pd.player_inventory.primary_selection):
else: primary_item.texture = pd.player_inventory.primary_selection.inventory_icon
_secondary_item_count.text = '' var count = pd.player_inventory.get_item_inventory_count(pd.player_inventory.primary_selection)
else: if count > 1:
secondary_item.texture = null _primary_item_count.text = str(count)
_secondary_item_count.text = '' else:
_primary_item_count.text = ''
else:
primary_item.texture = null
_primary_item_count.text = ''
if (pd.player_inventory.secondary_selection):
secondary_item.texture = pd.player_inventory.secondary_selection.inventory_icon
var count = pd.player_inventory.get_item_inventory_count(pd.player_inventory.secondary_selection)
if count > 1:
_secondary_item_count.text = str(count)
else:
_secondary_item_count.text = ''
else:
secondary_item.texture = null
_secondary_item_count.text = ''

View File

@ -5,12 +5,24 @@ extends TextureProgress
# var a = 2 # var a = 2
# var b = "text" # var b = "text"
var _player_number
# 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_stamina #value = PlayerInfo.player_stamina
if _player_number:
#value = PlayerInfo.player_health
var pd :PlayerData = PlayerInfo.get_player_data(_player_number - 1)
if pd:
value = pd.player_stamina