Skip to content

Commit 841c99d

Browse files
committed
Fix Paperoids example and use Path#getIntersections for collision detection.
1 parent 2666e60 commit 841c99d

1 file changed

Lines changed: 4 additions & 18 deletions

File tree

examples/Games/Paperoids.html

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
path.closed = true;
126126
var thrust = new Path([-8, -4], [-14, 0], [-8, 4]);
127127
var group = new Group(path, thrust);
128+
group.applyMatrix = true;
128129
group.position = view.bounds.center;
129130
return {
130131
item: group,
@@ -231,28 +232,13 @@
231232

232233
// if bounding rect collision, do a line intersection test
233234
if (crash > -1) {
234-
var hit = false;
235-
var pos = Rocks.children[crash].position;
236-
var shipSegments = this.item.firstChild.segments;
237235
var index = Rocks.children[crash].typeIndex;
238236
var tempRock = Rocks.shapes[index].clone();
239237
tempRock.transform(Rocks.children[crash].matrix);
240238
tempRock.remove();
241-
var rockSegments = tempRock.segments;
242-
// This code should be able to be simplified alot very soon,
243-
// when Paper.js implements Path#intersects(path);
244-
for (var i = 0; i < rockSegments.length - 1; i++) {
245-
var rockLine = new Line(rockSegments[i].point,
246-
rockSegments[i + 1].point, false);
247-
var shipLine = new Line(shipSegments[0].point,
248-
shipSegments[1].point, false);
249-
var lineHit = shipLine.intersect(rockLine);
250-
if (lineHit) {
251-
hit = true;
252-
break;
253-
}
254-
}
255-
if (hit) Lives.remove();
239+
var intersections = this.item.firstChild.getIntersections(tempRock);
240+
if (intersections.length > 0)
241+
Lives.remove();
256242
}
257243
}
258244
};

0 commit comments

Comments
 (0)