aboutsummaryrefslogtreecommitdiff
path: root/input.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-05-07 12:07:02 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-05-07 12:07:02 +0200
commit20abde4dd780b51840e3498336bf907f0fd9164c (patch)
treea00d0fd7997651a1123bfbc9ccecb29d39615f1d /input.go
parent5c2d9ea10c9ed41fee41067c6d0d8d7fade8297c (diff)
Add Input abstraction between ebiten and simulation update
Introduces Input snapshot struct collected once per tick via CollectInput, and UpdateSimulation(Input) as the ebiten-free simulation entrypoint. Integration tests now drive the game through simulated inputs rather than direct method calls. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'input.go')
-rw-r--r--input.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/input.go b/input.go
new file mode 100644
index 0000000..5b9be32
--- /dev/null
+++ b/input.go
@@ -0,0 +1,36 @@
+package main
+
+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),
+ }
+}