extends Node2D # ===================== # CONFIG # ===================== const TILE_SIZE := 32 const WORLD_WIDTH := 16 const WORLD_HEIGHT := 16 const TICK_RATE := 1.0 # seconds per simulation tick # ===================== # TILE TYPES # ===================== enum TileType { FOREST, CITY, INDUSTRIAL, FARM, ENERGY, WASTE } # ===================== # TILE DATA STRUCT # ===================== class Tile: var type: TileType var population := 0 var pollution := 0.0 var energy := 0.0 var stability := 100.0 var sprite := ColorRect.new() func _init(t: TileType, pos: Vector2): type = t sprite.size = Vector2(TILE_SIZE, TILE_SIZE) sprite.position = pos _initialize_stats() _update_color() func _initialize_stats(): match type: TileType.FOREST: pollution = -1 stability = 120 TileType.CITY: population = 1000 pollution = 2 energy = -4 TileType.INDUSTRIAL: pollution = 6 energy = 12 stability = 80 TileType.FARM: population = 300 pollution = 1 TileType.ENERGY: energy = 20 pollution = 3 TileType.WASTE: pollution = 12 stability = 40 func _update_color(): match type: TileType.FOREST: sprite.color = Color.GREEN TileType.CITY: sprite.color = Color.DIM_GRAY TileType.INDUSTRIAL: sprite.color = Color.ORANGE TileType.FARM: sprite.color = Color.YELLOW TileType.ENERGY: sprite.color = Color.CYAN TileType.WASTE: sprite.color = Color.DARK_RED # ===================== # WORLD STATE # ===================== var world := [] var tick_timer := 0.0 var global_population := 0 var global_pollution := 0.0 var global_energy := 0.0 # Future tech flags var fusion_unlocked := false var teleportation_unlocked := false # ===================== # READY # ===================== func _ready(): _generate_world() print("Simulation running...") # ===================== # PROCESS LOOP # ===================== func _process(delta): tick_timer += delta if tick_timer >= TICK_RATE: tick_timer = 0 _simulation_tick() # ===================== # WORLD GENERATION # ===================== func _generate_world(): for x in WORLD_WIDTH: world.append([]) for y in WORLD_HEIGHT: var tile_type := TileType.FOREST if randi() % 10 < 2: tile_type = TileType.CITY elif randi() % 10 < 2: tile_type = TileType.INDUSTRIAL elif randi() % 10 < 1: tile_type = TileType.ENERGY var tile := Tile.new(tile_type, Vector2(x, y) * TILE_SIZE) add_child(tile.sprite) world[x].append(tile) # ===================== # SIMULATION TICK # ===================== func _simulation_tick(): global_population = 0 global_pollution = 0 global_energy = 0 for column in world: for tile in column: _update_tile(tile) global_population += tile.population global_pollution += tile.pollution global_energy += tile.energy _check_loss_conditions() _unlock_future_tech() print("POP:", global_population, " POL:", int(global_pollution), " ENG:", int(global_energy)) # ===================== # TILE UPDATE LOGIC # ===================== func _update_tile(tile: Tile): # Population growth / decline if tile.energy > 0 and tile.pollution < 5: tile.population += 5 else: tile.population -= 3 tile.population = max(tile.population, 0) # Stability decay tile.stability -= tile.pollution * 0.05 # Tile collapse if tile.stability <= 0: tile.type = TileType.WASTE tile.population = 0 tile.energy = 0 tile.pollution = 15 tile._update_color() # ===================== # FUTURE TECH UNLOCKS # ===================== func _unlock_future_tech(): if global_energy > 500 and not fusion_unlocked: fusion_unlocked = true print("FUSION POWER UNLOCKED") if global_population > 20000 and not teleportation_unlocked: teleportation_unlocked = true print("TELEPORTATION UNLOCKED") if fusion_unlocked: _apply_fusion_bonus() # ===================== # FUSION EFFECT # ===================== func _apply_fusion_bonus(): for column in world: for tile in column: if tile.type == TileType.ENERGY: tile.energy += 5 tile.pollution -= 1 # ===================== # LOSS CONDITIONS # ===================== func _check_loss_conditions(): if global_population <= 0: print("❌ EXTINCTION — GAME OVER") get_tree().quit() if global_pollution > 2000: print("❌ PLANETARY ECOLOGICAL COLLAPSE — GAME OVER") get_tree().quit()