diff --git a/addons/godot-git-plugin/win64/~libgit_plugin.windows.editor.x86_64.dll b/addons/godot-git-plugin/win64/~libgit_plugin.windows.editor.x86_64.dll deleted file mode 100644 index 47bbb1d..0000000 Binary files a/addons/godot-git-plugin/win64/~libgit_plugin.windows.editor.x86_64.dll and /dev/null differ diff --git a/scripts/isometric_map_layer_holder.gd b/scripts/isometric_map_layer_holder.gd index 441d019..d73bb1b 100644 --- a/scripts/isometric_map_layer_holder.gd +++ b/scripts/isometric_map_layer_holder.gd @@ -618,10 +618,15 @@ func init_player(): tile["visibility"] = true tile["unit"] = player_node tile["unit_type"] ="PC" - player_node.set_unit_position(tile["x"], tile["y"], tile["z"]) + var init_player_pos = iso_to_world(tile["x"], tile["y"], tile["z"]) + tile["unit"].set_unit_position(init_player_pos.x, init_player_pos.y, tile["z"]) - -func _on_player_z_layer_change_pressed() -> void: +func _move_up_or_down(up_or_down = "up"): + var z_offset = 0 + if up_or_down == "up": + z_offset = 1 + elif up_or_down == "down": + z_offset = -1 var new_z = 0 var new_y = 0 var new_x = 0 @@ -631,7 +636,7 @@ func _on_player_z_layer_change_pressed() -> void: for y in GRID_SIZE_LENGTH: tile = debug_map[x][y][z] if tile["unit_type"] == "PC": - new_z = z + 1 + new_z = z + z_offset new_y = y new_x = x break @@ -649,42 +654,42 @@ func _on_player_z_layer_change_pressed() -> void: new_player_tile["unit"] = player_node new_player_tile["visibility"] = true new_player_tile["unit_type"] ="PC" - player_node.set_unit_position(new_player_tile["x"], new_player_tile["y"], new_player_tile["z"]) + var new_player_pos = iso_to_world(tile["x"], tile["y"], tile["z"]) + new_player_tile["unit"].set_unit_position(new_player_pos.x, new_player_pos.y, tile["z"]) + + print(new_player_tile["x"], new_player_tile["y"], new_player_tile["z"]) + +func iso_to_world(tile_x, tile_y, player_z_layer = 0): + # Get the tile size from your tilemap + var tile_width = isometric_map_layers[player_z_layer].tile_set.tile_size.x + var tile_height = isometric_map_layers[player_z_layer].tile_set.tile_size.y + + # Calculate the world position + var world_x = (tile_x - tile_y) * (tile_width / 2) + var world_y = (tile_x + tile_y) * (tile_height / 2) - (player_z_layer * tile_height / 2) + + return Vector2(world_x, world_y) + +# Converts world position to isometric tile coordinates +func world_to_iso(world_pos, player_z_layer = 0): + # Get the tile size from your tilemap + var tile_width = isometric_map_layers[player_z_layer].tile_set.tile_size.x + var tile_height = isometric_map_layers[player_z_layer].tile_set.tile_size.y + + # Adjust y position based on z-layer + var adjusted_y = world_pos.y + (player_z_layer * tile_height / 2) + + # Calculate the tile coordinates + var tile_x = (world_pos.x / (tile_width / 2) + adjusted_y / (tile_height / 2)) / 2 + var tile_y = (adjusted_y / (tile_height / 2) - world_pos.x / (tile_width / 2)) / 2 + + return Vector2i(round(tile_x), round(tile_y)) + + + + +func _on_player_z_layer_change_pressed() -> void: + _move_up_or_down("up") - - func _on_player_z_layer_change_down_pressed() -> void: - var new_z = 0 - var new_y = 0 - var new_x = 0 - var tile = debug_map[0][0][0] - for z in GRID_SIZE_HEIGHT: - for x in GRID_SIZE_WIDTH: - for y in GRID_SIZE_LENGTH: - tile = debug_map[x][y][z] - if tile["unit_type"] == "PC": - new_z = z - 1 - new_y = 1 - new_x = 1 - break - if tile["unit_type"] == "PC": - print("y ", tile) - break - if tile["unit_type"] == "PC": - print("x ", tile) - break - if tile["unit_type"] == "PC": - print("z ", tile) - break - print("tile ", tile) - print("x ", new_x, " y ", new_y, " z ", new_z) - tile["unit"] = null - tile["unit_type"] = null - tile["visibility"] = null - - - var new_player_tile = debug_map[new_x][new_y][new_z] - new_player_tile["visibility"] = true - new_player_tile["unit"] = player_node - new_player_tile["unit_type"] ="PC" - player_node.set_unit_position(new_player_tile["x"], new_player_tile["y"], new_player_tile["z"]) + _move_up_or_down("down") diff --git a/scripts/player.gd b/scripts/player.gd index bb05704..867f446 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -15,6 +15,7 @@ var player_data = { } + func set_unit_position(x, y, z): var z_layer = z var x_position = x