Play Mode: Fix Level Collision w/ Scrolling

* Move the call to CollidesWithGrid() inside the Canvas instead of
  outside in the PlayScene.movePlayer() so it can apply to all Actors
  in motion.
* PlayScene.movePlayer() in turn just sets the player's Velocity so the
  Canvas.Loop() can move the actor itself.
* When keeping the player inside the level boundaries: previously it was
  assuming the player Position was relative to the window, and was
  checking the WorldIndexAt and getting wrong results.
* Canvas scrolling (loopFollowActor): check that the actor is getting
  close to the screen edge using the Viewport into the world, NOT the
  screen-relative coordinates of the Canvas bounding boxes.
Noah 4 years ago
parent 2ae77a8c82
commit 8dfae5b8d8
  1. 13
  2. 6

@ -135,6 +135,19 @@ func (r Rect) AddPoint(other Point) Rect {
// SubtractPoint is the inverse of AddPoint. Use this only if you need to invert
// the Point being added.
// This does r.X - other.X, r.Y - other.Y and keeps the width/height the same.
func (r Rect) SubtractPoint(other Point) Rect {
return Rect{
X: r.X - other.X,
Y: r.Y - other.Y,
W: r.W,
H: r.H,
// Text holds information for drawing text.
type Text struct {
Text string

@ -75,6 +75,12 @@ func (p *Point) Add(other Point) {
p.Y += other.Y
// Subtract the other point from your current point.
func (p *Point) Subtract(other Point) {
p.X -= other.X
p.Y -= other.Y
// MarshalText to convert the point into text so that a render.Point may be used
// as a map key and serialized to JSON.
func (p *Point) MarshalText() ([]byte, error) {