More World Generation, more Camera, other stuff.
This commit is contained in:
33
scenes/main/grid.gd
Normal file
33
scenes/main/grid.gd
Normal file
@@ -0,0 +1,33 @@
|
||||
class_name Grid
|
||||
extends Node2D
|
||||
|
||||
@export var width: int = 12
|
||||
@export var height: int = 12
|
||||
@export var cell_size: int = 128
|
||||
|
||||
@export var show_debug: bool = false
|
||||
|
||||
var grid: Dictionary = {}
|
||||
|
||||
func generateGrid():
|
||||
for x in width:
|
||||
for y in height:
|
||||
grid[Vector2(x,y)] = null
|
||||
if show_debug:
|
||||
var rect = ReferenceRect.new()
|
||||
rect.position = gridToWorld(Vector2(x,y))
|
||||
rect.size = Vector2(cell_size, cell_size)
|
||||
rect.editor_only = false
|
||||
$Debug.add_child(rect)
|
||||
var label = Label.new()
|
||||
label.position = gridToWorld(Vector2(x,y))
|
||||
label.text = str(Vector2(x,y))
|
||||
$Debug.add_child(label)
|
||||
|
||||
|
||||
func gridToWorld(_pos: Vector2) -> Vector2:
|
||||
return _pos * cell_size
|
||||
|
||||
|
||||
func worldToGrid(_pos: Vector2) -> Vector2:
|
||||
return floor(_pos / cell_size)
|
||||
Reference in New Issue
Block a user