|
|
|
|
@ -5,11 +5,12 @@
|
|
|
|
|
Vector
|
|
|
|
|
){
|
|
|
|
|
|
|
|
|
|
Engine.Shape = function(x, y, width, height, points, polygons, simple){
|
|
|
|
|
Engine.Shape = function(x, y, width, height, points, polygons){
|
|
|
|
|
var i, ref, point, poly;
|
|
|
|
|
|
|
|
|
|
this.pos = new Vector(x, y);
|
|
|
|
|
this.pos = new Vector(x, y);
|
|
|
|
|
this.size = new Vector(width, height);
|
|
|
|
|
this.sizeRef = this.size.clone();
|
|
|
|
|
|
|
|
|
|
ref = {};
|
|
|
|
|
this.points = [];
|
|
|
|
|
@ -18,10 +19,9 @@ Engine.Shape = function(x, y, width, height, points, polygons, simple){
|
|
|
|
|
for (i = 0; i < points.length; i++) {
|
|
|
|
|
point = new Point(
|
|
|
|
|
points[i].id,
|
|
|
|
|
points[i].x * this.size.x,
|
|
|
|
|
points[i].y * this.size.y,
|
|
|
|
|
this.size.x,
|
|
|
|
|
this.size.y
|
|
|
|
|
points[i].x,
|
|
|
|
|
points[i].y,
|
|
|
|
|
this.size
|
|
|
|
|
);
|
|
|
|
|
ref[point.id] = point;
|
|
|
|
|
this.points.push(point);
|
|
|
|
|
@ -33,17 +33,63 @@ Engine.Shape = function(x, y, width, height, points, polygons, simple){
|
|
|
|
|
ref[poly.points[0]],
|
|
|
|
|
ref[poly.points[1]],
|
|
|
|
|
ref[poly.points[2]],
|
|
|
|
|
poly.color,
|
|
|
|
|
simple
|
|
|
|
|
poly.color
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Engine.Shape.prototype = {
|
|
|
|
|
|
|
|
|
|
breathing: false,
|
|
|
|
|
|
|
|
|
|
breath: 0,
|
|
|
|
|
breathLength: 1,
|
|
|
|
|
breatheIn: false,
|
|
|
|
|
|
|
|
|
|
startBreathing: function(){
|
|
|
|
|
var p;
|
|
|
|
|
|
|
|
|
|
this.breathing = true;
|
|
|
|
|
this.breath = this.breathLength;
|
|
|
|
|
|
|
|
|
|
for (p = 0; p < this.points.length; p++) {
|
|
|
|
|
this.points[p].updateBreathingPhysics();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
breathe: function(tick){
|
|
|
|
|
var p, scale, newSize;
|
|
|
|
|
|
|
|
|
|
this.breath += tick;
|
|
|
|
|
|
|
|
|
|
if (this.breath < this.breathLength) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.breatheIn) {
|
|
|
|
|
scale = 1;
|
|
|
|
|
} else {
|
|
|
|
|
scale = 1.05;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.breatheIn = !this.breatheIn;
|
|
|
|
|
|
|
|
|
|
newSize = Vector.mult(this.sizeRef, scale);
|
|
|
|
|
|
|
|
|
|
for (p = 0; p < this.points.length; p++) {
|
|
|
|
|
this.points[p].updateTarget(newSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.breath = 0;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
update: function(engine){
|
|
|
|
|
var p;
|
|
|
|
|
|
|
|
|
|
if (this.breathing === true) {
|
|
|
|
|
this.breathe(engine.tick);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (p = 0; p < this.points.length; p++) {
|
|
|
|
|
this.points[p].update(engine);
|
|
|
|
|
}
|
|
|
|
|
|