42 lines
984 B
GDScript
42 lines
984 B
GDScript
class_name Chunk
|
|
|
|
var tiles : Array[int]
|
|
var position : Vector2i
|
|
|
|
var items : Dictionary[Vector2i, Item]
|
|
var arrows : Dictionary[Vector2i, Arrow]
|
|
|
|
func _init(position : Vector2i) -> void:
|
|
self.position = position
|
|
|
|
var noise : FastNoiseLite = FastNoiseLite.new()
|
|
noise.noise_type = FastNoiseLite.TYPE_PERLIN
|
|
noise.fractal_type = FastNoiseLite.FRACTAL_FBM
|
|
|
|
noise.seed = Globals.seed
|
|
noise.frequency = 0.025
|
|
|
|
noise.fractal_octaves = 5
|
|
noise.fractal_lacunarity = 2
|
|
noise.fractal_gain = 0.5
|
|
|
|
var x : int = 0
|
|
var y : int = 0
|
|
|
|
var offset : Vector2i = position * TileGlobals.chunk_size
|
|
|
|
for i in range(TileGlobals.chunk_size ** 2):
|
|
if x >= TileGlobals.chunk_size:
|
|
x = 0
|
|
y += 1
|
|
|
|
var point_value : float = remap(noise.get_noise_2d(x+offset.x,y+offset.y), -1, 1, 0, 1)
|
|
var tile_id : int = TileGlobals.chunk_gradient.sample(point_value).r8
|
|
|
|
tiles.append(tile_id)
|
|
|
|
x += 1
|
|
|
|
func get_tile(pos : Vector2i):
|
|
return tiles[pos.y * TileGlobals.chunk_size + pos.x]
|