Browse Source

Play Mode: Fix Level Collision w/ Scrolling

Fixes:
* 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.
master
Noah Petherbridge 2 years ago
parent
commit
8dfae5b8d8
2 changed files with 19 additions and 0 deletions
  1. +13
    -0
      interface.go
  2. +6
    -0
      point.go

+ 13
- 0
interface.go View File

@@ -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


+ 6
- 0
point.go View File

@@ -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) {


Loading…
Cancel
Save