39 lines
1.1 KiB
GDScript3
39 lines
1.1 KiB
GDScript3
|
extends TileMap
|
||
|
|
||
|
@export var map_width = 13 # keep to a odd value
|
||
|
@export var map_height = 19 # keep to a odd value
|
||
|
|
||
|
func _ready():
|
||
|
draw_map()
|
||
|
|
||
|
func draw_map():
|
||
|
draw_ground()
|
||
|
draw_separation()
|
||
|
get_random_top_cell()
|
||
|
|
||
|
func draw_ground():
|
||
|
for x in range(map_width):
|
||
|
for y in range(map_height):
|
||
|
set_cell(0, Vector2i(x, y), 0, Vector2i(0, 0), 0)
|
||
|
|
||
|
# The tilemap is initially divided in two section
|
||
|
# One for the player (bottom section)
|
||
|
# One for the enemy (top section)
|
||
|
func draw_separation():
|
||
|
var middle_height = floor(map_height / 2.0)
|
||
|
for x in range(map_width):
|
||
|
set_cell(1, Vector2i(x - 1, middle_height - 1), 1, Vector2i(0, 0), 0) # why have we to add -1?
|
||
|
|
||
|
func get_top_spawn_cell() -> Vector2i:
|
||
|
return Vector2i(floor(map_width / 2.0), 1)
|
||
|
|
||
|
func get_bottom_spawn_cell() -> Vector2i:
|
||
|
return Vector2i(floor(map_width / 2.0), map_height - 2)
|
||
|
|
||
|
func get_random_top_cell() -> Vector2i:
|
||
|
var middle_height = floor(map_height / 2.0)
|
||
|
var rand_width = randi_range(0, map_width - 1)
|
||
|
var rand_height = randi_range(0, middle_height - 1)
|
||
|
#set_cell(0, Vector2i(rand_width, rand_height), 1, Vector2i(0, 0), 0)
|
||
|
return Vector2i(rand_width, rand_height)
|