Compare commits
2 Commits
b330bfa184
...
cf6d0a9832
Author | SHA1 | Date |
---|---|---|
Squishy Bloob | cf6d0a9832 | |
Squishy Bloob | 5fbb9b3545 |
Binary file not shown.
After Width: | Height: | Size: 240 B |
2
go.sum
2
go.sum
|
@ -1,8 +1,6 @@
|
|||
github.com/askeladdk/aseprite v0.0.4 h1:/k1VTiDkPORnrzonUUV5oXWwdHBoYjIIYJ1K/PupNMU=
|
||||
github.com/askeladdk/aseprite v0.0.4/go.mod h1:lVW4EwZ7lgQjeHp7MhYj1NII5a/yLYyvAo7COPIn3WY=
|
||||
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=
|
||||
|
|
31
run.go
31
run.go
|
@ -1,14 +1,15 @@
|
|||
package bloob
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Runnable interface {
|
||||
Init(settings *Settings)
|
||||
Render(screen *Image)
|
||||
Init(bloob *Bloob, settings *Settings)
|
||||
Render(bloob *Bloob, screen *Image)
|
||||
Update(bloob *Bloob)
|
||||
}
|
||||
|
||||
|
@ -21,8 +22,14 @@ type Settings struct {
|
|||
|
||||
type Bloob struct {
|
||||
MousePos Vec2i
|
||||
Cursor *Image
|
||||
}
|
||||
|
||||
var DefaultCursor *Image
|
||||
|
||||
//go:embed "cursor.png"
|
||||
var defaultCursorBytes []byte
|
||||
|
||||
func Run(game Runnable) {
|
||||
_ = sdl.Init(sdl.INIT_EVERYTHING)
|
||||
defer sdl.Quit()
|
||||
|
@ -34,9 +41,15 @@ func Run(game Runnable) {
|
|||
Title: "Blooblib",
|
||||
}
|
||||
|
||||
bloob := Bloob{}
|
||||
if DefaultCursor == nil {
|
||||
DefaultCursor = LoadImageBytes(defaultCursorBytes)
|
||||
}
|
||||
|
||||
game.Init(&settings)
|
||||
bloob := Bloob{
|
||||
Cursor: DefaultCursor,
|
||||
}
|
||||
|
||||
game.Init(&bloob, &settings)
|
||||
|
||||
window, _ := sdl.CreateWindow(
|
||||
settings.Title,
|
||||
|
@ -51,13 +64,14 @@ func Run(game Runnable) {
|
|||
screen := NewImage(settings.WindowSize)
|
||||
screen.Alpha = false
|
||||
|
||||
sdl.ShowCursor(sdl.DISABLE)
|
||||
|
||||
_ = window.UpdateSurface()
|
||||
|
||||
lastSecond := time.Now()
|
||||
framesSinceLastSecond := 0
|
||||
|
||||
targetFPS := 60
|
||||
frameDuration := time.Second / time.Duration(targetFPS)
|
||||
frameDuration := time.Second / time.Duration(settings.TargetFps)
|
||||
lastFrame := lastSecond
|
||||
|
||||
running := true
|
||||
|
@ -84,7 +98,10 @@ func Run(game Runnable) {
|
|||
delta2 := now.Sub(lastFrame)
|
||||
if delta2 >= frameDuration {
|
||||
game.Update(&bloob)
|
||||
game.Render(screen)
|
||||
game.Render(&bloob, screen)
|
||||
if bloob.Cursor != nil {
|
||||
screen.Draw(bloob.Cursor, bloob.MousePos)
|
||||
}
|
||||
windowImage.DrawUpscale(screen)
|
||||
framesSinceLastSecond += 1
|
||||
lastFrame = lastFrame.Add(frameDuration)
|
||||
|
|
Loading…
Reference in New Issue