Skip to content

Instantly share code, notes, and snippets.

@namishelex01
Created April 20, 2025 13:33
Show Gist options
  • Save namishelex01/5d7894ea8d0379c6f22556191a57584c to your computer and use it in GitHub Desktop.
Save namishelex01/5d7894ea8d0379c6f22556191a57584c to your computer and use it in GitHub Desktop.
# world.gd
extends Node2D
class_name World
const TILE_SIZE = 32
const SEA_LEVEL = 0.0
const RENDER_DISTANCE = 16.0
@export var altitude_noise: FastNoiseLite
@export var tile: PackedScene
func _ready():
for n in RENDER_DISTANCE:
# We divide by two so that half the tiles
# generate left/above center and half right/below
var x = n - RENDER_DISTANCE / 2.0
for m in RENDER_DISTANCE:
var y = m - RENDER_DISTANCE / 2.0
generate_terrain_tile(x, y)
func generate_terrain_tile(x: int, y: int):
var tile = tile.instantiate()
tile.tile_type = altitude_value(x, y)
tile.position = Vector2(x, y) * TILE_SIZE
add_child(tile)
func altitude_value(x: int, y: int) -> Tile.TileType:
var value = altitude_noise.get_noise_2d(x, y)
if value >= SEA_LEVEL:
return Tile.TileType.LAND
return Tile.TileType.SEA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment