Skip to content

Commit

Permalink
Don't change laser.vector if reflected value undefined
Browse files Browse the repository at this point in the history
This could happen if a new laser is added by clicking on a boundary cell. In that case the reflection detection will consider that the direction of the laser should be reflected, but in 50% of cases it's already pointing away from the boundary and doesn't need to be.

This fixes a bug whereby the lasers get 'stuck' as a single cell on the boundary in those cases.
  • Loading branch information
jwg4 authored and bryanbraun committed Oct 13, 2021
1 parent 8aa72c6 commit 0001ebf
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docs/demos/lasers/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ function advanceTheLaser(laser) {

if (wallsCollidedWith.length !== 0) {
wallsCollidedWith.forEach(wallCollidedWith => {
laser.vector = reflections[wallCollidedWith][laser.vector];
// If we've just created a new laser on a boundary cell, this might not be true.
if (laser.vector in reflections[wallCollidedWith]) {
laser.vector = reflections[wallCollidedWith][laser.vector];
}
});
}

Expand Down

0 comments on commit 0001ebf

Please sign in to comment.