From d9a54f1319cc9dcc2861cecc9edfde14cf039c5b Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sat, 6 Jun 2026 20:59:12 +0200 Subject: Add examples catalog with subcommand dispatch - Extract game engine from package main to engine/ library package - Create examples/ package with registry, Entry type, and BuilderDeps - Register default world as an example (moved from main()) - Add combat example: two teams of units facing each other - Rewrite main.go as thin dispatch: go run . example [name] - Update README with examples catalog one-liner --- spawn.go | 53 ----------------------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 spawn.go (limited to 'spawn.go') diff --git a/spawn.go b/spawn.go deleted file mode 100644 index 87624fb..0000000 --- a/spawn.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "log/slog" - "time" - - "age_of_empires/ecs" - "age_of_empires/monad" - "age_of_empires/physics" -) - -type SpawnRequest struct { - Start time.Time -} - -type Spawn struct { - UnitResourceCost int - UnitSpawnDuration time.Duration - Requests []SpawnRequest - SpawnTarget monad.Option[physics.Point] -} - -func NewSpawn(unitResourceCost int, unitSpawnDuration time.Duration) Spawn { - return Spawn{ - UnitResourceCost: unitResourceCost, - UnitSpawnDuration: unitSpawnDuration, - Requests: make([]SpawnRequest, 0), - } -} - -func UpdateSpawnSystem(g *Game, now time.Time, masks []ecs.Mask, spawns []Spawn, positions []physics.Point) { - required := ecs.CM_Position | ecs.CM_Spawn - for i, mask := range masks { - if mask&required == required { - spawn := &spawns[i] - position := positions[i] - if len(spawn.Requests) == 0 || now.Sub(spawn.Requests[0].Start) < time.Duration(spawn.UnitSpawnDuration) { - continue - } - spawnPosition, _ := physics.Closest(position, physics.AdjacentPoints(position), g.getMoveMap()) - unit := g.Append(g.UnitBuilder.WithPosition(spawnPosition).Build()) - slog.Info("Spawned unit") - if spawn.SpawnTarget.Ok { - slog.Info("Unit has spawn target") - MainAction(g, unit, spawn.SpawnTarget.Value, g.getMoveMap()) - } - spawn.Requests = spawn.Requests[1:] - if len(spawn.Requests) > 0 { - spawn.Requests[0].Start = now - } - } - } -} -- cgit v1.3