working on items and inventory
This commit is contained in:
		@@ -21,13 +21,16 @@ extends CharacterBody2D
 | 
			
		||||
@onready var next_attack_time := 0
 | 
			
		||||
@onready var is_attacking := false
 | 
			
		||||
 | 
			
		||||
@onready var equipped:Node2D
 | 
			
		||||
#@onready var equipped:Node2D
 | 
			
		||||
@onready var active_item:Dictionary = {}
 | 
			
		||||
@onready var spawned_item:Node2D
 | 
			
		||||
@onready var invulnerability_timer:Timer = get_node("InvulnerableTimer")
 | 
			
		||||
@onready var player_disabled := false
 | 
			
		||||
@onready var player_in_inventory := false
 | 
			
		||||
@onready var is_searching := false
 | 
			
		||||
 | 
			
		||||
@onready var inv_manager = $CanvasLayer/UserInventory
 | 
			
		||||
 | 
			
		||||
@onready var item_hovering := false
 | 
			
		||||
 | 
			
		||||
@onready var rng = RandomNumberGenerator.new()
 | 
			
		||||
@@ -54,7 +57,9 @@ func set_spawn_location(spawn_position: Vector2):
 | 
			
		||||
	set_position(spawn_position)
 | 
			
		||||
 | 
			
		||||
func _ready():
 | 
			
		||||
	if not is_multiplayer_authority(): return
 | 
			
		||||
	if not is_multiplayer_authority(): 
 | 
			
		||||
		$CanvasLayer.set_visible(false)
 | 
			
		||||
		return
 | 
			
		||||
	print("Setting IDLE: ", get_position())
 | 
			
		||||
	player_cam.make_current()
 | 
			
		||||
	#player_cam.current = true # for mp to set the camera
 | 
			
		||||
@@ -151,8 +156,19 @@ func get_input():
 | 
			
		||||
				#anim_tree.set(atk_str, 1)
 | 
			
		||||
			#anim_mode.travel("attack")
 | 
			
		||||
			next_attack_time = now + attack_speed
 | 
			
		||||
			if equipped:
 | 
			
		||||
				pass
 | 
			
		||||
			print("Attacking!", active_item)
 | 
			
		||||
			if active_item:
 | 
			
		||||
				var item_details = ItemDatabase.PU_objects[active_item.item_name]
 | 
			
		||||
				var item_scene = load(item_details.scene)
 | 
			
		||||
				var item = item_scene.instantiate()
 | 
			
		||||
				add_child(item)
 | 
			
		||||
				item.set_position(get_position())
 | 
			
		||||
				print("ITEM IS: ", item)
 | 
			
		||||
 | 
			
		||||
				item.use_item($".")
 | 
			
		||||
				return
 | 
			
		||||
#			if equipped:
 | 
			
		||||
#				pass
 | 
			
		||||
				#spawned_item = load(ItemDatabase.Castable_objects[equipped.item_name]).instantiate()
 | 
			
		||||
				#var map = get_tree().current_scene
 | 
			
		||||
				#map.add_child(spawned_item)
 | 
			
		||||
@@ -161,6 +177,7 @@ func get_input():
 | 
			
		||||
			#		inventory_ui.set_ammo(-1)
 | 
			
		||||
				#spawned_item.use_item(player, spawned_item, map)
 | 
			
		||||
				#next_attack_time = now + attack_speed
 | 
			
		||||
#	print("RETURNING TO USER INPUT!")
 | 
			
		||||
	velocity = Vector2()
 | 
			
		||||
	var direction : String
 | 
			
		||||
	if Input.is_action_pressed("right") and not is_attacking:
 | 
			
		||||
@@ -237,6 +254,17 @@ func move_player(c_velocity: Vector2):
 | 
			
		||||
#				var normal = collision.get_normal()
 | 
			
		||||
#				collider.apply_central_impulse(-collision.get_normal() * push_power)
 | 
			
		||||
	player_hit.is_player_hit = false
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
@rpc("any_peer")
 | 
			
		||||
func set_context_label(text: String):
 | 
			
		||||
	$CanvasLayer/ContextLabel.set_text(text)
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
func add_inventory_item(item: Dictionary):
 | 
			
		||||
	inv_manager.add_inventory_item(item)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#signal from the inventory
 | 
			
		||||
func _on_user_inventory_active_item_changed(new_active_item):
 | 
			
		||||
	print("SETTING ACTIVE ITEM: ", new_active_item)
 | 
			
		||||
	active_item = new_active_item
 | 
			
		||||
 
 | 
			
		||||
@@ -5,10 +5,10 @@
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://drr0ptd6k6uch" path="res://UI/Inventory/UserInventory.tscn" id="3_nvr35"]
 | 
			
		||||
[ext_resource type="FontFile" uid="uid://dj4pldmxeqmtt" path="res://UI/PressStart2P-Regular.ttf" id="4_i8vjo"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_g1om0"]
 | 
			
		||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_h7cys"]
 | 
			
		||||
size = Vector2(22, 20)
 | 
			
		||||
 | 
			
		||||
[sub_resource type="Animation" id="Animation_5n6gk"]
 | 
			
		||||
[sub_resource type="Animation" id="Animation_epy5e"]
 | 
			
		||||
resource_name = "attack"
 | 
			
		||||
length = 0.65
 | 
			
		||||
tracks/0/type = "value"
 | 
			
		||||
@@ -24,7 +24,7 @@ tracks/0/keys = {
 | 
			
		||||
"values": [Vector2i(0, 5), Vector2i(1, 5), Vector2i(2, 5), Vector2i(3, 5)]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[sub_resource type="Animation" id="Animation_u6kdu"]
 | 
			
		||||
[sub_resource type="Animation" id="Animation_at62u"]
 | 
			
		||||
resource_name = "damage"
 | 
			
		||||
step = 0.01
 | 
			
		||||
tracks/0/type = "value"
 | 
			
		||||
@@ -40,7 +40,7 @@ tracks/0/keys = {
 | 
			
		||||
"values": [Color(0.792157, 0.0901961, 0.0901961, 1), Color(0.792157, 0.0901961, 0.0901961, 1), Color(0.792157, 0.0901961, 0.0901961, 1), Color(1, 1, 1, 1), Color(1, 1, 1, 1), Color(0.792157, 0.0901961, 0.0901961, 1), Color(0.792157, 0.0901961, 0.0901961, 1), Color(1, 1, 1, 1), Color(1, 1, 1, 1), Color(0.792157, 0.0901961, 0.0901961, 1), Color(0.792157, 0.0901961, 0.0901961, 1), Color(1, 1, 1, 1), Color(1, 1, 1, 1), Color(0.792157, 0.0901961, 0.0901961, 1), Color(0.792157, 0.0901961, 0.0901961, 1), Color(1, 1, 1, 1), Color(1, 1, 1, 1), Color(0.792157, 0.0901961, 0.0901961, 1), Color(0.792157, 0.0901961, 0.0901961, 1), Color(1, 1, 1, 1), Color(1, 1, 1, 1), Color(0.792157, 0.0901961, 0.0901961, 1), Color(0.792157, 0.0901961, 0.0901961, 1), Color(1, 1, 1, 1)]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[sub_resource type="Animation" id="Animation_ybwuj"]
 | 
			
		||||
[sub_resource type="Animation" id="Animation_708tn"]
 | 
			
		||||
resource_name = "die"
 | 
			
		||||
tracks/0/type = "value"
 | 
			
		||||
tracks/0/imported = false
 | 
			
		||||
@@ -55,7 +55,7 @@ tracks/0/keys = {
 | 
			
		||||
"values": [Vector2i(0, 4), Vector2i(1, 4), Vector2i(2, 4), Vector2i(3, 4), Vector2i(4, 4)]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[sub_resource type="Animation" id="Animation_h5uv5"]
 | 
			
		||||
[sub_resource type="Animation" id="Animation_ddmol"]
 | 
			
		||||
resource_name = "idle"
 | 
			
		||||
length = 2.0
 | 
			
		||||
loop_mode = 1
 | 
			
		||||
@@ -72,7 +72,7 @@ tracks/0/keys = {
 | 
			
		||||
"values": [Vector2i(0, 0), Vector2i(1, 0), Vector2i(2, 0), Vector2i(3, 0), Vector2i(4, 0)]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[sub_resource type="Animation" id="Animation_cev5d"]
 | 
			
		||||
[sub_resource type="Animation" id="Animation_al5w0"]
 | 
			
		||||
resource_name = "walk"
 | 
			
		||||
loop_mode = 1
 | 
			
		||||
step = 0.01
 | 
			
		||||
@@ -89,62 +89,62 @@ tracks/0/keys = {
 | 
			
		||||
"values": [Vector2i(0, 1), Vector2i(1, 1), Vector2i(2, 1), Vector2i(3, 1), Vector2i(4, 1), Vector2i(5, 1)]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_5qwfv"]
 | 
			
		||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_ufoec"]
 | 
			
		||||
_data = {
 | 
			
		||||
"attack": SubResource("Animation_5n6gk"),
 | 
			
		||||
"damage": SubResource("Animation_u6kdu"),
 | 
			
		||||
"die": SubResource("Animation_ybwuj"),
 | 
			
		||||
"idle": SubResource("Animation_h5uv5"),
 | 
			
		||||
"walk": SubResource("Animation_cev5d")
 | 
			
		||||
"attack": SubResource("Animation_epy5e"),
 | 
			
		||||
"damage": SubResource("Animation_at62u"),
 | 
			
		||||
"die": SubResource("Animation_708tn"),
 | 
			
		||||
"idle": SubResource("Animation_ddmol"),
 | 
			
		||||
"walk": SubResource("Animation_al5w0")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationNodeOneShot" id="AnimationNodeOneShot_2a8v8"]
 | 
			
		||||
[sub_resource type="AnimationNodeOneShot" id="AnimationNodeOneShot_hrw7i"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationNodeOneShot" id="AnimationNodeOneShot_5013i"]
 | 
			
		||||
[sub_resource type="AnimationNodeOneShot" id="AnimationNodeOneShot_a5dle"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_24wrp"]
 | 
			
		||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_jqlyn"]
 | 
			
		||||
animation = &"attack"
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationNodeOneShot" id="AnimationNodeOneShot_2lwq2"]
 | 
			
		||||
[sub_resource type="AnimationNodeOneShot" id="AnimationNodeOneShot_pxj46"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_mfi5b"]
 | 
			
		||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_y87rp"]
 | 
			
		||||
animation = &"damage"
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_yud6d"]
 | 
			
		||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_gy8c5"]
 | 
			
		||||
animation = &"die"
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_0n1hp"]
 | 
			
		||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_bc1jc"]
 | 
			
		||||
animation = &"idle"
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationNodeBlend2" id="AnimationNodeBlend2_qrdax"]
 | 
			
		||||
[sub_resource type="AnimationNodeBlend2" id="AnimationNodeBlend2_a7far"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_6pfdq"]
 | 
			
		||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_mcfk5"]
 | 
			
		||||
animation = &"walk"
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_78n1d"]
 | 
			
		||||
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_fx5ki"]
 | 
			
		||||
graph_offset = Vector2(-769.911, -161.25)
 | 
			
		||||
nodes/AttackOneShot/node = SubResource("AnimationNodeOneShot_2a8v8")
 | 
			
		||||
nodes/AttackOneShot/node = SubResource("AnimationNodeOneShot_hrw7i")
 | 
			
		||||
nodes/AttackOneShot/position = Vector2(-320, 60)
 | 
			
		||||
nodes/DieOneShot/node = SubResource("AnimationNodeOneShot_5013i")
 | 
			
		||||
nodes/DieOneShot/node = SubResource("AnimationNodeOneShot_a5dle")
 | 
			
		||||
nodes/DieOneShot/position = Vector2(-120, 180)
 | 
			
		||||
nodes/attack_anim/node = SubResource("AnimationNodeAnimation_24wrp")
 | 
			
		||||
nodes/attack_anim/node = SubResource("AnimationNodeAnimation_jqlyn")
 | 
			
		||||
nodes/attack_anim/position = Vector2(-560, 200)
 | 
			
		||||
nodes/damageOneShot/node = SubResource("AnimationNodeOneShot_2lwq2")
 | 
			
		||||
nodes/damageOneShot/node = SubResource("AnimationNodeOneShot_pxj46")
 | 
			
		||||
nodes/damageOneShot/position = Vector2(100, 320)
 | 
			
		||||
nodes/damage_anim/node = SubResource("AnimationNodeAnimation_mfi5b")
 | 
			
		||||
nodes/damage_anim/node = SubResource("AnimationNodeAnimation_y87rp")
 | 
			
		||||
nodes/damage_anim/position = Vector2(-200, 460)
 | 
			
		||||
nodes/die_anim/node = SubResource("AnimationNodeAnimation_yud6d")
 | 
			
		||||
nodes/die_anim/node = SubResource("AnimationNodeAnimation_gy8c5")
 | 
			
		||||
nodes/die_anim/position = Vector2(-440, 340)
 | 
			
		||||
nodes/idle_anim/node = SubResource("AnimationNodeAnimation_0n1hp")
 | 
			
		||||
nodes/idle_anim/node = SubResource("AnimationNodeAnimation_bc1jc")
 | 
			
		||||
nodes/idle_anim/position = Vector2(-940, 60)
 | 
			
		||||
nodes/output/position = Vector2(400, 340)
 | 
			
		||||
nodes/walkIdleBlend/node = SubResource("AnimationNodeBlend2_qrdax")
 | 
			
		||||
nodes/walkIdleBlend/node = SubResource("AnimationNodeBlend2_a7far")
 | 
			
		||||
nodes/walkIdleBlend/position = Vector2(-660, -40)
 | 
			
		||||
nodes/walk_anim/node = SubResource("AnimationNodeAnimation_6pfdq")
 | 
			
		||||
nodes/walk_anim/node = SubResource("AnimationNodeAnimation_mcfk5")
 | 
			
		||||
nodes/walk_anim/position = Vector2(-920, -80)
 | 
			
		||||
node_connections = [&"output", 0, &"damageOneShot", &"AttackOneShot", 0, &"walkIdleBlend", &"AttackOneShot", 1, &"attack_anim", &"DieOneShot", 0, &"AttackOneShot", &"DieOneShot", 1, &"die_anim", &"damageOneShot", 0, &"DieOneShot", &"damageOneShot", 1, &"damage_anim", &"walkIdleBlend", 0, &"walk_anim", &"walkIdleBlend", 1, &"idle_anim"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_hr3p8"]
 | 
			
		||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_xv2gm"]
 | 
			
		||||
properties/0/path = NodePath(".:position")
 | 
			
		||||
properties/0/spawn = true
 | 
			
		||||
properties/0/sync = true
 | 
			
		||||
@@ -163,7 +163,7 @@ motion_mode = 1
 | 
			
		||||
script = ExtResource("1_6aci1")
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
 | 
			
		||||
shape = SubResource("RectangleShape2D_g1om0")
 | 
			
		||||
shape = SubResource("RectangleShape2D_h7cys")
 | 
			
		||||
 | 
			
		||||
[node name="Sprite2D" type="Sprite2D" parent="."]
 | 
			
		||||
z_index = 1
 | 
			
		||||
@@ -171,15 +171,15 @@ position = Vector2(-1, -2)
 | 
			
		||||
texture = ExtResource("1_8pmbp")
 | 
			
		||||
hframes = 6
 | 
			
		||||
vframes = 6
 | 
			
		||||
frame = 1
 | 
			
		||||
frame = 4
 | 
			
		||||
 | 
			
		||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
 | 
			
		||||
libraries = {
 | 
			
		||||
"": SubResource("AnimationLibrary_5qwfv")
 | 
			
		||||
"": SubResource("AnimationLibrary_ufoec")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[node name="AnimationTree" type="AnimationTree" parent="."]
 | 
			
		||||
tree_root = SubResource("AnimationNodeBlendTree_78n1d")
 | 
			
		||||
tree_root = SubResource("AnimationNodeBlendTree_fx5ki")
 | 
			
		||||
anim_player = NodePath("../AnimationPlayer")
 | 
			
		||||
active = true
 | 
			
		||||
parameters/AttackOneShot/active = false
 | 
			
		||||
@@ -209,4 +209,6 @@ size_flags_horizontal = 4
 | 
			
		||||
theme_override_fonts/font = ExtResource("4_i8vjo")
 | 
			
		||||
 | 
			
		||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
 | 
			
		||||
replication_config = SubResource("SceneReplicationConfig_hr3p8")
 | 
			
		||||
replication_config = SubResource("SceneReplicationConfig_xv2gm")
 | 
			
		||||
 | 
			
		||||
[connection signal="active_item_changed" from="CanvasLayer/UserInventory" to="." method="_on_user_inventory_active_item_changed"]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user