Tree collisions and highlights

This commit is contained in:
Dan Baker 2025-06-26 18:28:33 +01:00
parent 57602adddb
commit 7255cbdf64
17 changed files with 231 additions and 2251 deletions

View file

@ -22,6 +22,6 @@ static func generate_cell(x: int, z: int, density: float, path: bool = false, wa
if not (path or water):
if density >= 0.6:
cell_data.add_trees(int(density * 10 / 3))
cell_data.add_trees(int(density * 10 / 2))
Global.map_data[x][z] = cell_data

View file

@ -1,53 +1,75 @@
extends Node
class_name RandomClass
var _rng: RandomNumberGenerator = RandomNumberGenerator.new()
# Static shared instance for all tiles to use
static var shared_instance: RandomClass = null
func _ready():
randomize()
randomize()
# Initialize shared instance if it doesn't exist
if shared_instance == null:
shared_instance = RandomClass.new()
# Static method to get the shared instance with a specific seed
static func get_seeded_instance(seed_value: int) -> RandomClass:
if shared_instance == null:
shared_instance = RandomClass.new()
shared_instance.set_seed(seed_value)
return shared_instance
# Static method to get the shared instance (without changing seed)
static func get_shared_instance() -> RandomClass:
if shared_instance == null:
shared_instance = RandomClass.new()
return shared_instance
# Set a specific seed for reproducible results
func set_seed(seed_value: int) -> void:
_rng.seed = seed_value
#Log.pr('Seeded RNG with ', seed_value)
_rng.seed = seed_value
# Randomize the seed (for non-reproducible results)
func randomize() -> void:
_rng.randomize()
_rng.randomize()
# Get the current seed value
func get_seed() -> int:
return _rng.seed
return _rng.seed
# Get a random integer between min and max (inclusive)
func randi_range(min_value: int, max_value: int) -> int:
return _rng.randi_range(min_value, max_value)
return _rng.randi_range(min_value, max_value)
# Get a random float between 0.0 and 1.0
func randf() -> float:
return _rng.randf()
return _rng.randf()
func randi() -> int:
return _rng.randi()
return _rng.randi()
# Get a random float between min and max
func randf_range(min_value: float, max_value: float) -> float:
return _rng.randf_range(min_value, max_value)
return _rng.randf_range(min_value, max_value)
# Get a random normalized vector
func random_unit_vector() -> Vector2:
return Vector2(randf_range(-1.0, 1.0), randf_range(-1.0, 1.0)).normalized()
return Vector2(randf_range(-1.0, 1.0), randf_range(-1.0, 1.0)).normalized()
# Get a random point inside a circle with radius 1
func random_point_in_circle() -> Vector2:
var r = sqrt(randf())
var theta = randf() * 2.0 * PI
return Vector2(r * cos(theta), r * sin(theta))
var r = sqrt(randf())
var theta = randf() * 2.0 * PI
return Vector2(r * cos(theta), r * sin(theta))
# Get a random point inside a circle with specified radius
func random_point_in_circle_with_radius(radius: float) -> Vector2:
return random_point_in_circle() * radius
return random_point_in_circle() * radius
# Get a random boolean value with specified probability
func random_bool(probability: float = 0.5) -> bool:
return randf() < probability
return randf() < probability