Add vectors and poly collisions
This commit is contained in:
parent
9ed0a61246
commit
b13ccf7203
@ -202,6 +202,11 @@ class GeneratedShape {
|
|||||||
this.xs = [];
|
this.xs = [];
|
||||||
this.ys = [];
|
this.ys = [];
|
||||||
|
|
||||||
|
// vector listing of the above xs, ys so that we can pass these lists to
|
||||||
|
// the collidePolyPoly function for collision detection which expects
|
||||||
|
// vector objects, not plain x, y coordinates as in xs, ys.
|
||||||
|
this.vectors = [];
|
||||||
|
|
||||||
// ???
|
// ???
|
||||||
this.angles = [];
|
this.angles = [];
|
||||||
|
|
||||||
@ -243,8 +248,9 @@ class GeneratedShape {
|
|||||||
for (let i = 0; i < this.edges; i++) {
|
for (let i = 0; i < this.edges; i++) {
|
||||||
this.startXs[i] = 0;
|
this.startXs[i] = 0;
|
||||||
this.startYs[i] = 0;
|
this.startYs[i] = 0;
|
||||||
this.ys[i] = 0;
|
|
||||||
this.xs[i] = 0;
|
this.xs[i] = 0;
|
||||||
|
this.ys[i] = 0;
|
||||||
|
this.vectors[i] = createVector(this.xs[i], this.ys[i]);
|
||||||
this.angles[i] = 0;
|
this.angles[i] = 0;
|
||||||
|
|
||||||
// this directly influences the shape of the size alongside the
|
// this directly influences the shape of the size alongside the
|
||||||
@ -262,7 +268,30 @@ class GeneratedShape {
|
|||||||
/**
|
/**
|
||||||
* Detect if the shape collides with another shape.
|
* Detect if the shape collides with another shape.
|
||||||
**/
|
**/
|
||||||
return false; // TODO: implement once again
|
if (shapes.length === 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < shapes.length; i++) {
|
||||||
|
let shape = shapes[i];
|
||||||
|
|
||||||
|
if (this === shape) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't detect if one shape is fully inside another
|
||||||
|
let interiorCollision = false;
|
||||||
|
|
||||||
|
var collision = collidePolyPoly(
|
||||||
|
this.vectors,
|
||||||
|
shape.vectors,
|
||||||
|
interiorCollision
|
||||||
|
);
|
||||||
|
|
||||||
|
if (collision === true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sound() {
|
sound() {
|
||||||
@ -367,6 +396,7 @@ class GeneratedShape {
|
|||||||
this.startXs[i] + sin(radians(this.angles[i])) * (this.accelX * 2);
|
this.startXs[i] + sin(radians(this.angles[i])) * (this.accelX * 2);
|
||||||
this.ys[i] =
|
this.ys[i] =
|
||||||
this.startYs[i] + sin(radians(this.angles[i])) * (this.accelY * 2);
|
this.startYs[i] + sin(radians(this.angles[i])) * (this.accelY * 2);
|
||||||
|
this.vectors[i] = createVector(this.xs[i], this.ys[i]);
|
||||||
this.angles[i] += this.frequencies[i];
|
this.angles[i] += this.frequencies[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user