mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Fix Paperoids example and use Path#getIntersections for collision detection.
This commit is contained in:
parent
2666e60f28
commit
841c99d6d8
1 changed files with 4 additions and 18 deletions
|
@ -125,6 +125,7 @@
|
||||||
path.closed = true;
|
path.closed = true;
|
||||||
var thrust = new Path([-8, -4], [-14, 0], [-8, 4]);
|
var thrust = new Path([-8, -4], [-14, 0], [-8, 4]);
|
||||||
var group = new Group(path, thrust);
|
var group = new Group(path, thrust);
|
||||||
|
group.applyMatrix = true;
|
||||||
group.position = view.bounds.center;
|
group.position = view.bounds.center;
|
||||||
return {
|
return {
|
||||||
item: group,
|
item: group,
|
||||||
|
@ -231,28 +232,13 @@
|
||||||
|
|
||||||
// if bounding rect collision, do a line intersection test
|
// if bounding rect collision, do a line intersection test
|
||||||
if (crash > -1) {
|
if (crash > -1) {
|
||||||
var hit = false;
|
|
||||||
var pos = Rocks.children[crash].position;
|
|
||||||
var shipSegments = this.item.firstChild.segments;
|
|
||||||
var index = Rocks.children[crash].typeIndex;
|
var index = Rocks.children[crash].typeIndex;
|
||||||
var tempRock = Rocks.shapes[index].clone();
|
var tempRock = Rocks.shapes[index].clone();
|
||||||
tempRock.transform(Rocks.children[crash].matrix);
|
tempRock.transform(Rocks.children[crash].matrix);
|
||||||
tempRock.remove();
|
tempRock.remove();
|
||||||
var rockSegments = tempRock.segments;
|
var intersections = this.item.firstChild.getIntersections(tempRock);
|
||||||
// This code should be able to be simplified alot very soon,
|
if (intersections.length > 0)
|
||||||
// when Paper.js implements Path#intersects(path);
|
Lives.remove();
|
||||||
for (var i = 0; i < rockSegments.length - 1; i++) {
|
|
||||||
var rockLine = new Line(rockSegments[i].point,
|
|
||||||
rockSegments[i + 1].point, false);
|
|
||||||
var shipLine = new Line(shipSegments[0].point,
|
|
||||||
shipSegments[1].point, false);
|
|
||||||
var lineHit = shipLine.intersect(rockLine);
|
|
||||||
if (lineHit) {
|
|
||||||
hit = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hit) Lives.remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue