xonecas.ioDon't click! Sean Caetano Martin Sign in

space-browser / commits / 261f7b4

feat: start burn, players die now

xonecas5 weeks ago261f7b4a25bbaa91696c6aed6299f5b5b9fa061eparent 171db702 files changed

GAME_DESIGN.md+2-2
@@ -57,7 +57,7 @@ Inspired by the amber/sepia monospace terminal animation of `xonecas.io`. The wo
5757
5858 Every POI has a clear gameplay function. Nothing decorative.
5959
60-- **Stars:** Deadly cosmic hazards at the heart of each system. Colliding with a star destroys ship pieces on contact.
60+- **Stars:** Deadly cosmic hazards at the heart of each system. A piece that overlaps a star burns, losing hit points every second it stays in the heat, so a glancing pass costs armour and a careless one costs the pieces that went in.
6161 - **Planets:** Orbit stars. Every planet is one of two kinds.
6262 - **Shipyard Planets:** Provide refuelling, crafting, upgrading, and repairing. Common in the central spawn systems and increasingly rare toward the galaxy edges in a smooth progression.
6363 - **Barren Planets:** The ore bodies of the galaxy. While anchored in orbit around a barren planet, the player automatically pulls physical ore out of it at a steady rate per second (no "collect ore" menu clicks). Each planet holds a finite amount and regrows it over time, so a single planet cannot be farmed forever — plenty is what makes you move.
@@ -132,7 +132,7 @@ Combat is frequent, automated, and controlled purely through movement and positi
132132 3. **Tow, Stash & Build:** Tow ore (`Circles + 1`) to a Shipyard Planet (or hide stashes in space) to craft and upgrade pieces, dragging them directly onto your ship graph.
133133 4. **Expedition Outward:** Use the Galaxy Map to plot fuel-efficient Deep Space routes into the fog of war. Fight or cross Rogue AI packs that grow as Shipyard Planets and Galaxy Security disappear.
134134 5. **Endgame Rim:** Reach the treacherous outer edges to find rare edge Shipyards and craft **Star** pieces, the only way to survive a run that keeps going.
135-6. **Permadeath:** Run ends when the root piece reaches 0 HP, hits a star, self-destructs, or disconnects past the grace window. Your ship pieces and towed cargo remain in space as a persistent wreck named after your callsign, while all map discoveries and named bodies endure for future runs.
135+6. **Permadeath:** Run ends when the root piece reaches 0 HP, self-destructs, or disconnects past the grace window. Your ship pieces and towed cargo remain in space as a persistent wreck named after your callsign, while all map discoveries and named bodies endure for future runs. A dead run is replaced at once: the same callsign deploys again with a brand new ship in the core, and the wreck it left stays where it died.
136136
137137 ---
138138
server/main.go+71-6
@@ -48,12 +48,14 @@ const (
4848 oreWaitMax = 60.0
4949 oreHolds = 3 // a barren planet holds 3-6 ore, a fixed count per planet
5050
51- dockR = 8.0 // the ship counts as docked inside this of its ring point
52- towBase = 3 // ore a hull can haul with no circle at all
53- towPer = 3 // extra ore each circle adds to the line
54- maxTier = 2 // a piece can be upgraded twice
55- yardOre = 3 // ore a shipyard takes for one service
56- yardGap = 1.0 // seconds between services, so a full line drains visibly
51+ pieceR = 11.0 // world radius of a piece, for star heat overlap
52+ burn = 5.0 // hit points a second a piece loses inside a star
53+ dockR = 8.0 // the ship counts as docked inside this of its ring point
54+ towBase = 3 // ore a hull can haul with no circle at all
55+ towPer = 3 // extra ore each circle adds to the line
56+ maxTier = 2 // a piece can be upgraded twice
57+ yardOre = 3 // ore a shipyard takes for one service
58+ yardGap = 1.0 // seconds between services, so a full line drains visibly
5759 )
5860
5961 // A hull is a graph of pieces placed relative to the ship. Piece ids are unique
@@ -477,6 +479,39 @@ func (h *hub) sever(p *player, gone map[int]bool) []*loose {
477479 return off
478480 }
479481
482+// A star is not instant death: its heat eats whatever of the hull actually enters
483+// it, so brushing the limb costs armour and lingering costs the run. A piece is hit
484+// by its own outline, not the ship's centre, so a big rig can lose an outer piece
485+// while the root stays clear.
486+func (h *hub) burn(p *player, dt float64) {
487+ var dead []int
488+ for i := range p.Pieces {
489+ q := &p.Pieces[i]
490+ x, y := hullToWorld(p, q.LX, q.LY)
491+ if !h.hot(x, y) {
492+ continue
493+ }
494+ q.HP = math.Max(0, q.HP-burn*dt)
495+ if q.HP == 0 {
496+ dead = append(dead, q.ID)
497+ }
498+ }
499+ for _, id := range dead {
500+ h.destroy(p, id) // the dead piece and whatever only it held on
501+ }
502+}
503+
504+// A point is hot once it sits past a star's surface, with a piece's own girth
505+// taken into account, so only real overlap burns.
506+func (h *hub) hot(x, y float64) bool {
507+ for _, b := range h.bodies {
508+ if b.Kind == "star" && math.Hypot(b.X-x, b.Y-y) < b.R+pieceR {
509+ return true
510+ }
511+ }
512+ return false
513+}
514+
480515 // A piece at zero hit points is destroyed for good: the hull loses it, and
481516 // whatever it was the only link to breaks off as wreckage.
482517 func (h *hub) destroy(p *player, id int) {
@@ -490,6 +525,32 @@ func (h *hub) destroy(p *player, id int) {
490525 }
491526 }
492527
528+// Losing the root piece ends that life. Everything still bolted to the hull is left
529+// where the ship died as loose wreckage, the tow line goes slack, and the callsign
530+// comes back at the spawn in a brand new ship under a new player id, so the client
531+// snaps there instead of sliding out of its own corpse.
532+func (h *hub) respawn(p *player) *player {
533+ for _, q := range p.Pieces[1:] { // the dead root piece is gone, not salvage
534+ x, y := hullToWorld(p, q.LX, q.LY)
535+ h.loose = append(h.loose, &loose{ID: q.ID, Kind: q.Kind, X: x, Y: y, H: p.H,
536+ HP: q.HP, MaxHP: q.MaxHP, Tier: q.Tier})
537+ }
538+ for _, id := range p.tow {
539+ if o := h.oreByID(id); o != nil {
540+ o.Towed = 0 // dropped where the line was
541+ }
542+ }
543+ if l := h.looseByID(p.held); l != nil {
544+ l.held = 0
545+ }
546+ h.nextID++
547+ q := &player{ID: h.nextID, Name: p.Name, // the callsign outlives the ship
548+ X: spawnX, Y: spawnY, TX: spawnX, TY: spawnY}
549+ q.Pieces = []piece{h.fitted("triangle", 0)} // every life starts from one triangle
550+ q.Fuel = q.fuel()
551+ return q
552+}
553+
493554 // Snap a dropped piece onto the free slot closest to where it was let go.
494555 func (h *hub) attach(p *player, l *loose) bool {
495556 lx, ly := hullToLocal(p, l.X, l.Y)
@@ -582,6 +643,7 @@ func (h *hub) step(dt float64) {
582643 p.TY = p.ox*sn + p.oy*cs
583644 }
584645 p.steer(dt)
646+ h.burn(p, dt)
585647 h.haul(p)
586648 p.Fuel = p.fuel()
587649 if b := h.body(p.orbit); b != nil && b.Kind == "shipyard" && p.docked() {
@@ -592,6 +654,9 @@ func (h *hub) step(dt float64) {
592654 h.onLine(o, p, float64(i+1))
593655 }
594656 }
657+ if p.Pieces[0].HP == 0 {
658+ c.p = h.respawn(p) // the root piece is the run itself
659+ }
595660 }
596661 }