working on items and inventory
This commit is contained in:
@@ -15,17 +15,22 @@ extends PU_Item
|
||||
|
||||
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!")
|
||||
var result = current_player.add_inventory_item(item_info)
|
||||
if result:
|
||||
queue_free()
|
||||
current_player.add_inventory_item(item_info)
|
||||
print("Adding inventory item!")
|
||||
cleanup.rpc()
|
||||
|
||||
@rpc("call_local", "any_peer")
|
||||
func cleanup():
|
||||
queue_free()
|
||||
|
||||
func _on_bomb_pu_area_body_entered(body):
|
||||
if body.is_in_group("player"):
|
||||
current_player = body
|
||||
is_reachable = true
|
||||
current_player.set_context_label("Pickup " + item_info.item_name + "?")
|
||||
current_player.set_context_label.rpc_id(current_player.get_multiplayer_authority(), "Pickup " + item_info.item_name + "?")
|
||||
|
||||
|
||||
func _on_bomb_pu_area_body_exited(body):
|
||||
|
@@ -6,8 +6,14 @@
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1taf2"]
|
||||
size = Vector2(20, 34)
|
||||
|
||||
[node name="bomb" type="Node"]
|
||||
[node name="Bomb" type="Node2D"]
|
||||
script = ExtResource("1_0j4vj")
|
||||
item_name = "Bomb"
|
||||
item_description = "Throw and run. Simple and effective."
|
||||
item_type = 0
|
||||
item_clip_size = 1
|
||||
item_ammo = 1
|
||||
item_texture = ExtResource("2_c4hvj")
|
||||
|
||||
[node name="BombPUArea" type="Area2D" parent="."]
|
||||
|
||||
|
45
PickupableObjects/GluePatch/GluePatch.gd
Normal file
45
PickupableObjects/GluePatch/GluePatch.gd
Normal file
@@ -0,0 +1,45 @@
|
||||
extends PU_Item
|
||||
|
||||
@onready var is_reachable := false
|
||||
@onready var current_player:CharacterBody2D = null
|
||||
|
||||
@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 _on_glue_patch_pu_area_body_exited(body):
|
||||
if body.is_in_group("player"):
|
||||
current_player.set_context_label("")
|
||||
current_player = null
|
||||
is_reachable = false
|
||||
|
||||
|
||||
func _on_glue_patch_pu_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 + "?")
|
||||
|
||||
|
||||
|
||||
|
28
PickupableObjects/GluePatch/GluePatch.tscn
Normal file
28
PickupableObjects/GluePatch/GluePatch.tscn
Normal file
@@ -0,0 +1,28 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://r0424mbc1jx8"]
|
||||
|
||||
[ext_resource type="Script" path="res://PickupableObjects/GluePatch/GluePatch.gd" id="1_j7usm"]
|
||||
[ext_resource type="Texture2D" uid="uid://t7jsxx1bf6dl" path="res://PickupableObjects/GluePatch/glue_patch.png" id="2_aflxg"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_dpesl"]
|
||||
size = Vector2(17, 25)
|
||||
|
||||
[node name="GluePatch" type="Node2D"]
|
||||
script = ExtResource("1_j7usm")
|
||||
item_name = "Glue Patch"
|
||||
item_description = "Lay down to slow down enemies!"
|
||||
item_type = 0
|
||||
item_clip_size = 3
|
||||
item_ammo = 3
|
||||
item_texture = ExtResource("2_aflxg")
|
||||
|
||||
[node name="GluePatchPUArea" type="Area2D" parent="."]
|
||||
|
||||
[node name="GluePatchImage" type="Sprite2D" parent="GluePatchPUArea"]
|
||||
texture = ExtResource("2_aflxg")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="GluePatchPUArea"]
|
||||
position = Vector2(0.5, 3.5)
|
||||
shape = SubResource("RectangleShape2D_dpesl")
|
||||
|
||||
[connection signal="body_entered" from="GluePatchPUArea" to="." method="_on_glue_patch_pu_area_body_entered"]
|
||||
[connection signal="body_exited" from="GluePatchPUArea" to="." method="_on_glue_patch_pu_area_body_exited"]
|
BIN
PickupableObjects/GluePatch/glue_patch.png
Normal file
BIN
PickupableObjects/GluePatch/glue_patch.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 517 B |
34
PickupableObjects/GluePatch/glue_patch.png.import
Normal file
34
PickupableObjects/GluePatch/glue_patch.png.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://t7jsxx1bf6dl"
|
||||
path="res://.godot/imported/glue_patch.png-0c65bf8d7d6c6677dda74b8b236a0fa9.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://PickupableObjects/GluePatch/glue_patch.png"
|
||||
dest_files=["res://.godot/imported/glue_patch.png-0c65bf8d7d6c6677dda74b8b236a0fa9.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
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
|
||||
|
29
PickupableObjects/NailGun/NailGun.tscn
Normal file
29
PickupableObjects/NailGun/NailGun.tscn
Normal file
@@ -0,0 +1,29 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://d1w6rui20nu63"]
|
||||
|
||||
[ext_resource type="Script" path="res://PickupableObjects/NailGun/NailGun.gd" id="1_nb5m2"]
|
||||
[ext_resource type="Texture2D" uid="uid://ci13ka3m3nfmw" path="res://PickupableObjects/NailGun/nail_gun.png" id="2_w7jwi"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_38nhd"]
|
||||
size = Vector2(20, 31)
|
||||
|
||||
[node name="NailGun" type="Node2D"]
|
||||
script = ExtResource("1_nb5m2")
|
||||
item_name = "Nail Gun"
|
||||
item_description = "Shoot at Enemies to slow them down!"
|
||||
item_type = 0
|
||||
item_clip_size = 6
|
||||
item_ammo = 5
|
||||
item_cooldown = 2.0
|
||||
item_texture = ExtResource("2_w7jwi")
|
||||
|
||||
[node name="NailGunArea" type="Area2D" parent="."]
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="NailGunArea"]
|
||||
texture = ExtResource("2_w7jwi")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="NailGunArea"]
|
||||
position = Vector2(0, 5.5)
|
||||
shape = SubResource("RectangleShape2D_38nhd")
|
||||
|
||||
[connection signal="body_entered" from="NailGunArea" to="." method="_on_nail_gun_area_body_entered"]
|
||||
[connection signal="body_exited" from="NailGunArea" to="." method="_on_nail_gun_area_body_exited"]
|
25
PickupableObjects/NailGun/NailShot.gd
Normal file
25
PickupableObjects/NailGun/NailShot.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
extends RigidBody2D
|
||||
|
||||
@export var hit_power:int = 10
|
||||
@export var nail_velocity:int = 200
|
||||
@export var spawn_offset:int = 25
|
||||
@export var cleanup_time:float = 2.0
|
||||
|
||||
@onready var collision_shape = get_node("CollisionShape2D")
|
||||
@onready var facing_vector = Vector2(0, 0)
|
||||
@onready var controlling_player:CharacterBody2D
|
||||
@onready var hit_player:CharacterBody2D = null
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func _on_body_entered(body):
|
||||
if body.is_in_group("moveable"):
|
||||
collision_shape.set_deferred("disabled", true)
|
||||
body.apply_central_impulse(facing_vector)
|
||||
elif body.is_in_group("player"):
|
||||
body.player_hit.is_player_hit = true
|
||||
#body.player_hit.hit_velocity = last_velocity.normalized() * push_strength
|
||||
body.health_changed_func(-1)
|
||||
hit_player = body
|
21
PickupableObjects/NailGun/NailShot.tscn
Normal file
21
PickupableObjects/NailGun/NailShot.tscn
Normal file
@@ -0,0 +1,21 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://brs78nmhyom78"]
|
||||
|
||||
[ext_resource type="Script" path="res://PickupableObjects/NailGun/NailShot.gd" id="1_ul31y"]
|
||||
[ext_resource type="Texture2D" uid="uid://cgtkkroa583fo" path="res://TileSets/Stuff.png" id="2_4fssh"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_dsxgv"]
|
||||
size = Vector2(11, 15)
|
||||
|
||||
[node name="NailShot" type="RigidBody2D"]
|
||||
script = ExtResource("1_ul31y")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("2_4fssh")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(0, 98, 15, 15)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0.5, -0.5)
|
||||
shape = SubResource("RectangleShape2D_dsxgv")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
BIN
PickupableObjects/NailGun/nail_gun.png
Normal file
BIN
PickupableObjects/NailGun/nail_gun.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 281 B |
34
PickupableObjects/NailGun/nail_gun.png.import
Normal file
34
PickupableObjects/NailGun/nail_gun.png.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://ci13ka3m3nfmw"
|
||||
path="res://.godot/imported/nail_gun.png-bd6d067424e08f8881295b50a9197858.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://PickupableObjects/NailGun/nail_gun.png"
|
||||
dest_files=["res://.godot/imported/nail_gun.png-bd6d067424e08f8881295b50a9197858.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
@@ -1,4 +1,4 @@
|
||||
extends Node
|
||||
extends Node2D
|
||||
|
||||
class_name PU_Item
|
||||
|
||||
@@ -6,7 +6,7 @@ enum ItemType {WEAPON, ITEM, OTHER, ELSE}
|
||||
|
||||
@export var item_name:String = ""
|
||||
@export_multiline var item_description:String = ""
|
||||
@export var item_type = ItemType
|
||||
@export var item_type: ItemType
|
||||
@export var item_clip_size:int = 0
|
||||
@export var item_ammo:int = 0
|
||||
@export var item_cooldown:float = 1.0
|
||||
|
Reference in New Issue
Block a user