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/default.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/default.go')
| -rw-r--r-- | examples/default.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/default.go b/examples/default.go new file mode 100644 index 0000000..d291a26 --- /dev/null +++ b/examples/default.go @@ -0,0 +1,40 @@ +package examples + +import ( + "image/color" + "time" + + "age_of_empires/engine" + "age_of_empires/physics" + "age_of_empires/selection" +) + +func init() { + Registry["default"] = Entry{ + Name: "Default", + Description: "Free play with a town center, iron mine, and gatherer units", + Build: buildDefault, + } +} + +func buildDefault(g *engine.Game, deps BuilderDeps) { + g.ResourceAmount = 150 + g.Camera = engine.Camera{X: 1000, Y: 1000, Zoom: 1.0} + g.CurrentAction = engine.Selecting + g.UnitBuilder = deps.UnitBuilder + + ironMineBuilder := engine.NewEntityBuilder(). + WithSolid(engine.NewFilledRectangleImage(physics.Point{X: 100, Y: 100}, color.RGBA{0x80, 0x80, 0x80, 0xff})). + WithResourceSource(1000). + WithSelectable("square", selection.Building) + g.Append(ironMineBuilder.WithPosition(physics.Point{X: 1000, Y: 1000}).Build()) + + townCenterBuilder := engine.NewEntityBuilder(). + WithSolid(engine.NewFilledRectangleImage(physics.Point{X: 100, Y: 100}, color.RGBA{0x0, 0x0, 0xff, 0xff})). + WithResourceStorage(). + WithSelectable("square", selection.Building). + WithSpawn(engine.NewSpawn(50, 1*time.Second)) + townCenter := g.Append(townCenterBuilder.WithPosition(physics.Point{X: 1000, Y: 2000}).Build()) + + _ = townCenter // suppress unused warning; future spawn loop will use it +} |
