Fix Scroll-Follow-Actor Behavior

* The scrollbox by which the game follows the player character has been
  revised, it is now an offset away from the window's center instead of
  fixed pixel distances from the window's edges.
* Mobile form-factor (Pinephone) now scrolls OK instead of jerking back
  and forth rapidly when moving left.
loading-screen
Noah 2021-06-13 20:25:42 -07:00
parent c5e3fc297c
commit e6b71f5512
2 changed files with 21 additions and 16 deletions

View File

@ -1,5 +1,7 @@
package balance
import "git.kirsle.net/go/render"
// Numbers.
var (
// Window dimensions.
@ -10,12 +12,10 @@ var (
CanvasScrollSpeed = 8
// Window scrolling behavior in Play Mode.
// DEPRECATED: pixels close to window edges
ScrollboxHoz = 256 // horizontal px from window border to start scrol
ScrollboxVert = 160
// NEW: set scrollbox bounds by percents
ScrollboxHozPercent float64 = 0.25
ScrollboxVertPercent float64 = 0.40
ScrollboxOffset = render.Point{ // from center of screen
X: 40,
Y: 100,
}
// Player speeds
PlayerMaxVelocity float64 = 6

View File

@ -6,6 +6,7 @@ import (
"git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/level"
"git.kirsle.net/apps/doodle/pkg/shmem"
"git.kirsle.net/go/render"
"git.kirsle.net/go/render/event"
)
@ -110,8 +111,12 @@ func (w *Canvas) loopFollowActor(ev *event.State) error {
}
var (
VP = w.Viewport()
// ScrollboxHoz = VP.
VP = w.Viewport()
engine = shmem.CurrentRenderEngine
Width, Height = engine.WindowSize()
midpoint = render.NewPoint(Width/2, Height/2)
scrollboxHoz = midpoint.X - balance.ScrollboxOffset.X
scrollboxVert = midpoint.Y - balance.ScrollboxOffset.Y
)
// Find the actor.
@ -127,8 +132,8 @@ func (w *Canvas) loopFollowActor(ev *event.State) error {
)
// Scroll left
if APosition.X <= VP.X+balance.ScrollboxHoz {
var delta = VP.X + balance.ScrollboxHoz - APosition.X
if APosition.X <= VP.X+scrollboxHoz {
var delta = VP.X + scrollboxHoz - APosition.X
// constrain in case they're FAR OFF SCREEN so we don't flip back around
if delta < 0 {
@ -138,14 +143,14 @@ func (w *Canvas) loopFollowActor(ev *event.State) error {
}
// Scroll right
if APosition.X >= VP.W-ASize.W-balance.ScrollboxHoz {
var delta = VP.W - ASize.W - APosition.X - balance.ScrollboxHoz
if APosition.X >= VP.W-ASize.W-scrollboxHoz {
var delta = VP.W - ASize.W - APosition.X - scrollboxHoz
scrollBy.X = delta
}
// Scroll up
if APosition.Y <= VP.Y+balance.ScrollboxVert {
var delta = VP.Y + balance.ScrollboxVert - APosition.Y
if APosition.Y <= VP.Y+scrollboxVert {
var delta = VP.Y + scrollboxVert - APosition.Y
if delta < 0 {
delta = -delta
@ -154,8 +159,8 @@ func (w *Canvas) loopFollowActor(ev *event.State) error {
}
// Scroll down
if APosition.Y >= VP.H-ASize.H-balance.ScrollboxVert {
var delta = VP.H - ASize.H - APosition.Y - balance.ScrollboxVert
if APosition.Y >= VP.H-ASize.H-scrollboxVert {
var delta = VP.H - ASize.H - APosition.Y - scrollboxVert
if delta > 300 {
delta = 300
} else if delta < -300 {