working on items and inventory
This commit is contained in:
69
PickupableObjects/NailGun/NailGun.gd
Normal file
69
PickupableObjects/NailGun/NailGun.gd
Normal file
@@ -0,0 +1,69 @@
|
||||
extends PU_Item
|
||||
|
||||
@onready var is_reachable := false
|
||||
@onready var current_player:CharacterBody2D = null
|
||||
@onready var controlling_player:CharacterBody2D
|
||||
@onready var item_info = {
|
||||
"item_name": item_name,
|
||||
"item_description": item_description,
|
||||
"item_type": item_type,
|
||||
"item_clip_size": item_clip_size,
|
||||
"item_ammo": item_ammo,
|
||||
"item_cooldown": item_cooldown,
|
||||
"item_texture": item_texture,
|
||||
}
|
||||
|
||||
func _input(event):
|
||||
if Input.is_action_pressed("interact") and is_reachable and current_player:
|
||||
print("ITEM TYPE: ", item_type)
|
||||
# if item_type == 0: # 0 is weapon
|
||||
# print("Weapon!")
|
||||
current_player.add_inventory_item(item_info)
|
||||
print("Adding inventory item!")
|
||||
cleanup.rpc()
|
||||
|
||||
@rpc("call_local", "any_peer")
|
||||
func cleanup():
|
||||
queue_free()
|
||||
|
||||
func use_item(player: CharacterBody2D):
|
||||
controlling_player = player
|
||||
print("PLAYER FACING!", player.player_facing)
|
||||
var player_pos = controlling_player.get_position()
|
||||
var nail = preload("res://PickupableObjects/NailGun/NailShot.tscn").instantiate()
|
||||
var facing_vector = Vector2(0, -nail.nail_velocity)
|
||||
var spawn_pos = player_pos + Vector2(0, -nail.spawn_offset)
|
||||
nail.set_position(spawn_pos)
|
||||
match controlling_player.player_facing:
|
||||
"down":
|
||||
nail.set_rotation(deg_to_rad(180))
|
||||
facing_vector = Vector2(0, nail.nail_velocity)
|
||||
spawn_pos = player_pos + Vector2(0, nail.spawn_offset)
|
||||
"right":
|
||||
nail.set_rotation(deg_to_rad(90))
|
||||
facing_vector = Vector2(nail.nail_velocity, 0)
|
||||
spawn_pos = player_pos + Vector2(nail.spawn_offset, 0)
|
||||
"left":
|
||||
nail.set_rotation(deg_to_rad(-90))
|
||||
facing_vector = Vector2(-nail.nail_velocity, 0)
|
||||
spawn_pos = player_pos + Vector2(-nail.spawn_offset, 0)
|
||||
# spawn_item.set_position(spawn_pos)
|
||||
nail.apply_central_impulse(facing_vector)
|
||||
print("GET TREE: ", get_tree())
|
||||
await get_tree().create_timer(nail.cleanup_time).timeout
|
||||
nail.queue_free()
|
||||
|
||||
|
||||
func _on_nail_gun_area_body_entered(body):
|
||||
if body.is_in_group("player"):
|
||||
current_player = body
|
||||
is_reachable = true
|
||||
current_player.set_context_label.rpc_id(current_player.get_multiplayer_authority(), "Pickup " + item_info.item_name + "?")
|
||||
|
||||
|
||||
func _on_nail_gun_area_body_exited(body):
|
||||
if body.is_in_group("player"):
|
||||
current_player.set_context_label("")
|
||||
current_player = null
|
||||
is_reachable = false
|
||||
|
Reference in New Issue
Block a user