Skip to content

Commit

Permalink
Add puzzle 011 (#16)
Browse files Browse the repository at this point in the history
This puzzle introduces directional portals. It also refines the rules
for portals in general and improves collision logic for beams using
portals.

Additionally, support for sequential mask resolution was added. For
example, this is the case if multiple beams enter portals at the same
time.
  • Loading branch information
kflorence authored Feb 8, 2024
1 parent dfdabf9 commit 64debbc
Show file tree
Hide file tree
Showing 14 changed files with 448 additions and 177 deletions.
32 changes: 27 additions & 5 deletions src/components/collision.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
import { StepState } from './step'

export class Collision {
constructor (index, points, items) {
constructor (index, points, beam, item) {
const items = [beam]

if (item !== undefined) {
items.push(item)
}

this.beam = beam
this.index = index

// The item that was collided with
this.item = items[1]
this.item = item
this.itemIds = items.map((item) => item.id)
this.items = items

// The first collision point
this.point = points[0]
this.points = points

// Check if the collision is with self
this.withSelf = beam.equals(item)
}

copy (settings) {
return new Collision(
settings.index ?? this.index,
settings.points ?? this.points,
settings.beam ?? this.beam,
settings.item ?? this.item
)
}

equals (other) {
return other && other.point.equals(this.point) &&
other.items.length === this.items.length &&
other.items.every((item) => this.has(item))
}

has (beam) {
return this.itemIds.includes(beam.id)
has (item) {
return this.itemIds.includes(item.id)
}

mirror () {
return this.copy({ beam: this.item, item: this.beam })
}
}

Expand Down
Loading

0 comments on commit 64debbc

Please sign in to comment.