2019-04-16 02:12:25 +00:00
|
|
|
package collision
|
2018-07-24 03:10:53 +00:00
|
|
|
|
|
|
|
import (
|
2019-05-07 00:06:40 +00:00
|
|
|
"sync"
|
|
|
|
|
2022-09-24 22:17:25 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/balance"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/level"
|
2019-12-28 03:16:34 +00:00
|
|
|
"git.kirsle.net/go/render"
|
2018-07-24 03:10:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Collide describes how a collision occurred.
|
|
|
|
type Collide struct {
|
2018-07-25 03:57:22 +00:00
|
|
|
Top bool
|
|
|
|
TopPoint render.Point
|
2018-09-25 16:40:34 +00:00
|
|
|
TopPixel *level.Swatch
|
2018-07-25 03:57:22 +00:00
|
|
|
Left bool
|
|
|
|
LeftPoint render.Point
|
2018-09-25 16:40:34 +00:00
|
|
|
LeftPixel *level.Swatch
|
2018-07-25 03:57:22 +00:00
|
|
|
Right bool
|
|
|
|
RightPoint render.Point
|
2018-09-25 16:40:34 +00:00
|
|
|
RightPixel *level.Swatch
|
2018-07-25 03:57:22 +00:00
|
|
|
Bottom bool
|
|
|
|
BottomPoint render.Point
|
2018-09-25 16:40:34 +00:00
|
|
|
BottomPixel *level.Swatch
|
2018-07-25 03:57:22 +00:00
|
|
|
MoveTo render.Point
|
Add Switches, Fire/Water Collision and Play Menu
* New doodads: Switches.
* They come in four varieties: wall switch (background element, with
"ON/OFF" text) and three side-profile switches for the floor, left
or right walls.
* On collision with the player, they flip their state from "OFF" to
"ON" or vice versa. If the player walks away and then collides
again, the switch flips again.
* Can be used to open/close Electric Doors when turned on/off. Their
default state is "off"
* If a switch receives a power signal from another linked switch, it
sets its own state to match. So, two "on/off" switches that are
connected to a door AND to each other will both flip on/off when one
of them flips.
* Update the Level Collision logic to support Decoration, Fire and Water
pixel collisions.
* Previously, ALL pixels in the level were acting as though solid.
* Non-solid pixels don't count for collision detection, but their
attributes (fire and water) are collected and returned.
* Updated the MenuScene to support loading a map file in Play Mode
instead of Edit Mode. Updated the title screen menu to add a button
for playing levels instead of editing them.
* Wrote some documentation.
2019-07-07 01:30:03 +00:00
|
|
|
|
|
|
|
// Swatch attributes affecting the collision at this time.
|
2022-10-10 17:52:28 +00:00
|
|
|
InFire string // the name of the swatch, Fire = general ouchy color.
|
|
|
|
InWater bool
|
|
|
|
IsSlippery bool
|
2018-07-25 03:57:22 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 05:26:27 +00:00
|
|
|
// Reset a Collide struct flipping all the bools off, but keeping MoveTo.
|
|
|
|
func (c *Collide) Reset() {
|
|
|
|
c.Top = false
|
|
|
|
c.Left = false
|
|
|
|
c.Right = false
|
|
|
|
c.Bottom = false
|
2022-05-06 04:35:32 +00:00
|
|
|
c.InWater = false
|
2018-07-25 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 03:57:22 +00:00
|
|
|
// Side of the collision box (top, bottom, left, right)
|
|
|
|
type Side uint8
|
|
|
|
|
|
|
|
// Options for the Side type.
|
|
|
|
const (
|
|
|
|
Top Side = iota
|
|
|
|
Bottom
|
|
|
|
Left
|
|
|
|
Right
|
|
|
|
)
|
|
|
|
|
2019-04-14 22:25:03 +00:00
|
|
|
/*
|
|
|
|
CollidesWithGrid checks if a Doodad collides with level geometry.
|
|
|
|
|
|
|
|
The `target` is the point the actor wants to move to on this tick.
|
|
|
|
*/
|
2020-04-05 04:00:32 +00:00
|
|
|
func CollidesWithGrid(d Actor, grid *level.Chunker, target render.Point) (*Collide, bool) {
|
2018-07-24 03:10:53 +00:00
|
|
|
var (
|
2022-04-10 01:21:26 +00:00
|
|
|
P = d.Position()
|
|
|
|
S = d.Size()
|
2021-06-03 03:41:53 +00:00
|
|
|
hitbox = d.Hitbox()
|
2018-07-25 03:57:22 +00:00
|
|
|
|
|
|
|
result = &Collide{
|
|
|
|
MoveTo: P,
|
2018-07-24 03:10:53 +00:00
|
|
|
}
|
2019-12-28 03:16:34 +00:00
|
|
|
ceiling bool // Has hit a ceiling?
|
|
|
|
capHeight int // Stop vertical movement thru a ceiling
|
|
|
|
capLeft int // Stop movement thru a wall
|
|
|
|
capRight int
|
|
|
|
capFloor int // Stop movement thru the floor
|
|
|
|
hitLeft bool // Has hit an obstacle on the left
|
|
|
|
hitRight bool // or right
|
2018-07-25 05:26:27 +00:00
|
|
|
hitFloor bool
|
2018-07-25 03:57:22 +00:00
|
|
|
)
|
|
|
|
|
2021-06-03 03:41:53 +00:00
|
|
|
// Adjust the actor's bounding rect by its stated Hitbox from its script.
|
2021-06-03 04:49:29 +00:00
|
|
|
// e.g.: Boy's Canvas size is 56x56 but he is a narrower character with a
|
|
|
|
// hitbox width smaller than its Canvas size.
|
|
|
|
S = SizePlusHitbox(GetBoundingRect(d), hitbox)
|
2024-02-08 06:14:48 +00:00
|
|
|
actorHeight := P.Y + S.H
|
2021-06-03 03:41:53 +00:00
|
|
|
|
2021-06-03 04:49:29 +00:00
|
|
|
// Test if we are ALREADY colliding with level geometry and try and wiggle
|
|
|
|
// free. ScanBoundingBox scans level pixels along the four edges of the
|
|
|
|
// actor's hitbox in world space.
|
2021-06-03 03:41:53 +00:00
|
|
|
if ok := result.ScanBoundingBox(GetBoundingRectHitbox(d, hitbox), grid); ok {
|
2018-07-25 03:57:22 +00:00
|
|
|
// We've already collided! Try to wiggle free.
|
|
|
|
if result.Bottom {
|
|
|
|
if !d.Grounded() {
|
|
|
|
d.SetGrounded(true)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
d.SetGrounded(false)
|
2018-07-24 03:10:53 +00:00
|
|
|
}
|
2018-07-25 03:57:22 +00:00
|
|
|
if result.Top {
|
2020-01-03 04:23:27 +00:00
|
|
|
ceiling = true
|
|
|
|
P.Y++
|
2018-07-24 03:10:53 +00:00
|
|
|
}
|
2022-10-10 04:39:43 +00:00
|
|
|
if result.Left && !result.LeftPixel.SemiSolid {
|
2018-07-25 03:57:22 +00:00
|
|
|
P.X++
|
|
|
|
}
|
2022-10-10 04:39:43 +00:00
|
|
|
if result.Right && !result.RightPixel.SemiSolid {
|
2018-07-25 03:57:22 +00:00
|
|
|
P.X--
|
|
|
|
}
|
|
|
|
}
|
2018-07-24 03:10:53 +00:00
|
|
|
|
2018-07-25 03:57:22 +00:00
|
|
|
// If grounded, cap our Y position.
|
|
|
|
if d.Grounded() {
|
|
|
|
if !result.Bottom {
|
|
|
|
// We've fallen off a ledge.
|
|
|
|
d.SetGrounded(false)
|
|
|
|
} else if target.Y < P.Y {
|
|
|
|
// We're moving upward.
|
|
|
|
d.SetGrounded(false)
|
|
|
|
} else {
|
2021-06-03 04:49:29 +00:00
|
|
|
// Cap our downward motion to our current position,
|
|
|
|
// fighting the force of gravity.
|
2018-07-25 03:57:22 +00:00
|
|
|
target.Y = P.Y
|
2018-07-24 03:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 03:57:22 +00:00
|
|
|
// Cap our horizontal movement if we're touching walls.
|
|
|
|
if (result.Left && target.X < P.X) || (result.Right && target.X > P.X) {
|
2024-02-08 06:14:48 +00:00
|
|
|
// Handle walking up slopes, if the step is short enough.
|
|
|
|
var slopeHeight int
|
|
|
|
if result.Left {
|
|
|
|
slopeHeight = result.LeftPoint.Y
|
|
|
|
} else if result.Right {
|
|
|
|
slopeHeight = result.RightPoint.Y
|
2018-07-25 03:57:22 +00:00
|
|
|
}
|
2024-02-08 06:14:48 +00:00
|
|
|
|
|
|
|
if offset, ok := CanStepUp(actorHeight, slopeHeight, target.X > P.X); ok {
|
|
|
|
target.Add(offset)
|
2018-07-25 03:57:22 +00:00
|
|
|
} else {
|
2022-10-10 04:39:43 +00:00
|
|
|
// Not a slope.. may be a solid wall. If the wall is a SemiSolid though,
|
|
|
|
// do not cap our direction just yet.
|
|
|
|
if !(result.Left && result.LeftPixel.SemiSolid) && !(result.Right && result.RightPixel.SemiSolid) {
|
|
|
|
target.X = P.X
|
|
|
|
}
|
2018-07-24 03:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 05:26:27 +00:00
|
|
|
// Cap our vertical movement if we're touching ceilings.
|
|
|
|
if ceiling {
|
|
|
|
// The existing box intersects a ceiling, this will almost never
|
|
|
|
// happen because gravity will always pull you away at the last frame.
|
|
|
|
// But if we do somehow get here, may as well cap it where it's at.
|
|
|
|
capHeight = P.Y
|
|
|
|
}
|
|
|
|
|
2018-07-25 03:57:22 +00:00
|
|
|
// Trace a line from where we are to where we wanna go.
|
2018-07-25 05:26:27 +00:00
|
|
|
result.Reset()
|
2018-07-25 03:57:22 +00:00
|
|
|
result.MoveTo = P
|
2019-07-14 21:18:44 +00:00
|
|
|
for point := range render.IterLine(P, target) {
|
2020-01-03 04:23:27 +00:00
|
|
|
// Before we compute their next move, if we're already capping their
|
|
|
|
// height make sure the new point stays capped too. This prevents them
|
|
|
|
// clipping thru a ceiling if they were also holding right/left too.
|
|
|
|
if capHeight != 0 && point.Y < capHeight {
|
|
|
|
point.Y = capHeight
|
|
|
|
}
|
2020-04-12 02:21:12 +00:00
|
|
|
if capLeft != 0 && point.X < capLeft {
|
|
|
|
// TODO: this along with a "+ 1" hack prevents clipping thru the
|
|
|
|
// left wall sometimes, but breaks walking up leftward slopes.
|
|
|
|
point.X = capLeft
|
|
|
|
}
|
2022-04-10 01:21:26 +00:00
|
|
|
if capRight != 0 && point.X > capRight {
|
|
|
|
// This if check fixes the climbing-walls-on-the-right bug.
|
|
|
|
point.X = capRight
|
|
|
|
}
|
2020-01-03 04:23:27 +00:00
|
|
|
|
2018-07-25 05:26:27 +00:00
|
|
|
if has := result.ScanBoundingBox(render.Rect{
|
2018-07-24 03:10:53 +00:00
|
|
|
X: point.X,
|
|
|
|
Y: point.Y,
|
2018-07-25 03:57:22 +00:00
|
|
|
W: S.W,
|
|
|
|
H: S.H,
|
2018-07-25 05:26:27 +00:00
|
|
|
}, grid); has {
|
|
|
|
if result.Bottom {
|
|
|
|
if !hitFloor {
|
|
|
|
hitFloor = true
|
|
|
|
capFloor = result.BottomPoint.Y - S.H
|
2018-07-25 03:57:22 +00:00
|
|
|
}
|
|
|
|
d.SetGrounded(true)
|
|
|
|
}
|
2018-07-25 05:26:27 +00:00
|
|
|
|
|
|
|
if result.Top && !ceiling {
|
|
|
|
// This is a newly discovered ceiling.
|
|
|
|
ceiling = true
|
2020-04-12 02:21:12 +00:00
|
|
|
capHeight = result.TopPoint.Y + 1
|
|
|
|
// TODO: the "+ 1" helps prevent clip thru ceiling, probably.
|
|
|
|
// Similar to the "+ 1" on the left side, below.
|
2018-07-25 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-10 04:39:43 +00:00
|
|
|
// TODO: this block of code is interesting. For SemiSolid slopes, the character
|
|
|
|
// walks up the slopes FAST (full speed) which is nice; would like to do this
|
|
|
|
// for regular solid slopes too. But if this block of code is dummied out for
|
|
|
|
// solid walls, the player is able to clip thru thin walls (couple px thick); the
|
|
|
|
// capLeft/capRight behavior is good at stopping the player here.
|
2024-02-08 06:14:48 +00:00
|
|
|
|
|
|
|
// See if they have hit a solid wall on their left or right edge. If the wall
|
|
|
|
// is short enough to step up, allow them to pass through.
|
2022-10-10 04:39:43 +00:00
|
|
|
if result.Left && !hitLeft && !result.LeftPixel.SemiSolid {
|
2024-02-08 06:14:48 +00:00
|
|
|
if _, ok := CanStepUp(actorHeight, result.LeftPoint.Y, false); !ok {
|
|
|
|
hitLeft = true
|
|
|
|
capLeft = result.LeftPoint.X
|
|
|
|
}
|
2018-07-25 05:26:27 +00:00
|
|
|
}
|
2022-10-10 04:39:43 +00:00
|
|
|
if result.Right && !hitRight && !result.RightPixel.SemiSolid {
|
2024-02-08 06:14:48 +00:00
|
|
|
if _, ok := CanStepUp(actorHeight, result.RightPoint.Y, false); !ok {
|
|
|
|
hitRight = true
|
|
|
|
capRight = result.RightPoint.X - S.W
|
|
|
|
}
|
2018-07-25 05:26:27 +00:00
|
|
|
}
|
2018-07-24 03:10:53 +00:00
|
|
|
}
|
2018-07-25 05:26:27 +00:00
|
|
|
|
|
|
|
// So far so good, keep following the MoveTo to
|
|
|
|
// the last good point before a collision.
|
2018-07-25 03:57:22 +00:00
|
|
|
result.MoveTo = point
|
2018-07-25 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If they hit the roof, cap them to the roof.
|
|
|
|
if ceiling && result.MoveTo.Y < capHeight {
|
|
|
|
result.Top = true
|
|
|
|
result.MoveTo.Y = capHeight
|
|
|
|
}
|
|
|
|
if hitFloor && result.MoveTo.Y > capFloor {
|
|
|
|
result.Bottom = true
|
|
|
|
result.MoveTo.Y = capFloor
|
|
|
|
}
|
2022-10-10 04:39:43 +00:00
|
|
|
if hitLeft && !result.LeftPixel.SemiSolid {
|
2018-07-25 05:26:27 +00:00
|
|
|
result.Left = true
|
|
|
|
result.MoveTo.X = capLeft
|
|
|
|
}
|
2022-10-10 04:39:43 +00:00
|
|
|
if hitRight && !result.RightPixel.SemiSolid {
|
2018-07-25 05:26:27 +00:00
|
|
|
result.Right = true
|
|
|
|
result.MoveTo.X = capRight
|
2018-07-25 03:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result, result.IsColliding()
|
|
|
|
}
|
|
|
|
|
2024-02-08 06:14:48 +00:00
|
|
|
/*
|
|
|
|
CanStepUp checks whether the actor is moving left or right onto a gentle slope which
|
|
|
|
they can step on top of instead of being blocked by the solid wall.
|
|
|
|
|
|
|
|
* actorHeight is the actor's Y position + their hitbox height.
|
|
|
|
* slopeHeight is the Y position of the left or right edge of the level they collide with.
|
|
|
|
* moveRight is true if moving right, false if moving left.
|
|
|
|
|
|
|
|
If the actor can step up the slope, the return value is the Point of how to offset their
|
|
|
|
X,Y position to move up the slope and the boolean is whether they can step up.
|
|
|
|
*/
|
|
|
|
func CanStepUp(actorHeight, slopeHeight int, moveRight bool) (render.Point, bool) {
|
|
|
|
var (
|
|
|
|
height = actorHeight - slopeHeight
|
|
|
|
target render.Point
|
|
|
|
)
|
|
|
|
|
|
|
|
if height <= balance.SlopeMaxHeight {
|
|
|
|
target.Y -= height
|
|
|
|
if moveRight {
|
|
|
|
target.X++
|
|
|
|
} else {
|
|
|
|
target.X--
|
|
|
|
}
|
|
|
|
|
|
|
|
return target, true
|
|
|
|
}
|
|
|
|
|
|
|
|
return target, false
|
|
|
|
}
|
|
|
|
|
2018-07-25 03:57:22 +00:00
|
|
|
// IsColliding returns whether any sort of collision has occurred.
|
|
|
|
func (c *Collide) IsColliding() bool {
|
2022-10-10 04:39:43 +00:00
|
|
|
return c.Top || c.Bottom || (c.Left && !c.LeftPixel.SemiSolid) || (c.Right && !c.RightPixel.SemiSolid) ||
|
2021-03-31 06:33:25 +00:00
|
|
|
c.InFire != "" || c.InWater
|
2018-07-25 03:57:22 +00:00
|
|
|
}
|
2019-04-16 02:12:25 +00:00
|
|
|
|
|
|
|
// ScanBoundingBox scans all of the pixels in a bounding box on the grid and
|
|
|
|
// returns if any of them intersect with level geometry.
|
|
|
|
func (c *Collide) ScanBoundingBox(box render.Rect, grid *level.Chunker) bool {
|
|
|
|
col := GetCollisionBox(box)
|
|
|
|
|
2019-05-07 00:06:40 +00:00
|
|
|
// Check all four edges of the box in parallel on different CPU cores.
|
|
|
|
type jobSide struct {
|
2019-05-07 05:57:32 +00:00
|
|
|
p1 render.Point // p2 is perpendicular to p1 along a straight edge
|
|
|
|
p2 render.Point // of the collision box.
|
2019-05-07 00:06:40 +00:00
|
|
|
side Side
|
|
|
|
}
|
2019-05-07 05:57:32 +00:00
|
|
|
jobs := []jobSide{ // We'll scan each side of the bounding box in parallel
|
2022-05-06 04:35:32 +00:00
|
|
|
{col.Top[0], col.Top[1], Top},
|
|
|
|
{col.Bottom[0], col.Bottom[1], Bottom},
|
|
|
|
{col.Left[0], col.Left[1], Left},
|
|
|
|
{col.Right[0], col.Right[1], Right},
|
2019-05-07 00:06:40 +00:00
|
|
|
}
|
2019-05-07 05:57:32 +00:00
|
|
|
|
2019-05-07 00:06:40 +00:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
for _, job := range jobs {
|
|
|
|
wg.Add(1)
|
2020-01-03 04:23:27 +00:00
|
|
|
job := job
|
|
|
|
go func() {
|
2019-05-07 00:06:40 +00:00
|
|
|
defer wg.Done()
|
|
|
|
c.ScanGridLine(job.p1, job.p2, grid, job.side)
|
2020-01-03 04:23:27 +00:00
|
|
|
}()
|
2019-05-07 00:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
2019-04-16 02:12:25 +00:00
|
|
|
return c.IsColliding()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ScanGridLine scans all of the pixels between p1 and p2 on the grid and tests
|
|
|
|
// for any pixels to be set, implying a collision between level geometry and the
|
|
|
|
// bounding boxes of the doodad.
|
|
|
|
func (c *Collide) ScanGridLine(p1, p2 render.Point, grid *level.Chunker, side Side) {
|
2020-01-03 04:23:27 +00:00
|
|
|
// If scanning the top or bottom line, offset the X coordinate by 1 pixel.
|
|
|
|
// This is because the 4 corners of the bounding box share their corner
|
|
|
|
// pixel with each side, so the Left and Right edges will check the
|
|
|
|
// left- and right-most point.
|
|
|
|
if side == Top || side == Bottom {
|
2020-04-12 02:21:12 +00:00
|
|
|
p1.X++
|
|
|
|
p2.X--
|
2020-01-03 04:23:27 +00:00
|
|
|
}
|
|
|
|
|
2019-07-14 21:18:44 +00:00
|
|
|
for point := range render.IterLine(p1, p2) {
|
Add Switches, Fire/Water Collision and Play Menu
* New doodads: Switches.
* They come in four varieties: wall switch (background element, with
"ON/OFF" text) and three side-profile switches for the floor, left
or right walls.
* On collision with the player, they flip their state from "OFF" to
"ON" or vice versa. If the player walks away and then collides
again, the switch flips again.
* Can be used to open/close Electric Doors when turned on/off. Their
default state is "off"
* If a switch receives a power signal from another linked switch, it
sets its own state to match. So, two "on/off" switches that are
connected to a door AND to each other will both flip on/off when one
of them flips.
* Update the Level Collision logic to support Decoration, Fire and Water
pixel collisions.
* Previously, ALL pixels in the level were acting as though solid.
* Non-solid pixels don't count for collision detection, but their
attributes (fire and water) are collected and returned.
* Updated the MenuScene to support loading a map file in Play Mode
instead of Edit Mode. Updated the title screen menu to add a button
for playing levels instead of editing them.
* Wrote some documentation.
2019-07-07 01:30:03 +00:00
|
|
|
if swatch, err := grid.Get(point); err == nil {
|
|
|
|
// We're intersecting a pixel! If it's a solid one we'll return it
|
|
|
|
// in our result. If non-solid, we'll collect attributes from it
|
|
|
|
// and return them in the final result for gameplay behavior.
|
|
|
|
if swatch.Fire {
|
2021-03-31 06:33:25 +00:00
|
|
|
c.InFire = swatch.Name
|
Add Switches, Fire/Water Collision and Play Menu
* New doodads: Switches.
* They come in four varieties: wall switch (background element, with
"ON/OFF" text) and three side-profile switches for the floor, left
or right walls.
* On collision with the player, they flip their state from "OFF" to
"ON" or vice versa. If the player walks away and then collides
again, the switch flips again.
* Can be used to open/close Electric Doors when turned on/off. Their
default state is "off"
* If a switch receives a power signal from another linked switch, it
sets its own state to match. So, two "on/off" switches that are
connected to a door AND to each other will both flip on/off when one
of them flips.
* Update the Level Collision logic to support Decoration, Fire and Water
pixel collisions.
* Previously, ALL pixels in the level were acting as though solid.
* Non-solid pixels don't count for collision detection, but their
attributes (fire and water) are collected and returned.
* Updated the MenuScene to support loading a map file in Play Mode
instead of Edit Mode. Updated the title screen menu to add a button
for playing levels instead of editing them.
* Wrote some documentation.
2019-07-07 01:30:03 +00:00
|
|
|
}
|
|
|
|
if swatch.Water {
|
|
|
|
c.InWater = true
|
|
|
|
}
|
|
|
|
|
2022-10-10 17:52:28 +00:00
|
|
|
// Slippery floor?
|
|
|
|
if side == Bottom && swatch.Slippery {
|
|
|
|
c.IsSlippery = true
|
|
|
|
}
|
|
|
|
|
Add Switches, Fire/Water Collision and Play Menu
* New doodads: Switches.
* They come in four varieties: wall switch (background element, with
"ON/OFF" text) and three side-profile switches for the floor, left
or right walls.
* On collision with the player, they flip their state from "OFF" to
"ON" or vice versa. If the player walks away and then collides
again, the switch flips again.
* Can be used to open/close Electric Doors when turned on/off. Their
default state is "off"
* If a switch receives a power signal from another linked switch, it
sets its own state to match. So, two "on/off" switches that are
connected to a door AND to each other will both flip on/off when one
of them flips.
* Update the Level Collision logic to support Decoration, Fire and Water
pixel collisions.
* Previously, ALL pixels in the level were acting as though solid.
* Non-solid pixels don't count for collision detection, but their
attributes (fire and water) are collected and returned.
* Updated the MenuScene to support loading a map file in Play Mode
instead of Edit Mode. Updated the title screen menu to add a button
for playing levels instead of editing them.
* Wrote some documentation.
2019-07-07 01:30:03 +00:00
|
|
|
// Non-solid swatches don't collide so don't pay them attention.
|
2022-10-10 04:39:43 +00:00
|
|
|
if !swatch.Solid && !swatch.SemiSolid {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// A semisolid only has collision on the bottom (and a little on the
|
|
|
|
// sides, for slope walking only)
|
|
|
|
if swatch.SemiSolid && side == Top {
|
Add Switches, Fire/Water Collision and Play Menu
* New doodads: Switches.
* They come in four varieties: wall switch (background element, with
"ON/OFF" text) and three side-profile switches for the floor, left
or right walls.
* On collision with the player, they flip their state from "OFF" to
"ON" or vice versa. If the player walks away and then collides
again, the switch flips again.
* Can be used to open/close Electric Doors when turned on/off. Their
default state is "off"
* If a switch receives a power signal from another linked switch, it
sets its own state to match. So, two "on/off" switches that are
connected to a door AND to each other will both flip on/off when one
of them flips.
* Update the Level Collision logic to support Decoration, Fire and Water
pixel collisions.
* Previously, ALL pixels in the level were acting as though solid.
* Non-solid pixels don't count for collision detection, but their
attributes (fire and water) are collected and returned.
* Updated the MenuScene to support loading a map file in Play Mode
instead of Edit Mode. Updated the title screen menu to add a button
for playing levels instead of editing them.
* Wrote some documentation.
2019-07-07 01:30:03 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-04-16 02:12:25 +00:00
|
|
|
switch side {
|
|
|
|
case Top:
|
|
|
|
c.Top = true
|
|
|
|
c.TopPoint = point
|
Add Switches, Fire/Water Collision and Play Menu
* New doodads: Switches.
* They come in four varieties: wall switch (background element, with
"ON/OFF" text) and three side-profile switches for the floor, left
or right walls.
* On collision with the player, they flip their state from "OFF" to
"ON" or vice versa. If the player walks away and then collides
again, the switch flips again.
* Can be used to open/close Electric Doors when turned on/off. Their
default state is "off"
* If a switch receives a power signal from another linked switch, it
sets its own state to match. So, two "on/off" switches that are
connected to a door AND to each other will both flip on/off when one
of them flips.
* Update the Level Collision logic to support Decoration, Fire and Water
pixel collisions.
* Previously, ALL pixels in the level were acting as though solid.
* Non-solid pixels don't count for collision detection, but their
attributes (fire and water) are collected and returned.
* Updated the MenuScene to support loading a map file in Play Mode
instead of Edit Mode. Updated the title screen menu to add a button
for playing levels instead of editing them.
* Wrote some documentation.
2019-07-07 01:30:03 +00:00
|
|
|
c.TopPixel = swatch
|
2019-04-16 02:12:25 +00:00
|
|
|
case Bottom:
|
|
|
|
c.Bottom = true
|
|
|
|
c.BottomPoint = point
|
Add Switches, Fire/Water Collision and Play Menu
* New doodads: Switches.
* They come in four varieties: wall switch (background element, with
"ON/OFF" text) and three side-profile switches for the floor, left
or right walls.
* On collision with the player, they flip their state from "OFF" to
"ON" or vice versa. If the player walks away and then collides
again, the switch flips again.
* Can be used to open/close Electric Doors when turned on/off. Their
default state is "off"
* If a switch receives a power signal from another linked switch, it
sets its own state to match. So, two "on/off" switches that are
connected to a door AND to each other will both flip on/off when one
of them flips.
* Update the Level Collision logic to support Decoration, Fire and Water
pixel collisions.
* Previously, ALL pixels in the level were acting as though solid.
* Non-solid pixels don't count for collision detection, but their
attributes (fire and water) are collected and returned.
* Updated the MenuScene to support loading a map file in Play Mode
instead of Edit Mode. Updated the title screen menu to add a button
for playing levels instead of editing them.
* Wrote some documentation.
2019-07-07 01:30:03 +00:00
|
|
|
c.BottomPixel = swatch
|
2019-04-16 02:12:25 +00:00
|
|
|
case Left:
|
|
|
|
c.Left = true
|
|
|
|
c.LeftPoint = point
|
Add Switches, Fire/Water Collision and Play Menu
* New doodads: Switches.
* They come in four varieties: wall switch (background element, with
"ON/OFF" text) and three side-profile switches for the floor, left
or right walls.
* On collision with the player, they flip their state from "OFF" to
"ON" or vice versa. If the player walks away and then collides
again, the switch flips again.
* Can be used to open/close Electric Doors when turned on/off. Their
default state is "off"
* If a switch receives a power signal from another linked switch, it
sets its own state to match. So, two "on/off" switches that are
connected to a door AND to each other will both flip on/off when one
of them flips.
* Update the Level Collision logic to support Decoration, Fire and Water
pixel collisions.
* Previously, ALL pixels in the level were acting as though solid.
* Non-solid pixels don't count for collision detection, but their
attributes (fire and water) are collected and returned.
* Updated the MenuScene to support loading a map file in Play Mode
instead of Edit Mode. Updated the title screen menu to add a button
for playing levels instead of editing them.
* Wrote some documentation.
2019-07-07 01:30:03 +00:00
|
|
|
c.LeftPixel = swatch
|
2019-04-16 02:12:25 +00:00
|
|
|
case Right:
|
|
|
|
c.Right = true
|
|
|
|
c.RightPoint = point
|
Add Switches, Fire/Water Collision and Play Menu
* New doodads: Switches.
* They come in four varieties: wall switch (background element, with
"ON/OFF" text) and three side-profile switches for the floor, left
or right walls.
* On collision with the player, they flip their state from "OFF" to
"ON" or vice versa. If the player walks away and then collides
again, the switch flips again.
* Can be used to open/close Electric Doors when turned on/off. Their
default state is "off"
* If a switch receives a power signal from another linked switch, it
sets its own state to match. So, two "on/off" switches that are
connected to a door AND to each other will both flip on/off when one
of them flips.
* Update the Level Collision logic to support Decoration, Fire and Water
pixel collisions.
* Previously, ALL pixels in the level were acting as though solid.
* Non-solid pixels don't count for collision detection, but their
attributes (fire and water) are collected and returned.
* Updated the MenuScene to support loading a map file in Play Mode
instead of Edit Mode. Updated the title screen menu to add a button
for playing levels instead of editing them.
* Wrote some documentation.
2019-07-07 01:30:03 +00:00
|
|
|
c.RightPixel = swatch
|
2019-04-16 02:12:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|