aboutsummaryrefslogtreecommitdiff
path: root/engine/input.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-06-06 20:59:12 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-06-06 20:59:12 +0200
commitd9a54f1319cc9dcc2861cecc9edfde14cf039c5b (patch)
tree74df791d6eda0ffe6c09cb32e5ffd76c4849cbac /engine/input.go
parent18592fd9f520a33ab307e496b995c1a7bf284893 (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 'engine/input.go')
-rw-r--r--engine/input.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/engine/input.go b/engine/input.go
new file mode 100644
index 0000000..5d03b08
--- /dev/null
+++ b/engine/input.go
@@ -0,0 +1,36 @@
+package engine
+
+import (
+ "age_of_empires/physics"
+
+ "github.com/hajimehoshi/ebiten/v2"
+ "github.com/hajimehoshi/ebiten/v2/inpututil"
+)
+
+type Input struct {
+ Cursor physics.Point
+ ScreenCursor physics.Point
+
+ EscapePressed bool
+ PatrolPressed bool
+
+ LeftMouseDown bool
+ LeftMouseUp bool
+ RightMouseUp bool
+
+ SpawnPressed bool
+}
+
+func CollectInput(camera *Camera) Input {
+ sx, sy := ebiten.CursorPosition()
+ return Input{
+ Cursor: camera.ScreenToWorld(sx, sy),
+ ScreenCursor: physics.Point{X: sx, Y: sy},
+ EscapePressed: inpututil.IsKeyJustReleased(ebiten.KeyEscape),
+ PatrolPressed: inpututil.IsKeyJustReleased(KeyPatrolRequest),
+ LeftMouseDown: inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft),
+ LeftMouseUp: inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonLeft),
+ RightMouseUp: inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonRight),
+ SpawnPressed: inpututil.IsKeyJustReleased(KeySpawnRequest),
+ }
+}