basic scene switching added
This commit is contained in:
parent
bf2a5b8cf1
commit
7ae1e86f9d
22
Global.gd
22
Global.gd
@ -3,6 +3,26 @@ extends Node2D
|
|||||||
var ShowInventory = 0
|
var ShowInventory = 0
|
||||||
var LeftClick = 0
|
var LeftClick = 0
|
||||||
var player_inventory_items = []
|
var player_inventory_items = []
|
||||||
|
var river_intersection_home_2 = preload("res://river_intersection_home2.tscn").instance()
|
||||||
|
var inventory_screen = preload("res://MiscScenes/Inventory.tscn").instance()
|
||||||
|
var current_scene = null
|
||||||
|
#func _add_a_scene_manually():
|
||||||
|
# # This is like autoloading the scene, only
|
||||||
|
# # it happens after already loading the main scene.
|
||||||
|
# get_tree().get_root().add_child(simultaneous_scene)
|
||||||
|
|
||||||
|
func GoToScene(scene):
|
||||||
|
if current_scene != null:
|
||||||
|
get_tree().get_root().remove_child(current_scene)
|
||||||
|
match scene:
|
||||||
|
"river_intersection_home_2":
|
||||||
|
current_scene = river_intersection_home_2
|
||||||
|
get_tree().get_root().add_child(river_intersection_home_2)
|
||||||
|
#.change_scene_to(river_intersection_home_2)
|
||||||
|
"inventory_screen":
|
||||||
|
current_scene = inventory_screen
|
||||||
|
get_tree().get_root().add_child(inventory_screen)
|
||||||
|
|
||||||
|
|
||||||
func LoadSave():
|
func LoadSave():
|
||||||
Database.OpenConnection()
|
Database.OpenConnection()
|
||||||
@ -11,4 +31,6 @@ func _input(event):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
get_tree().get_root().add_child(river_intersection_home_2)
|
||||||
|
get_tree().get_root().add_child(inventory_screen)
|
||||||
pass
|
pass
|
||||||
|
@ -28,16 +28,14 @@ func _physics_process(delta):
|
|||||||
velocity.x = 0
|
velocity.x = 0
|
||||||
velocity.y = 0
|
velocity.y = 0
|
||||||
move_and_slide(velocity, Vector2(0, -1))
|
move_and_slide(velocity, Vector2(0, -1))
|
||||||
if(interaction.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y)) == -1):
|
# if(interaction.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y)) == -1):
|
||||||
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
|
#Handles interaction with the map
|
||||||
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))
|
var x = plants_map.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y))
|
||||||
# if x > 0:
|
|
||||||
# print("woo")
|
|
||||||
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):
|
||||||
|
3
Menu.gd
3
Menu.gd
@ -5,4 +5,5 @@ func _ready():
|
|||||||
|
|
||||||
func _on_Btn_PlayGame_pressed():
|
func _on_Btn_PlayGame_pressed():
|
||||||
Global.LoadSave()
|
Global.LoadSave()
|
||||||
get_tree().change_scene("res://river_intersection_home2.tscn")
|
Global.GoToScene("river_intersection_home_2")
|
||||||
|
|
||||||
|
@ -33,4 +33,4 @@ func _input(event):
|
|||||||
holding_item.global_position = get_global_mouse_position()
|
holding_item.global_position = get_global_mouse_position()
|
||||||
|
|
||||||
func _on_TouchScreenButton_pressed():
|
func _on_TouchScreenButton_pressed():
|
||||||
get_tree().change_scene("res://river_intersection_home2.tscn")
|
Global.GoToScene("river_intersection_home_2")
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
|
var id = 0
|
||||||
# Many thanks to Arkeve! https://github.com/arkeve
|
# Many thanks to Arkeve! https://github.com/arkeve
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
if randi() % 3 == 0:
|
match Global.player_inventory_items[self.id].item_id:
|
||||||
$TextureRect.texture = load("res://pictures/inventory_iconpictures/miscellaneous/magic_formulae.png")
|
0:
|
||||||
else:
|
pass
|
||||||
$TextureRect.texture = load("res://pictures/inventory_iconpictures/tools_and_weapons/tools/ploeg.png")
|
1:
|
||||||
|
$TextureRect.texture = load("res://pictures/inventory_iconpictures/miscellaneous/magic_formulae.png")
|
||||||
|
2:
|
||||||
|
$TextureRect.texture = load("res://pictures/inventory_iconpictures/tools_and_weapons/tools/ploeg.png")
|
||||||
|
@ -23,11 +23,9 @@ func _ready():
|
|||||||
#default_style.texture = default_tex
|
#default_style.texture = default_tex
|
||||||
#empty_style.texture = empty_tex
|
#empty_style.texture = empty_tex
|
||||||
# print(self.get)
|
# print(self.get)
|
||||||
# if randi() % 2 == 0:
|
|
||||||
print(Global.player_inventory_items)
|
|
||||||
print(Global.player_inventory_items[self.id])
|
|
||||||
if Global.player_inventory_items[self.id] != null:
|
if Global.player_inventory_items[self.id] != null:
|
||||||
item = ItemClass.instance()
|
item = ItemClass.instance()
|
||||||
|
item.set("id", self.id)
|
||||||
add_child(item)
|
add_child(item)
|
||||||
# refresh_style()
|
# refresh_style()
|
||||||
|
|
||||||
|
@ -10,11 +10,38 @@ var verbose = true
|
|||||||
func _ready():
|
func _ready():
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
func CreateWorldDatabase():
|
||||||
|
print("Creating new database")
|
||||||
|
var player_inventory : Dictionary = Dictionary()
|
||||||
|
player_inventory["id"] = {"data_type":"int", "primary_key": true, "not_null": true} #slot id
|
||||||
|
player_inventory["item_id"] = {"data_type":"int", "not_null": true} #item id
|
||||||
|
player_inventory["item_name"] = {"data_type":"text", "not_null": true} #item name
|
||||||
|
player_inventory["amount"] = {"data_type":"int", "not_null": true} #amount
|
||||||
|
player_inventory["shortdesc"] = {"data_type":"char(80)", "not_null": true} #short description
|
||||||
|
db.create_table("player_inventory", player_inventory)
|
||||||
|
var items : Dictionary = Dictionary()
|
||||||
|
for i in range(40):
|
||||||
|
items["id"] = i
|
||||||
|
items["item_id"] = 0
|
||||||
|
items["item_name"] = "No Item"
|
||||||
|
items["amount"] = 0
|
||||||
|
items["shortdesc"] = "No item here"
|
||||||
|
|
||||||
|
# Insert a new row in the table
|
||||||
|
db.insert_row("player_inventory", items)
|
||||||
|
items.clear()
|
||||||
|
|
||||||
func OpenConnection():
|
func OpenConnection():
|
||||||
self.db = SQLite.new()
|
self.db = SQLite.new()
|
||||||
|
var file = File.new()
|
||||||
self.db.path = path
|
self.db.path = path
|
||||||
self.db.verbose_mode = verbose
|
self.db.verbose_mode = verbose
|
||||||
|
var create = false
|
||||||
|
if !file.file_exists(path):
|
||||||
|
create = true
|
||||||
self.db.open_db()
|
self.db.open_db()
|
||||||
|
if create:
|
||||||
|
CreateWorldDatabase()
|
||||||
|
|
||||||
func OpenConnectionIfClosed():
|
func OpenConnectionIfClosed():
|
||||||
if self.db == null:
|
if self.db == null:
|
||||||
@ -23,8 +50,7 @@ func OpenConnectionIfClosed():
|
|||||||
func GetInventoryItems():
|
func GetInventoryItems():
|
||||||
OpenConnectionIfClosed()
|
OpenConnectionIfClosed()
|
||||||
var ret = []
|
var ret = []
|
||||||
for x in range(40):
|
ret = db.select_rows("player_inventory", "",["*"])
|
||||||
ret.append([x, "test"])
|
|
||||||
return ret
|
return ret
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
#func _process(delta):
|
#func _process(delta):
|
||||||
|
Binary file not shown.
@ -23,4 +23,4 @@ func _unhandled_input(event):
|
|||||||
|
|
||||||
|
|
||||||
func _on_Inventory_pressed():
|
func _on_Inventory_pressed():
|
||||||
get_tree().change_scene("res://MiscScenes/Inventory.tscn")
|
Global.GoToScene("inventory_screen")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user