You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Gridmap/scripts/World.gd

65 lines
1.9 KiB

extends Node
class_name World
var heightMap: Array
var temperatureMap: Array
var moistureMap: Array
var blocs: Array
var entities: Array
var width: int
var height: int
func get_neighbours_8_at_same_height(point: Vector2):
var neighbours = 0
var current_bloc = heightMap[point.x][point.y]
if heightMap[point.x-1][point.y-1] == current_bloc:
neighbours += Global.directions_8.TOP_LEFT
if heightMap[point.x][point.y-1] == current_bloc:
neighbours += Global.directions_8.TOP
if heightMap[point.x+1][point.y-1] == current_bloc:
neighbours += Global.directions_8.TOP_RIGHT
if heightMap[point.x+1][point.y] == current_bloc:
neighbours += Global.directions_8.RIGHT
if heightMap[point.x+1][point.y+1] == current_bloc:
neighbours += Global.directions_8.BOTTOM_RIGHT
if heightMap[point.x][point.y+1] == current_bloc:
neighbours += Global.directions_8.BOTTOM
if heightMap[point.x-1][point.y+1] == current_bloc:
neighbours += Global.directions_8.BOTTOM_LEFT
if heightMap[point.x-1][point.y] == current_bloc:
neighbours += Global.directions_8.LEFT
return neighbours
func get_neighbours_4_at_same_height(point: Vector2):
var neighbours = 0
var current_bloc = heightMap[point.x][point.y]
if heightMap[point.x][point.y-1] == current_bloc:
neighbours += Global.directions_4.TOP
if heightMap[point.x+1][point.y] == current_bloc:
neighbours += Global.directions_4.RIGHT
if heightMap[point.x][point.y+1] == current_bloc:
neighbours += Global.directions_4.BOTTOM
if heightMap[point.x-1][point.y] == current_bloc:
neighbours += Global.directions_4.LEFT
return neighbours
func get_bloc(point: Vector2):
var bloc = {
"x" = point.x,
"y" = heightMap[point.x][point.y],
"z" = point.y
}
for key in blocs[point.x][point.y].keys():
bloc[key] = blocs[point.x][point.y][key]
return bloc
func add_entity(position: Vector2):
entities.append(Entity.new(position))
blocs[position.x][position.y]["entity"] = entities.size()
pass