Using tilemaplayer as grid
This commit is contained in:
@@ -7,7 +7,7 @@ class_name Grid
|
||||
# The of a cell in pixels
|
||||
@export var cellSize := Vector2(16, 16)
|
||||
|
||||
@export var cameraPosition := Vector2.ONE
|
||||
@export var cameraPosition := Vector2.ZERO
|
||||
func setCameraPosition(pos: Vector2):
|
||||
cameraPosition = pos
|
||||
@export var cameraZoom := Vector2(2, 2)
|
||||
@@ -24,14 +24,22 @@ var _halfCellSize: Vector2 = cellSize / 2
|
||||
|
||||
# Returns the position of a cell's center in pixels.
|
||||
# We'll place units and have them move through cells using this function.
|
||||
# Example:
|
||||
# cellSize = (32)
|
||||
# gridPosition = (2, 3)
|
||||
# cameraZoom = 1
|
||||
# (2,3) * 32 + 16
|
||||
# (64, 96) + 16
|
||||
# == (80, 112) <- This is the position ON THE SCREEN.
|
||||
func calculateMapPosition(gridPosition: Vector2) -> Vector2:
|
||||
return cameraPosition + (gridPosition * cellSize + _halfCellSize) / cameraZoom
|
||||
return (gridPosition * cellSize + _halfCellSize) / cameraZoom
|
||||
|
||||
# Returns the coordinates of the cell on the grid given a position on the map.
|
||||
# This is the complementary of `calculate_map_position()` above.
|
||||
# When designing a level, you'll place units visually in the editor. We'll use this function to find
|
||||
# the grid coordinates they're placed on, and call `calculate_map_position()` to snap them to the
|
||||
# cell's center.
|
||||
# This is the position IN THE GRID
|
||||
func calculateGridCoordinates(mapPosition: Vector2) -> Vector2:
|
||||
return (mapPosition / cellSize).floor()
|
||||
|
||||
|
||||
@@ -50,11 +50,21 @@ separation = Vector2i(1, 1)
|
||||
5:0/0/terrain = 0
|
||||
5:0/0/terrains_peering_bit/right_side = 0
|
||||
5:0/0/terrains_peering_bit/bottom_side = 0
|
||||
5:0/0/terrains_peering_bit/bottom_left_corner = 0
|
||||
5:0/0/terrains_peering_bit/left_side = 0
|
||||
5:0/0/terrains_peering_bit/top_left_corner = 0
|
||||
5:0/0/terrains_peering_bit/top_side = 0
|
||||
5:0/0/terrains_peering_bit/top_right_corner = 0
|
||||
6:0/0 = 0
|
||||
6:0/0/terrain_set = 0
|
||||
6:0/0/terrain = 0
|
||||
6:0/0/terrains_peering_bit/right_side = 0
|
||||
6:0/0/terrains_peering_bit/bottom_right_corner = 0
|
||||
6:0/0/terrains_peering_bit/bottom_side = 0
|
||||
6:0/0/terrains_peering_bit/left_side = 0
|
||||
6:0/0/terrains_peering_bit/top_left_corner = 0
|
||||
6:0/0/terrains_peering_bit/top_side = 0
|
||||
6:0/0/terrains_peering_bit/top_right_corner = 0
|
||||
7:0/0 = 0
|
||||
7:0/0/terrain_set = 0
|
||||
7:0/0/terrain = 0
|
||||
@@ -63,34 +73,52 @@ separation = Vector2i(1, 1)
|
||||
8:0/0/terrain_set = 0
|
||||
8:0/0/terrain = 3
|
||||
8:0/0/terrains_peering_bit/right_side = 3
|
||||
8:0/0/terrains_peering_bit/bottom_right_corner = 3
|
||||
8:0/0/terrains_peering_bit/bottom_side = 3
|
||||
9:0/0 = 0
|
||||
9:0/0/terrain_set = 0
|
||||
9:0/0/terrain = 3
|
||||
9:0/0/terrains_peering_bit/right_side = 3
|
||||
9:0/0/terrains_peering_bit/bottom_right_corner = 3
|
||||
9:0/0/terrains_peering_bit/bottom_side = 3
|
||||
9:0/0/terrains_peering_bit/bottom_left_corner = 3
|
||||
9:0/0/terrains_peering_bit/left_side = 3
|
||||
10:0/0 = 0
|
||||
10:0/0/terrain_set = 0
|
||||
10:0/0/terrain = 3
|
||||
10:0/0/terrains_peering_bit/bottom_side = 3
|
||||
10:0/0/terrains_peering_bit/bottom_left_corner = 3
|
||||
10:0/0/terrains_peering_bit/left_side = 3
|
||||
11:0/0 = 0
|
||||
11:0/0/terrain_set = 0
|
||||
11:0/0/terrain = 3
|
||||
11:0/0/terrains_peering_bit/right_side = 3
|
||||
11:0/0/terrains_peering_bit/bottom_side = 3
|
||||
12:0/0 = 0
|
||||
12:0/0/terrain_set = 0
|
||||
12:0/0/terrain = 3
|
||||
12:0/0/terrains_peering_bit/bottom_side = 3
|
||||
12:0/0/terrains_peering_bit/left_side = 3
|
||||
13:0/0 = 0
|
||||
13:0/0/terrain_set = 0
|
||||
13:0/0/terrain = 3
|
||||
13:0/0/terrains_peering_bit/right_side = 3
|
||||
13:0/0/terrains_peering_bit/bottom_side = 3
|
||||
13:0/0/terrains_peering_bit/bottom_left_corner = 3
|
||||
13:0/0/terrains_peering_bit/left_side = 3
|
||||
13:0/0/terrains_peering_bit/top_left_corner = 3
|
||||
13:0/0/terrains_peering_bit/top_side = 3
|
||||
13:0/0/terrains_peering_bit/top_right_corner = 3
|
||||
14:0/0 = 0
|
||||
14:0/0/terrain_set = 0
|
||||
14:0/0/terrain = 3
|
||||
14:0/0/terrains_peering_bit/right_side = 3
|
||||
14:0/0/terrains_peering_bit/bottom_right_corner = 3
|
||||
14:0/0/terrains_peering_bit/bottom_side = 3
|
||||
14:0/0/terrains_peering_bit/left_side = 3
|
||||
14:0/0/terrains_peering_bit/top_left_corner = 3
|
||||
14:0/0/terrains_peering_bit/top_side = 3
|
||||
14:0/0/terrains_peering_bit/top_right_corner = 3
|
||||
15:0/0 = 0
|
||||
15:0/0/terrain_set = 0
|
||||
15:0/0/terrain = 3
|
||||
@@ -147,12 +175,22 @@ separation = Vector2i(1, 1)
|
||||
5:1/0/terrain_set = 0
|
||||
5:1/0/terrain = 0
|
||||
5:1/0/terrains_peering_bit/right_side = 0
|
||||
5:1/0/terrains_peering_bit/bottom_right_corner = 0
|
||||
5:1/0/terrains_peering_bit/bottom_side = 0
|
||||
5:1/0/terrains_peering_bit/bottom_left_corner = 0
|
||||
5:1/0/terrains_peering_bit/left_side = 0
|
||||
5:1/0/terrains_peering_bit/top_left_corner = 0
|
||||
5:1/0/terrains_peering_bit/top_side = 0
|
||||
6:1/0 = 0
|
||||
6:1/0/terrain_set = 0
|
||||
6:1/0/terrain = 0
|
||||
6:1/0/terrains_peering_bit/right_side = 0
|
||||
6:1/0/terrains_peering_bit/bottom_right_corner = 0
|
||||
6:1/0/terrains_peering_bit/bottom_side = 0
|
||||
6:1/0/terrains_peering_bit/bottom_left_corner = 0
|
||||
6:1/0/terrains_peering_bit/left_side = 0
|
||||
6:1/0/terrains_peering_bit/top_side = 0
|
||||
6:1/0/terrains_peering_bit/top_right_corner = 0
|
||||
7:1/0 = 0
|
||||
7:1/0/terrain_set = 0
|
||||
7:1/0/terrain = 0
|
||||
@@ -162,37 +200,59 @@ separation = Vector2i(1, 1)
|
||||
8:1/0/terrain_set = 0
|
||||
8:1/0/terrain = 3
|
||||
8:1/0/terrains_peering_bit/right_side = 3
|
||||
8:1/0/terrains_peering_bit/bottom_right_corner = 3
|
||||
8:1/0/terrains_peering_bit/bottom_side = 3
|
||||
8:1/0/terrains_peering_bit/top_side = 3
|
||||
8:1/0/terrains_peering_bit/top_right_corner = 3
|
||||
9:1/0 = 0
|
||||
9:1/0/terrain_set = 0
|
||||
9:1/0/terrain = 3
|
||||
9:1/0/terrains_peering_bit/right_side = 3
|
||||
9:1/0/terrains_peering_bit/bottom_right_corner = 3
|
||||
9:1/0/terrains_peering_bit/bottom_side = 3
|
||||
9:1/0/terrains_peering_bit/bottom_left_corner = 3
|
||||
9:1/0/terrains_peering_bit/left_side = 3
|
||||
9:1/0/terrains_peering_bit/top_left_corner = 3
|
||||
9:1/0/terrains_peering_bit/top_side = 3
|
||||
9:1/0/terrains_peering_bit/top_right_corner = 3
|
||||
10:1/0 = 0
|
||||
10:1/0/terrain_set = 0
|
||||
10:1/0/terrain = 3
|
||||
10:1/0/terrains_peering_bit/bottom_side = 3
|
||||
10:1/0/terrains_peering_bit/bottom_left_corner = 3
|
||||
10:1/0/terrains_peering_bit/left_side = 3
|
||||
10:1/0/terrains_peering_bit/top_left_corner = 3
|
||||
10:1/0/terrains_peering_bit/top_side = 3
|
||||
11:1/0 = 0
|
||||
11:1/0/terrain_set = 0
|
||||
11:1/0/terrain = 3
|
||||
11:1/0/terrains_peering_bit/right_side = 3
|
||||
11:1/0/terrains_peering_bit/top_side = 3
|
||||
12:1/0 = 0
|
||||
12:1/0/terrain_set = 0
|
||||
12:1/0/terrain = 3
|
||||
12:1/0/terrains_peering_bit/left_side = 3
|
||||
12:1/0/terrains_peering_bit/top_side = 3
|
||||
13:1/0 = 0
|
||||
13:1/0/terrain_set = 0
|
||||
13:1/0/terrain = 3
|
||||
13:1/0/terrains_peering_bit/right_side = 3
|
||||
13:1/0/terrains_peering_bit/bottom_right_corner = 3
|
||||
13:1/0/terrains_peering_bit/bottom_side = 3
|
||||
13:1/0/terrains_peering_bit/bottom_left_corner = 3
|
||||
13:1/0/terrains_peering_bit/left_side = 3
|
||||
13:1/0/terrains_peering_bit/top_left_corner = 3
|
||||
13:1/0/terrains_peering_bit/top_side = 3
|
||||
14:1/0 = 0
|
||||
14:1/0/terrain_set = 0
|
||||
14:1/0/terrain = 3
|
||||
14:1/0/terrains_peering_bit/right_side = 3
|
||||
14:1/0/terrains_peering_bit/bottom_right_corner = 3
|
||||
14:1/0/terrains_peering_bit/bottom_side = 3
|
||||
14:1/0/terrains_peering_bit/bottom_left_corner = 3
|
||||
14:1/0/terrains_peering_bit/left_side = 3
|
||||
14:1/0/terrains_peering_bit/top_side = 3
|
||||
14:1/0/terrains_peering_bit/top_right_corner = 3
|
||||
15:1/0 = 0
|
||||
15:1/0/terrain_set = 0
|
||||
15:1/0/terrain = 3
|
||||
@@ -254,16 +314,20 @@ separation = Vector2i(1, 1)
|
||||
8:2/0/terrain = 3
|
||||
8:2/0/terrains_peering_bit/right_side = 3
|
||||
8:2/0/terrains_peering_bit/top_side = 3
|
||||
8:2/0/terrains_peering_bit/top_right_corner = 3
|
||||
9:2/0 = 0
|
||||
9:2/0/terrain_set = 0
|
||||
9:2/0/terrain = 3
|
||||
9:2/0/terrains_peering_bit/right_side = 3
|
||||
9:2/0/terrains_peering_bit/left_side = 3
|
||||
9:2/0/terrains_peering_bit/top_left_corner = 3
|
||||
9:2/0/terrains_peering_bit/top_side = 3
|
||||
9:2/0/terrains_peering_bit/top_right_corner = 3
|
||||
10:2/0 = 0
|
||||
10:2/0/terrain_set = 0
|
||||
10:2/0/terrain = 3
|
||||
10:2/0/terrains_peering_bit/left_side = 3
|
||||
10:2/0/terrains_peering_bit/top_left_corner = 3
|
||||
10:2/0/terrains_peering_bit/top_side = 3
|
||||
11:2/0 = 0
|
||||
11:2/0/terrain_set = 0
|
||||
@@ -274,7 +338,6 @@ separation = Vector2i(1, 1)
|
||||
12:2/0/terrain = 3
|
||||
12:2/0/terrains_peering_bit/right_side = 3
|
||||
12:2/0/terrains_peering_bit/left_side = 3
|
||||
12:2/0/terrains_peering_bit/top_side = 3
|
||||
13:2/0 = 0
|
||||
13:2/0/terrain_set = 0
|
||||
13:2/0/terrain = 3
|
||||
@@ -944,6 +1007,7 @@ terrain_set_0/terrain_3/name = "Pavement"
|
||||
terrain_set_0/terrain_3/color = Color(0.835294, 0.831373, 0.870588, 1)
|
||||
terrain_set_0/terrain_4/name = "Roof_1"
|
||||
terrain_set_0/terrain_4/color = Color(0.886275, 0.870588, 0.811765, 1)
|
||||
navigation_layer_0/layers = 1
|
||||
sources/1 = SubResource("TileSetAtlasSource_vqaso")
|
||||
pattern_0 = SubResource("TileMapPattern_vrbvq")
|
||||
pattern_1 = SubResource("TileMapPattern_07llt")
|
||||
|
||||
Reference in New Issue
Block a user