Working on tilemap

This commit is contained in:
Jonathan Herrewijnen 2022-10-15 21:33:54 +02:00
parent 4d6ac271c0
commit 6a9483042b
4 changed files with 21 additions and 23 deletions

View File

@ -17,8 +17,7 @@ func load_scene(map_data):
map_name = map_data map_name = map_data
var scene = load(map_data+".tscn") var scene = load(map_data+".tscn")
print("MAP NAME ",map_data+".tscn") print("MAP NAME ",map_data+".tscn")
var map = scene.instance() return scene.instance()
return map
func AddInventoryItem(itemid, amount): func AddInventoryItem(itemid, amount):
for x in range(40): for x in range(40):

View File

@ -4,11 +4,10 @@ const GRAVITY = 0.0
const WALK_SPEED = 200 const WALK_SPEED = 200
const interaction_circle_size = 150 const interaction_circle_size = 150
#onready var background_map = get_node("/root/base_scene/background") #onready var background_map = get_node("/root/base_scene/background")
onready var background_map = get_parent().get_node("background") onready var background_map = get_node("../background")
#onready var background_map = get_node("background") onready var vegetation_map = get_node("../vegetation")
onready var vegetation_map = get_parent().get_node("vegetation") onready var interaction_map = get_node("../interaction_map")
onready var interaction_map = get_parent().get_node("interaction_map") onready var player_interaction_map = get_node("../player_interaction")
onready var player_interaction_map = get_parent().get_node("player_interaction")
onready var cell_size = background_map._get_cell_size() onready var cell_size = background_map._get_cell_size()
var velocity = Vector2() var velocity = Vector2()
@ -42,11 +41,18 @@ func _physics_process(delta):
Global.current_camera.Update() Global.current_camera.Update()
func InteractWithCell(): func InteractWithCell():
for _i in self.get_children(): for _i in self.get_parent().get_children():
print(_i) print("Nodes visible ",_i)
print(background_map) if _i is TileMap:
print(interaction_map) print("Checking ", _i)
var plant_cell_mouse = interaction_map.get_cell(int(world_position[0] / cell_size.x), int(world_position[0] / cell_size.y)) for x in 300:
for y in 300:
if _i.get_cell(x, y) != -1:
print(_i.get_cell(x, y))
# else:
# _i.set_cell(x, y, 1)
var plant_cell_mouse = interaction_map.get_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y))
var plant_cell_character = interaction_map.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y)) var plant_cell_character = interaction_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(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y)) var background_cell = background_map.get_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y))
@ -54,12 +60,12 @@ func InteractWithCell():
print("plant cell mouse line 1: ", interaction_map.get_cell(12, 36)) print("plant cell mouse line 1: ", interaction_map.get_cell(12, 36))
print('plant_cell_mouse=',plant_cell_mouse,' | plant_cell_character=', plant_cell_character,' | background_cell=', background_cell,' | interaction_cell=',interaction_cell) print('plant_cell_mouse=',plant_cell_mouse,' | plant_cell_character=', plant_cell_character,' | background_cell=', background_cell,' | interaction_cell=',interaction_cell)
GlobalGameFunctions.SoundOnInteraction(self, "standard")
if plant_cell_mouse > 0 and plant_cell_mouse % 2 == 0: if plant_cell_mouse > 0 and plant_cell_mouse % 2 == 0:
Global.AddInventoryItem(plant_cell_mouse/2, 1) Global.AddInventoryItem(plant_cell_mouse/2, 1)
interaction_map.set_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y), (plant_cell_mouse-1)) interaction_map.set_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y), (plant_cell_mouse-1))
AnimationOnInteraction(1) AnimationOnInteraction(1)
GlobalGameFunctions.SoundOnInteraction(self, "standard")
Global.Save() Global.Save()
elif plant_cell_character > 0 and plant_cell_character % 2 == 0: elif plant_cell_character > 0 and plant_cell_character % 2 == 0:
Global.AddInventoryItem(plant_cell_character/2, 1) Global.AddInventoryItem(plant_cell_character/2, 1)

View File

@ -1,14 +1,7 @@
extends TouchScreenButton extends TouchScreenButton
#func _input(always):
func _physics_process(delta): func _physics_process(delta):
if Input.is_action_pressed("move_left") and Input.is_action_pressed("move_right"): if Input.is_action_pressed("move_left") and Input.is_action_pressed("move_right"):
show() show()
elif Input.is_action_pressed("ui_end"): elif Input.is_action_pressed("ui_end"):
hide() hide()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

View File

@ -10,9 +10,9 @@ 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)
var pl_tile = get_cellv(pl_pos_tile) var pl_tile = get_cellv(pl_pos_tile)
if event == Input.action_press("map_interaction"): # if event == Input.action_press("map_interaction"):
if(pl_tile != -1): # if(pl_tile != -1):
set_cellv(pl_pos_tile, -1) # set_cellv(pl_pos_tile, -1)
func _on_Settings_pressed(): func _on_Settings_pressed():
Global.GoToScene("menu") Global.GoToScene("menu")