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

View File

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