Skip to content

Commit

Permalink
prevent moving window out of bounds
Browse files Browse the repository at this point in the history
Still a bug in KDE: taskbar pushes the boundary inward but that
difference isn't reflected in ebiten.ScreenSizeInFullscreen().
  • Loading branch information
nhanb committed Sep 17, 2023
1 parent 4375d5a commit f5eb120
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Position struct{ x, y int }

var DurationTillHungry time.Duration
var WalkChance, StopChance int
var WindowWidth, WindowHeight int

type Vector struct{ x, y int }

Expand Down Expand Up @@ -118,9 +119,11 @@ func main() {
DurationTillHungry = time.Duration(secondsUntilHungryFlag) * 1_000_000_000

ebiten.SetWindowPosition(xFlag, yFlag)
ebiten.SetWindowSize(SPRITE_X*sizeFlag, SPRITE_Y*sizeFlag)
WindowWidth = SPRITE_X * sizeFlag
WindowHeight = SPRITE_Y * sizeFlag
ebiten.SetWindowSize(WindowWidth, WindowHeight)
ebiten.SetWindowTitle("Shark!")
//ebiten.SetWindowDecorated(false)
ebiten.SetWindowDecorated(false)
ebiten.SetWindowFloating(true)

AppIcon, _ := must.Two(image.Decode(bytes.NewReader(IconFile)))
Expand Down
4 changes: 4 additions & 0 deletions states.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/hajimehoshi/ebiten/v2/inpututil"
)

var screenW, screenH = ebiten.ScreenSizeInFullscreen()

type StateMachine struct {
state State
anim *Anim
Expand Down Expand Up @@ -48,6 +50,8 @@ func (sm *StateMachine) Update() error {

sm.state.Update(sm)

sm.x = min(max(sm.x, 0), screenW-WindowWidth)
sm.y = min(max(sm.y, 0), screenH-WindowHeight)
ebiten.SetWindowPosition(sm.x, sm.y)

// Advance to next animation frame
Expand Down

0 comments on commit f5eb120

Please sign in to comment.