mouse pos

This commit is contained in:
Squishy Bloob 2024-03-23 08:41:02 +00:00
parent d01ce82106
commit b330bfa184
3 changed files with 17 additions and 5 deletions

2
go.mod
View File

@ -4,6 +4,6 @@ go 1.22.1
require ( require (
github.com/askeladdk/aseprite v0.0.4 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 golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81
) )

2
go.sum
View File

@ -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/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 h1:lx8syOA2ccXlgViYkQe2Kn/4xt+p9mdd1Qc/yYMrmSo=
github.com/veandco/go-sdl2 v0.4.38/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= 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 h1:6R2FC06FonbXQ8pK11/PDFY6N6LWlf9KlzibaCapmqc=
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ= 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= golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=

18
run.go
View File

@ -9,7 +9,7 @@ import (
type Runnable interface { type Runnable interface {
Init(settings *Settings) Init(settings *Settings)
Render(screen *Image) Render(screen *Image)
Update() Update(bloob *Bloob)
} }
type Settings struct { type Settings struct {
@ -19,6 +19,10 @@ type Settings struct {
Title string Title string
} }
type Bloob struct {
MousePos Vec2i
}
func Run(game Runnable) { func Run(game Runnable) {
_ = sdl.Init(sdl.INIT_EVERYTHING) _ = sdl.Init(sdl.INIT_EVERYTHING)
defer sdl.Quit() defer sdl.Quit()
@ -30,6 +34,8 @@ func Run(game Runnable) {
Title: "Blooblib", Title: "Blooblib",
} }
bloob := Bloob{}
game.Init(&settings) game.Init(&settings)
window, _ := sdl.CreateWindow( window, _ := sdl.CreateWindow(
@ -57,10 +63,14 @@ func Run(game Runnable) {
running := true running := true
for running { for running {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch event.(type) { switch event := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
break break
case sdl.MouseMotionEvent:
bloob.MousePos.X = int(event.X) / settings.Scale
bloob.MousePos.Y = int(event.Y) / settings.Scale
break
} }
} }
now := time.Now() now := time.Now()
@ -73,7 +83,7 @@ func Run(game Runnable) {
delta2 := now.Sub(lastFrame) delta2 := now.Sub(lastFrame)
if delta2 >= frameDuration { if delta2 >= frameDuration {
game.Update() game.Update(&bloob)
game.Render(screen) game.Render(screen)
windowImage.DrawUpscale(screen) windowImage.DrawUpscale(screen)
framesSinceLastSecond += 1 framesSinceLastSecond += 1