Working towards item pickups and player inventory
This commit is contained in:
parent
1a82c2bdf0
commit
b9fd6bb3af
27
assets/items/doodad.tres
Normal file
27
assets/items/doodad.tres
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
[gd_resource type="Resource" load_steps=7 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://src/classes/item.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://assets/levels/LegacyFantasy-High_Forest/Tiles/Tiles.png" type="Texture" id=2]
|
||||||
|
[ext_resource path="res://assets/items/mushroom_icon.png" type="Texture" id=3]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id=1]
|
||||||
|
atlas = ExtResource( 2 )
|
||||||
|
region = Rect2( 256, 240, 32, 32 )
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id=2]
|
||||||
|
atlas = ExtResource( 2 )
|
||||||
|
region = Rect2( 288, 240, 32, 32 )
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id=3]
|
||||||
|
animations = [ {
|
||||||
|
"frames": [ SubResource( 1 ), SubResource( 2 ) ],
|
||||||
|
"loop": true,
|
||||||
|
"name": "default",
|
||||||
|
"speed": 1.0
|
||||||
|
} ]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
name = "mushroom"
|
||||||
|
inventory_icon = ExtResource( 3 )
|
||||||
|
in_game_sprite = SubResource( 3 )
|
||||||
BIN
assets/items/mushroom_icon.png
Normal file
BIN
assets/items/mushroom_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 401 B |
35
assets/items/mushroom_icon.png.import
Normal file
35
assets/items/mushroom_icon.png.import
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/mushroom_icon.png-692f5daaafe395b280b8df070c417867.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/items/mushroom_icon.png"
|
||||||
|
dest_files=[ "res://.import/mushroom_icon.png-692f5daaafe395b280b8df070c417867.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=0
|
||||||
|
flags/filter=false
|
||||||
|
flags/mipmaps=false
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=true
|
||||||
|
svg/scale=1.0
|
||||||
|
|
@ -54,6 +54,21 @@ _global_script_classes=[ {
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://lib/templates/Interactable/Interactable_Receiver.gd"
|
"path": "res://lib/templates/Interactable/Interactable_Receiver.gd"
|
||||||
}, {
|
}, {
|
||||||
|
"base": "Resource",
|
||||||
|
"class": "InventoryManager",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://src/classes/inventory_manager.gd"
|
||||||
|
}, {
|
||||||
|
"base": "Resource",
|
||||||
|
"class": "Item",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://src/classes/item.gd"
|
||||||
|
}, {
|
||||||
|
"base": "Interactable",
|
||||||
|
"class": "ItemPickup",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://src/Interactables/ItemPickup.gd"
|
||||||
|
}, {
|
||||||
"base": "Node2D",
|
"base": "Node2D",
|
||||||
"class": "Level",
|
"class": "Level",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
|
|
@ -129,6 +144,9 @@ _global_script_class_icons={
|
||||||
"HealthPickup": "",
|
"HealthPickup": "",
|
||||||
"Interactable": "",
|
"Interactable": "",
|
||||||
"Interactable_Receiver": "",
|
"Interactable_Receiver": "",
|
||||||
|
"InventoryManager": "",
|
||||||
|
"Item": "",
|
||||||
|
"ItemPickup": "",
|
||||||
"Level": "",
|
"Level": "",
|
||||||
"LevelTransition": "",
|
"LevelTransition": "",
|
||||||
"Modifier_Receiver": "",
|
"Modifier_Receiver": "",
|
||||||
|
|
|
||||||
17
src/Interactables/ItemPickup.gd
Normal file
17
src/Interactables/ItemPickup.gd
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
class_name ItemPickup
|
||||||
|
extends Interactable
|
||||||
|
|
||||||
|
|
||||||
|
# Declare member variables here. Examples:
|
||||||
|
# var a = 2
|
||||||
|
# var b = "text"
|
||||||
|
|
||||||
|
|
||||||
|
# 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
src/Interactables/ItemPickup.tscn
Normal file
9
src/Interactables/ItemPickup.tscn
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://src/Interactables/ItemPickup.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="ItemPickup" type="Area2D"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_Interactable_Component_body_entered"]
|
||||||
|
[connection signal="body_exited" from="." to="." method="_on_Interactable_Component_body_exited"]
|
||||||
46
src/classes/inventory_manager.gd
Normal file
46
src/classes/inventory_manager.gd
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
class_name InventoryManager
|
||||||
|
extends Resource
|
||||||
|
|
||||||
|
|
||||||
|
# Declare member variables here. Examples:
|
||||||
|
# var a = 2
|
||||||
|
# var b = "text"
|
||||||
|
var primary_selection: Item
|
||||||
|
var secondary_selection: Item
|
||||||
|
|
||||||
|
# count of items in dictionary value
|
||||||
|
var _items :Dictionary
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
func add_to_inventory(_item :Item) -> int:
|
||||||
|
if _items.has(_item):
|
||||||
|
_items[_item] += 1
|
||||||
|
else:
|
||||||
|
_items[_item] = 1
|
||||||
|
return _items[_item]
|
||||||
|
|
||||||
|
|
||||||
|
func remove_from_inventory (_item :Item) -> int:
|
||||||
|
if _items.has(_item):
|
||||||
|
_items[_item] -= 1
|
||||||
|
if _items[_item] == 0:
|
||||||
|
_items.erase(_item)
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
return _items[_item]
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
func clear_item_from_inventory (_item :Item) -> void:
|
||||||
|
if _items.has(_item):
|
||||||
|
_items.erase(_item)
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
#func _process(delta):
|
||||||
|
# pass
|
||||||
19
src/classes/item.gd
Normal file
19
src/classes/item.gd
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
class_name Item
|
||||||
|
extends Resource
|
||||||
|
|
||||||
|
|
||||||
|
# Declare member variables here. Examples:
|
||||||
|
# var a = 2
|
||||||
|
# var b = "text"
|
||||||
|
export var name :String
|
||||||
|
export var inventory_icon :Texture
|
||||||
|
export var in_game_sprite :SpriteFrames
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
assert ( name != '', "Name never given to Item" + self.resource_path )
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
#func _process(delta):
|
||||||
|
# pass
|
||||||
Loading…
Reference in New Issue
Block a user