Initial commit: SpaceshipTest, a top-down space RTS in Godot 4.7.1
A fleet of neon-outlined ships explores a procedurally generated, seeded infinite world: tap/joystick steering, pinch zoom, formation pivoting, planet landings, an ore economy with extractors and haulers, and player built structures (mothership, ship crafter, command centre). All art is hand-drawn with draw_* calls rather than textures, and the backgrounds are camera-relative shaders so they stay precise at large world coordinates. Includes a 35-test headless suite (tests/run_tests.sh) plus screenshot tooling that renders real frames through Xvfb and Mesa softpipe, since --headless has no GPU. Excluded from version control: .godot/ (import cache, and it holds export credentials), builds/, android/build/ and packaged APKs - all regenerable, and ~325 MB combined. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
commit
85814ce88c
192 changed files with 9602 additions and 0 deletions
93
PlanetField.gd
Normal file
93
PlanetField.gd
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
extends Node2D
|
||||
|
||||
# Spawns "Big Stable Asteroid" planets in ASTEROID_FIELD biome chunks near
|
||||
# the fleet where WorldGen says one belongs, and despawns them once the
|
||||
# fleet has moved far enough away - mirrors AsteroidField's chunk-lifecycle
|
||||
# pattern, but at a sparser, larger-radius scale since planets are rare
|
||||
# landmarks rather than common decoration.
|
||||
|
||||
@export var check_interval: float = 1.0
|
||||
@export var spawn_radius_chunks: int = 3
|
||||
@export var despawn_radius_chunks: int = 6
|
||||
|
||||
@onready var fleet: Node2D = get_node("../Fleet")
|
||||
|
||||
var planet_scene: PackedScene = preload("res://Planet.tscn")
|
||||
var populated_chunks: Dictionary = {}
|
||||
var timer: float = 0.0
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
timer += delta
|
||||
if timer < check_interval:
|
||||
return
|
||||
timer = 0.0
|
||||
update_chunks()
|
||||
|
||||
|
||||
func get_planet_fleet_is_on() -> Node2D:
|
||||
# Fleet centroid distance, not per-ship Area2D overlap - a single
|
||||
# stable number instead of many independently-noisy ship positions.
|
||||
# See Planet.gd for why this matters.
|
||||
var fleet_centroid: Vector2 = fleet.get_centroid()
|
||||
for chunk in populated_chunks.keys():
|
||||
for planet in populated_chunks[chunk]:
|
||||
if is_instance_valid(planet) and planet.position.distance_to(fleet_centroid) <= planet.landing_radius:
|
||||
return planet
|
||||
return null
|
||||
|
||||
|
||||
func update_chunks() -> void:
|
||||
# Public (not just called from _process's own timer): also invoked
|
||||
# once synchronously right after the fleet is positioned on a fresh
|
||||
# Main.tscn load, so a nearby planet exists immediately instead of
|
||||
# only appearing ~check_interval seconds later - most noticeable as a
|
||||
# jarring pop-in right after returning from a planet's surface.
|
||||
var center_chunk: Vector2i = WorldGen.chunk_coords(fleet.get_centroid())
|
||||
|
||||
for dx in range(-spawn_radius_chunks, spawn_radius_chunks + 1):
|
||||
for dy in range(-spawn_radius_chunks, spawn_radius_chunks + 1):
|
||||
var chunk: Vector2i = center_chunk + Vector2i(dx, dy)
|
||||
if populated_chunks.has(chunk):
|
||||
continue
|
||||
if not WorldGen.has_planet_at_chunk(chunk):
|
||||
continue
|
||||
_spawn_chunk_planet(chunk)
|
||||
|
||||
var to_remove: Array = []
|
||||
for chunk in populated_chunks.keys():
|
||||
if _chebyshev_chunk_distance(chunk, center_chunk) > despawn_radius_chunks:
|
||||
for planet in populated_chunks[chunk]:
|
||||
if is_instance_valid(planet):
|
||||
planet.queue_free()
|
||||
to_remove.append(chunk)
|
||||
for chunk in to_remove:
|
||||
populated_chunks.erase(chunk)
|
||||
|
||||
|
||||
func _chebyshev_chunk_distance(a: Vector2i, b: Vector2i) -> int:
|
||||
return max(abs(a.x - b.x), abs(a.y - b.y))
|
||||
|
||||
|
||||
func _spawn_chunk_planet(chunk: Vector2i) -> void:
|
||||
# WorldGen.planet_data_at_chunk() is seeded purely from the chunk's own
|
||||
# coordinates, so a given chunk always produces the exact same planet -
|
||||
# name, position within the chunk, and shape - no matter how many times
|
||||
# it's despawned and respawned across a scene reload. It's also the
|
||||
# same function the world map uses to place a marker for a
|
||||
# not-currently-loaded explored chunk, so the two never disagree.
|
||||
var data: Dictionary = WorldGen.planet_data_at_chunk(chunk)
|
||||
var origin: Vector2 = WorldGen.chunk_origin(chunk)
|
||||
|
||||
var planet: Node2D = planet_scene.instantiate()
|
||||
planet.position = origin + data.local_pos
|
||||
planet.planet_name = data.name
|
||||
planet.shape_seed = data.shape_seed
|
||||
# Deferred: update_chunks() can run synchronously from inside a
|
||||
# parent's own _ready() chain (forced once right after the fleet is
|
||||
# positioned, to avoid a pop-in on scene load) - Godot refuses a
|
||||
# direct add_child() while the tree is still "busy setting up
|
||||
# children" in that situation, so this must be deferred either way.
|
||||
get_parent().add_child.call_deferred(planet)
|
||||
|
||||
populated_chunks[chunk] = [planet]
|
||||
Loading…
Reference in a new issue