Everything lived in one flat directory, so a diff gave no clue what area it touched and finding the file you wanted meant knowing its exact name. Twelve folders now, grouped by what a thing IS rather than what type it is - a vessel's definition, its component scenes and its upgrade resources sit together, because that is the set you read when you change one of them. buildings core controllers enemies logistics planets resources shaders surface ui vessels vfx world 332 files moved and every res:// reference rewritten - 306 files touched, including the autoload and main-scene paths in project.godot. Nothing renamed: this is purely where files sit, so the diff is a pile of pure moves and no behaviour is buried in it. ui_theme.tres, icon.svg and web_shell.html stay at the root, where Godot and the export preset expect them. Verified three ways, because a suite alone would not have caught all of it: the full 117 pass, the web export builds clean, and the game renders. The export is why that matters. The FIRST export after the move failed with "Attempt to open script 'res://GameState.gd'" - the old path - while project.godot on disk plainly said res://core/GameState.gd. That is this project's documented Android FUSE mtime trap: Godot served a cached copy of a file whose content had changed. A `touch` fixed it. Nothing in the test suite would have found that, because the suite runs from a copy on a native filesystem - the one place the bug cannot happen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
94 lines
3.3 KiB
GDScript
94 lines
3.3 KiB
GDScript
extends Area2D
|
|
|
|
# A drifting rock that can be shot apart for the ore inside it.
|
|
#
|
|
# Asteroids used to be pure hazard: they could only ever cost you a ship. Now
|
|
# they are also the one resource you can reach without conquering anything,
|
|
# which is what the fleet's guns are for out in open space.
|
|
#
|
|
# Two ways to destroy one, and they are deliberately NOT the same:
|
|
# - shot apart, which yields the ore
|
|
# - flown into, which does not. The rock shatters against a hull instead of
|
|
# being mined, and you have just lost a ship (or a shield charge) for it.
|
|
# Without that split, a shield vessel could farm asteroids by ramming.
|
|
|
|
const ROCK_SCENE: PackedScene = preload("res://surface/Rock.tscn")
|
|
# Shots needed to crack one open. Low enough that a single vessel clears one
|
|
# in a couple of bursts, high enough that a stray shot in passing does not.
|
|
const HIT_POINTS: int = 2
|
|
# How long the dropped ore survives if nobody comes for it. Surface rocks live
|
|
# forever because a planet surface is bounded and hand-authored; open space is
|
|
# not, and an asteroid field shot up and left behind would otherwise leak
|
|
# nodes for the rest of the session.
|
|
const DROP_LIFETIME: float = 60.0
|
|
|
|
var velocity: Vector2 = Vector2.ZERO
|
|
var rotation_speed: float = 0.0
|
|
var hp: int = HIT_POINTS
|
|
|
|
var shape_points: PackedVector2Array = PackedVector2Array()
|
|
|
|
|
|
func _ready() -> void:
|
|
randomize()
|
|
add_to_group("asteroids")
|
|
area_entered.connect(_on_area_entered)
|
|
|
|
var point_count: int = 7
|
|
for i in range(point_count):
|
|
var angle: float = (float(i) / point_count) * TAU
|
|
var radius: float = randf_range(14.0, 22.0)
|
|
shape_points.append(Vector2(cos(angle), sin(angle)) * radius)
|
|
queue_redraw()
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
# Deliberately no queue_redraw() here. position and rotation are node
|
|
# TRANSFORM properties - Godot applies them when rendering, and the
|
|
# polygon built in _ready() is in local space, so it never changes.
|
|
# Redrawing each frame re-tessellated four antialiased polylines per
|
|
# asteroid for an identical result; with ~150 asteroids on screen that
|
|
# was the single largest source of stutter.
|
|
position += velocity * delta
|
|
rotation += rotation_speed * delta
|
|
|
|
|
|
# Same contract as Enemy.take_damage, so every weapon that already knows how
|
|
# to hurt an enemy can hurt an asteroid without learning a second protocol.
|
|
func take_damage(amount: int) -> bool:
|
|
hp -= maxi(amount, 1)
|
|
if hp > 0:
|
|
return false
|
|
shatter(true)
|
|
return true
|
|
|
|
|
|
func shatter(drop_ore: bool) -> void:
|
|
AsteroidExplosionVFX.spawn(get_tree().root, position)
|
|
if drop_ore:
|
|
_drop_ore()
|
|
queue_free()
|
|
|
|
|
|
func _drop_ore() -> void:
|
|
var rock: Node2D = ROCK_SCENE.instantiate()
|
|
rock.build_shape(randi())
|
|
rock.position = position
|
|
rock.lifetime = DROP_LIFETIME
|
|
# Inherits the asteroid's drift, so the ore carries on along the path the
|
|
# rock it came from was already travelling instead of stopping dead in
|
|
# space - which reads as debris rather than as a spawned pickup.
|
|
rock.velocity = velocity
|
|
# Deferred: this runs from inside an area_entered signal, where the
|
|
# physics server is mid-flush and refuses a direct add_child.
|
|
get_parent().add_child.call_deferred(rock)
|
|
|
|
|
|
func _on_area_entered(area: Area2D) -> void:
|
|
if area.is_in_group("player_ships"):
|
|
# No ore: see the note at the top of this file.
|
|
shatter(false)
|
|
|
|
|
|
func _draw() -> void:
|
|
NeonDraw.draw_glowing_polygon(self, shape_points, Color(0.65, 0.5, 0.35), 1.0)
|