Added a logic to add items to the inventory

This commit is contained in:
Eljakim Herrewijnen 2020-10-10 22:23:11 +02:00
parent 7ae1e86f9d
commit 2efdaf8aee
8 changed files with 42 additions and 35 deletions

View File

@ -6,10 +6,22 @@ var player_inventory_items = []
var river_intersection_home_2 = preload("res://river_intersection_home2.tscn").instance() var river_intersection_home_2 = preload("res://river_intersection_home2.tscn").instance()
var inventory_screen = preload("res://MiscScenes/Inventory.tscn").instance() var inventory_screen = preload("res://MiscScenes/Inventory.tscn").instance()
var current_scene = null var current_scene = null
#func _add_a_scene_manually():
# # This is like autoloading the scene, only func AddInventoryItem(itemid, amount):
# # it happens after already loading the main scene. for x in range(40):
# get_tree().get_root().add_child(simultaneous_scene) if(player_inventory_items[x].item_id == itemid):
player_inventory_items[x].amount += amount
return
#if we reached here then no exisiting item is found and we iterate the array again
print("adding item")
for x in range(40):
if(player_inventory_items[x].item_id == 0):
player_inventory_items[x].id = x
player_inventory_items[x].item_name = "name"
player_inventory_items[x].shortdesc = "desc"
player_inventory_items[x].item_id = itemid
player_inventory_items[x].amount = amount
return
func GoToScene(scene): func GoToScene(scene):
if current_scene != null: if current_scene != null:

View File

@ -32,17 +32,22 @@ func _physics_process(delta):
# interaction.clear() # interaction.clear()
# interaction.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 0) # interaction.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 0)
#Handles interaction with the map func InteractWithCell():
var plant_cell = plants_map.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y))
var background_cell = background_map.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y))
var interaction_cell = interaction.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y))
print(plant_cell)
if plant_cell == 1:
Global.AddInventoryItem(3, 1)
plants_map.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 4)
# plants_map.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 4)
func _interaction_process(): func _interaction_process():
if Input.is_action_pressed("map_interaction") or Input.is_key_pressed((KEY_SPACE)): if Input.is_action_pressed("map_interaction") or Input.is_key_pressed((KEY_SPACE)):
var x = plants_map.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y)) InteractWithCell()
plants_map.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 10) # plants_map.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 10)
func _input(event): func _input(event):
# Mouse in viewport coordinates.
if event is InputEventMouseButton:
var pos = event.position
if Input.is_action_pressed("map_interaction"):
pass pass
func _ready(): func _ready():

View File

@ -14,6 +14,7 @@ font_data = ExtResource( 4 )
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="loading_ring" type="Sprite" parent="."] [node name="loading_ring" type="Sprite" parent="."]
visible = false
position = Vector2( 574.719, 228.63 ) position = Vector2( 574.719, 228.63 )
z_index = 1 z_index = 1
texture = ExtResource( 2 ) texture = ExtResource( 2 )

View File

@ -11,3 +11,11 @@ func _ready():
$TextureRect.texture = load("res://pictures/inventory_iconpictures/miscellaneous/magic_formulae.png") $TextureRect.texture = load("res://pictures/inventory_iconpictures/miscellaneous/magic_formulae.png")
2: 2:
$TextureRect.texture = load("res://pictures/inventory_iconpictures/tools_and_weapons/tools/ploeg.png") $TextureRect.texture = load("res://pictures/inventory_iconpictures/tools_and_weapons/tools/ploeg.png")
3:
$TextureRect.texture = load("res://pictures/inventory_iconpictures/food_items/herbs/saffron.png")
if Global.player_inventory_items[self.id].amount > 0:
var amountlbl = Label.new()
amountlbl.set_position(Vector2(self.position.x+102, self.position.y+102))
amountlbl.text = str(Global.player_inventory_items[self.id].amount)
add_child(amountlbl)

View File

@ -27,6 +27,7 @@ func _ready():
item = ItemClass.instance() item = ItemClass.instance()
item.set("id", self.id) item.set("id", self.id)
add_child(item) add_child(item)
# refresh_style() # refresh_style()
#func refresh_style(): #func refresh_style():

View File

@ -1,7 +1,6 @@
[gd_resource type="TileSet" load_steps=3 format=2] [gd_resource type="TileSet" load_steps=2 format=2]
[ext_resource path="res://Plants.png" type="Texture" id=1] [ext_resource path="res://Plants.png" type="Texture" id=1]
[ext_resource path="res://pictures/gui/interaction/tile_interaction.png" type="Texture" id=2]
[resource] [resource]
0/name = "Plants 0" 0/name = "Plants 0"
@ -179,17 +178,3 @@
11/shape_one_way_margin = 0.0 11/shape_one_way_margin = 0.0
11/shapes = [ ] 11/shapes = [ ]
11/z_index = 0 11/z_index = 0
12/name = "tile_interaction.png 12"
12/texture = ExtResource( 2 )
12/tex_offset = Vector2( 0, 0 )
12/modulate = Color( 1, 1, 1, 1 )
12/region = Rect2( 0, 0, 32, 32 )
12/tile_mode = 0
12/occluder_offset = Vector2( 0, 0 )
12/navigation_offset = Vector2( 0, 0 )
12/shape_offset = Vector2( 0, 0 )
12/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
12/shape_one_way = false
12/shape_one_way_margin = 0.0
12/shapes = [ ]
12/z_index = 0

View File

@ -1,18 +1,13 @@
extends TileMap extends TileMap
onready var player = get_node("/root/Map1/Player") onready var player = get_node("/root/Map1/Player")
# 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 _get_cell_size(): func _get_cell_size():
return cell_size return cell_size
# use unhandled_input so that...
# 1. You aren't executing this every frame, even when there is no input
# 2. You don't interrupt global / GUI related input callbacks
func _unhandled_input(event): func _unhandled_input(event):
var pl_pos = player.position var pl_pos = player.position
var pl_pos_tile = Vector2(pl_pos.x / cell_size.x, pl_pos.y / cell_size.y) var pl_pos_tile = Vector2(pl_pos.x / cell_size.x, pl_pos.y / cell_size.y)

File diff suppressed because one or more lines are too long