2D multiplayer platformer using Godot Engine
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.
 

58 lines
2.0 KiB

class_name GeneratorSimple
extends RefCounted
const NAME := "simple"
var noise := FastNoiseLite.new()
var array := PackedFloat32Array()
var bias_air := 0.0 # Above this, always air
var bias_solid := 64.0 # Below this, always solid
func _init() -> void:
noise.seed = randi()
noise.noise_type = FastNoiseLite.TYPE_SIMPLEX
noise.fractal_gain = 0.75
noise.fractal_lacunarity = 2.5
noise.fractal_octaves = 3
array.resize((Chunk.SIZE + 1) * (Chunk.SIZE + 1))
func generate(world: World, chunk: Chunk) -> void:
var i := 0
for y in Chunk.SIZE + 1:
for x in Chunk.SIZE + 1:
var local_pos := Vector2i(x, y)
var block_pos := (chunk.chunk_pos * Chunk.SIZE) + local_pos
var bias := (block_pos.y - bias_air) / (bias_solid - bias_air)
array[i] = noise.get_noise_2dv(Vector2(block_pos)) + bias
i += 1
var matter: Matter.Layer = chunk.get_or_create_layer(Matter)
var shapes: Shape.Layer = chunk.get_or_create_layer(Shape)
for local_pos in BlockRegion.LOCAL_CHUNK:
var shape: Shape
match _values(local_pos):
[ true, true, true, true ]: shape = Shape.FULL
[ false, true, true, true ]: shape = Shape.Base.SLOPE.variants[0]
[ true, false, true, true ]: shape = Shape.Base.SLOPE.variants[2]
[ true, true, false, true ]: shape = Shape.Base.SLOPE.variants[3]
[ true, true, true, false ]: shape = Shape.Base.SLOPE.variants[1]
[ false, false, true, true ]: shape = Shape.Base.HALF.variants[0]
[ true, false, false, true ]: shape = Shape.Base.HALF.variants[2]
[ true, true, false, false ]: shape = Shape.Base.HALF.variants[3]
[ false, true, true, false ]: shape = Shape.Base.HALF.variants[1]
if shape:
matter.set_at(local_pos, Matter.PLASTIC)
shapes.set_at(local_pos, shape)
func _values(pos: Vector2i) -> Array[bool]:
return [
_v(pos, 0, 0) >= 0.5,
_v(pos, 1, 0) >= 0.5,
_v(pos, 1, 1) >= 0.5,
_v(pos, 0, 1) >= 0.5,
]
func _v(pos: Vector2i, x: float, y: float) -> float:
return array[(pos.x + x) + (pos.y + y) * (Chunk.SIZE + 1)]