Retwerkin stuff

This commit is contained in:
Amadeus Demarzi 2014-07-24 00:46:14 -07:00
parent 27b3187ce9
commit 72f0ef0e8e
5 changed files with 30 additions and 19 deletions

View File

@ -162,7 +162,7 @@ Engine.Particle.prototype = {
}, },
kill: function(engine){ kill: function(engine){
engine._deferred.push(this); engine._deferredParticles.push(this);
return this; return this;
}, },

View File

@ -40,6 +40,11 @@ Engine.Shape = function(x, y, width, height, points, polygons){
Engine.Shape.prototype = { Engine.Shape.prototype = {
selfDestruct: function(time){
this.destruct = time;
return this;
},
update: function(engine){ update: function(engine){
var p; var p;
@ -52,6 +57,8 @@ Engine.Shape.prototype = {
this.polygons[p].update(engine); this.polygons[p].update(engine);
// this.polygons[p].draw(this.context, scale); // this.polygons[p].draw(this.context, scale);
} }
return this;
}, },
draw: function(ctx, scale){ draw: function(ctx, scale){
@ -63,6 +70,7 @@ Engine.Shape.prototype = {
this.polygons[p].draw(ctx, scale); this.polygons[p].draw(ctx, scale);
} }
ctx.restore(); ctx.restore();
return this;
} }
}; };

View File

@ -1,6 +1,6 @@
/* jshint unused: false */ /* jshint unused: false */
/* global console */ /* global console */
(function(Base, Vector, Circle){ (function(Base, Vector, Logo){
var sqrt, pow, Engine; var sqrt, pow, Engine;
@ -23,15 +23,11 @@ Engine = Base.extend({
scale: window.devicePixelRatio || 1, scale: window.devicePixelRatio || 1,
// scale:1, // scale:1,
shapes : [],
particles : [], particles : [],
_deferred : [],
// points : [], _deferredParticles: [],
// polygons : [], _deferredShapes: [],
shapes: [],
speed: 1,
accel: 0.08,
constructor: function(canvas, bg){ constructor: function(canvas, bg){
var image, el; var image, el;
@ -96,8 +92,8 @@ Engine = Base.extend({
(this.height / 2 - 180), (this.height / 2 - 180),
360, 360,
360, 360,
Circle.Points, Logo.Points,
Circle.Polygons Logo.Polygons
); );
}, },
@ -123,7 +119,6 @@ Engine = Base.extend({
this.now = Date.now() / 1000; this.now = Date.now() / 1000;
tick = Math.min(this.now - this.last, 0.017); tick = Math.min(this.now - this.last, 0.017);
this.tick = this.speed * tick;
this.renderStarfield(this.now); this.renderStarfield(this.now);
this.tick = tick; this.tick = tick;
@ -139,7 +134,7 @@ Engine = Base.extend({
renderTessellation: function(){ renderTessellation: function(){
var scale = this.scale, var scale = this.scale,
p; p, index;
for (p = 0; p < this.shapes.length; p++) { for (p = 0; p < this.shapes.length; p++) {
this.shapes[p].update(this); this.shapes[p].update(this);
@ -148,6 +143,14 @@ Engine = Base.extend({
this.logo.update(this); this.logo.update(this);
this.logo.draw(this.context, scale); this.logo.draw(this.context, scale);
// Remove destroyed shapes
for (p = 0; p < this._deferredShapes.length; p++) {
index = this.shapes.indexOf(this._deferredShapes.pop());
if (index >= 0) {
this.shapes.splice(index, 1);
}
}
}, },
generateParticles: function(num, fixed){ generateParticles: function(num, fixed){
@ -180,9 +183,9 @@ Engine = Base.extend({
.draw(this.context, scale); .draw(this.context, scale);
} }
// Remove destroyed entities // Remove destroyed particles
for (p = 0; p < this._deferred.length; p++) { for (p = 0; p < this._deferredParticles.length; p++) {
index = this.particles.indexOf(this._deferred.pop()); index = this.particles.indexOf(this._deferredParticles.pop());
if (index >= 0) { if (index >= 0) {
this.particles.splice(index, 1); this.particles.splice(index, 1);
} }
@ -215,4 +218,4 @@ Engine.clone = function(ref) {
window.Engine = Engine; window.Engine = Engine;
})(window.Base, window.Vector, window.Circle); })(window.Base, window.Vector, window.Logo);

View File

@ -1,5 +1,5 @@
// jshint unused:false // jshint unused:false
var Circle = { var Logo = {
"Points": [ "Points": [
{ {
"id": "point-0", "id": "point-0",

View File

@ -25,7 +25,7 @@
<script type="text/javascript" src="/javascripts/lib/Base.js"></script> <script type="text/javascript" src="/javascripts/lib/Base.js"></script>
<script type="text/javascript" src="/javascripts/lib/String.substitute.js"></script> <script type="text/javascript" src="/javascripts/lib/String.substitute.js"></script>
<script type="text/javascript" src="/javascripts/lib/Vector.js"></script> <script type="text/javascript" src="/javascripts/lib/Vector.js"></script>
<script type="text/javascript" src="/javascripts/app/Circle.js"></script> <script type="text/javascript" src="/javascripts/app/Logo.js"></script>
<script type="text/javascript" src="/javascripts/app/Engine.js"></script> <script type="text/javascript" src="/javascripts/app/Engine.js"></script>
<script type="text/javascript" src="/javascripts/app/Engine.Particle.js"></script> <script type="text/javascript" src="/javascripts/app/Engine.Particle.js"></script>
<script type="text/javascript" src="/javascripts/app/Engine.Particle.Fixed.js"></script> <script type="text/javascript" src="/javascripts/app/Engine.Particle.Fixed.js"></script>