diff --git a/go.mod b/go.mod index c085d46..9614e38 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,6 @@ go 1.22.1 require ( github.com/askeladdk/aseprite v0.0.4 - github.com/veandco/go-sdl2 v0.4.38 + github.com/veandco/go-sdl2 v0.5.0-alpha.4.0.20240323054118-79669ab74d94 golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 ) diff --git a/go.sum b/go.sum index 663b411..e343de5 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,8 @@ github.com/askeladdk/aseprite v0.0.4/go.mod h1:lVW4EwZ7lgQjeHp7MhYj1NII5a/yLYyvA github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/veandco/go-sdl2 v0.4.38 h1:lx8syOA2ccXlgViYkQe2Kn/4xt+p9mdd1Qc/yYMrmSo= github.com/veandco/go-sdl2 v0.4.38/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= +github.com/veandco/go-sdl2 v0.5.0-alpha.4.0.20240323054118-79669ab74d94 h1:7Ay2TWWqg2J4mqPj6vgbg9ib7OzO37szAnQ48MmdD/Y= +github.com/veandco/go-sdl2 v0.5.0-alpha.4.0.20240323054118-79669ab74d94/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 h1:6R2FC06FonbXQ8pK11/PDFY6N6LWlf9KlzibaCapmqc= golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ= golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= diff --git a/run.go b/run.go index 632c46f..bcc6dec 100644 --- a/run.go +++ b/run.go @@ -9,7 +9,7 @@ import ( type Runnable interface { Init(settings *Settings) Render(screen *Image) - Update() + Update(bloob *Bloob) } type Settings struct { @@ -19,6 +19,10 @@ type Settings struct { Title string } +type Bloob struct { + MousePos Vec2i +} + func Run(game Runnable) { _ = sdl.Init(sdl.INIT_EVERYTHING) defer sdl.Quit() @@ -30,6 +34,8 @@ func Run(game Runnable) { Title: "Blooblib", } + bloob := Bloob{} + game.Init(&settings) window, _ := sdl.CreateWindow( @@ -57,10 +63,14 @@ func Run(game Runnable) { running := true for running { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { - switch event.(type) { - case *sdl.QuitEvent: + switch event := event.(type) { + case sdl.QuitEvent: running = false break + case sdl.MouseMotionEvent: + bloob.MousePos.X = int(event.X) / settings.Scale + bloob.MousePos.Y = int(event.Y) / settings.Scale + break } } now := time.Now() @@ -73,7 +83,7 @@ func Run(game Runnable) { delta2 := now.Sub(lastFrame) if delta2 >= frameDuration { - game.Update() + game.Update(&bloob) game.Render(screen) windowImage.DrawUpscale(screen) framesSinceLastSecond += 1