diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-06-06 20:59:12 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-06-06 20:59:12 +0200 |
| commit | d9a54f1319cc9dcc2861cecc9edfde14cf039c5b (patch) | |
| tree | 74df791d6eda0ffe6c09cb32e5ffd76c4849cbac /examples/combat.go | |
| parent | 18592fd9f520a33ab307e496b995c1a7bf284893 (diff) | |
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
Diffstat (limited to 'examples/combat.go')
| -rw-r--r-- | examples/combat.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/combat.go b/examples/combat.go new file mode 100644 index 0000000..f2dd92f --- /dev/null +++ b/examples/combat.go @@ -0,0 +1,42 @@ +package examples + +import ( + "image/color" + + "age_of_empires/engine" + "age_of_empires/physics" + "age_of_empires/selection" +) + +func init() { + Registry["combat"] = Entry{ + Name: "Combat", + Description: "Two groups of units facing each other — ready for battle", + Build: buildCombat, + } +} + +func buildCombat(g *engine.Game, deps BuilderDeps) { + g.ResourceAmount = 500 + g.Camera = engine.Camera{X: 800, Y: 1000, Zoom: 1.0} + g.CurrentAction = engine.Selecting + g.UnitBuilder = deps.UnitBuilder + + // Red team (left) + redBuilder := engine.NewEntityBuilder(). + WithSolid(engine.NewFilledCircleImage(100, color.RGBA{0xff, 0x00, 0x00, 0xff})). + WithSelectable("round", selection.Unit). + WithMove().WithOrder().WithResourceGatherer(15) + for x := 0; x < 5; x++ { + g.Append(redBuilder.WithPosition(physics.Point{X: 200 + x*120, Y: 1000}).Build()) + } + + // Blue team (right) + blueBuilder := engine.NewEntityBuilder(). + WithSolid(engine.NewFilledCircleImage(100, color.RGBA{0x00, 0x00, 0xff, 0xff})). + WithSelectable("round", selection.Unit). + WithMove().WithOrder().WithResourceGatherer(15) + for x := 0; x < 5; x++ { + g.Append(blueBuilder.WithPosition(physics.Point{X: 1000 + x*120, Y: 1000}).Build()) + } +} |
