<div id="scripts">
<!--[if IE]><script type="text/javascript" src="lib/excanvas.min.js"></script><![endif]-->
-<?php
-$scripts = array(
- "lib/jquery-1.4.3.js",
- "lib/jquery.sparkline.min.js",
- "lib/jquery.hotkeys.js",
-
- // "http://static.ukijs.org/pkg/0.3.8/uki.js",
- // "http://static.ukijs.org/pkg/0.3.8/uki-more.js",
-
- "src/lessly/future.js",
-
- "src/Y/y.js.php",
- "src/Y/modules/y.event.js",
-
- "src/evt/evt.class.js",
-
- "src/portal/layer.js",
- "src/portal/shape.js",
-
- "src/portal/math/math.js",
- "src/portal/math/vec.js",
- "src/portal/math/line.js",
-
- "src/portal/util/loc.js",
- "src/portal/util/quadtree.js",
- "src/portal/util/rbtree.js",
-
- "src/portal/util/eventloop.js",
- "src/portal/util/fps.js",
- "src/portal/util/cooldown.js",
-
- "src/tanks/globals.js",
- "src/tanks/util/calc.js",
- "src/tanks/util/grid.js",
- "src/tanks/util/pathmap.js",
-
- "src/tanks/game/level.js",
- "src/tanks/game/game.js",
- "src/tanks/game/map.js",
-
- "src/tanks/thing/thing.js",
- "src/tanks/thing/bullet.js",
- "src/tanks/thing/tank.js",
- "src/tanks/game/player.js",
-
- "src/tanks/lttl.js",
- "src/tanks/ui.js"
-
-);
-
-function js($src) {
- echo " <script src=\"$src\" type=\"text/javascript\"></script>\n";
-}
-
-foreach ($scripts as $s) js($s);
-?>
+<?php require "tanks.php"; Tanks::writeTags( Tanks::ALL_SCRIPTS ); ?>
</div>
</body>
}
function isFunction(obj) { return type_of(obj) === "function"; }
-
function isString(obj) { return type_of(obj) === "string"; }
-
function isNumber(obj) { return type_of(obj) === "number"; }
-
-
-// A crude way of determining if an object is a window
-function isWindow( obj ) {
- return obj && typeof obj === "object" && "setInterval" in obj;
-}
+function isWindow( obj ) { return obj && typeof obj === "object" && "setInterval" in obj; }
function isPlainObject( obj ){
// Must be an Object.
// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.
-
var key;
for ( key in obj ) {}
Y.attr = dattr;
Y.extend = extend;
-Y.isFunction = isFunction;
-Y.isString = isString;
-Y.isNumber = isNumber;
+Y.isString = isString;
+Y.isNumber = isNumber;
+Y.isFunction = isFunction;
+Y.isArray = isArray;
Y.isPlainObject = isPlainObject;
math.Vec = new Y.Class('Vec', [], {
init : function init(x, y){
- if ( Array.isArray(x) ) {
- y = x[1];
- x = x[0];
- }
-
this.length = 2;
- this.x = this[0] = x;
- this.y = this[1] = y;
+
+ if ( x instanceof Array ) {
+ y = x[1]; x = x[0];
+ }
+ this.setXY(x,y);
},
equals : function equals(b){
return new math.Vec(this.x, this.y);
},
- scale : function scale(s){
- this.x *= s;
- this.y *= s;
+ setXY : function setXY(x,y){
+ this.x = this[0] = x;
+ this.y = this[1] = y;
return this;
},
- invert : function invert(){
- this.x = -this.x;
- this.y = -this.y;
- return this;
+ add : function add(b){
+ return this.setXY(this.x+b.x, this.y+b.y);
},
- normalize : function normalize(){
- return this.scale(1 / this.magnitude());
+ subtract : function subtract(b){
+ return this.setXY(this.x-b.x, this.y-b.y);
},
- add : function add(b){
- this.x += b.x;
- this.y += b.y;
- return this;
+ scale : function scale(s){
+ return this.setXY(this.x*s, this.y*s);
},
- subtract : function subtract(b){
- this.x -= b.x;
- this.y -= b.y;
- return this;
+ invert : function invert(){
+ return this.setXY(-this.x, -this.y);
+ },
+
+ normalize : function normalize(){
+ return this.scale(1 / this.magnitude());
},
magnitude : function magnitude(){
+++ /dev/null
-Shape = new Y.Class('Shape', Layer, {
- _cssClasses : 'portal layer shape',
- fillStyle : 'rgba(231,48,117, 1)',
- strokeStyle : 'transparent',
- lineWidth : 0,
-
- _calcDimension : function _calcDimension(which, values){
- values.unshift(0);
- var self = this
- , neg = -1 * Math.min.apply(Math, values)
- // , pos = Math.min(0, Math.max.apply(Max, values) - max)
- ;
-
- self.negBleed.attr(which, neg);
- // self.posBleed.attr(which, pos);
-
- return values.map(function(v, i){
- return (self[which+i] = v);
- });
- }
-
-});
-
-
-Line = new Y.Class('Line', Shape, {
- _cssClasses : 'portal layer shape line',
-
- useCanvasScaling : true,
- fillStyle : 'transparent',
- strokeStyle : "#000000",
- lineWidth : 1,
-
- drawDefinitionPoints : false,
- invertY : false,
-
-
- init : function initLine(x,y){
- Layer.init.call(this);
-
- this.sublayer = jQuery('<div style="overflow:hidden" />')
- .append(this.canvas)
- .appendTo(this.layer);
-
- this.x2 = x; this.y2 = y;
- this.position(0,0);
- },
-
- position : function position(left, top){
- if (top === undefined && left === undefined)
- return this.line.p1;
-
- var pos = Y.isPlainObject(top) ? top : {'top':top, 'left':left};
-
- this.x1 = pos.left; this.x2 += this.x1;
- this.y1 = pos.top; this.y2 += this.y1;
-
- this.line = new math.Line(this.x1,this.y1, this.x2,this.y2, (this.line||{}).tdist);
-
- return this;
- },
-
- origin : function origin(x,y){
- var o = this.transform.origin;
- if (arguments.length === 0)
- return o.absolute(this.layerWidth, this.layerHeight);
-
- o.x = x;
- o.y = y;
- this.ctx.translate(x,y);
- this.dirty = true;
- return this._applyTransforms();
- },
-
- appendTo : function appendTo(parent){
- var r = Layer.prototype.appendTo.call(this, parent);
- this._fixSize();
- return r;
- },
-
- _fixSize : function _fixSize(){
- var p = this.parent
- , pw = p.canvasWidth, ph = p.canvasHeight
- , w = this.canvasWidth, h = this.canvasHeight
- ;
-
- if (w !== pw) {
- this.width(pw);
- this.sublayer.width(pw);
- }
- if (h !== ph) {
- this.height(ph);
- this.sublayer.height(ph);
- }
- return this;
- },
-
- drawShape : function drawShape(ctx){
- this._fixSize();
- var x1,y1, x2,y2, t = this.transform.translate
- , line = this.line, p1 = line.p1, p2 = line.p2
- , minW = -t.x, minH = -t.y
- , maxW = this.canvasWidth+minW, maxH = this.canvasHeight+minH
- ;
-
- x1 = minW; y1 = line.calcY(x1);
- if (isNaN(y1) || !isFinite(y1)) {
- y1 = minH; x1 = line.calcX(y1);
- }
-
- x2 = maxW; y2 = line.calcY(x2);
- if (isNaN(y2) || !isFinite(y2)) {
- y2 = maxH; x2 = line.calcX(y2);
- }
-
- if (this.invertY){
- y1 = -y1;
- y2 = -y2;
- }
-
- try {
- ctx.moveTo(x1,y1);
- ctx.lineTo(x2,y2);
- ctx.stroke();
- ctx.closePath();
- } catch(e) {
- console.error(this+'.drawShape()');
- console.log(' points:', x1,y1, ' ', x2,y2);
- console.log(' bounds:', minW,minH, ' ', maxW,maxH);
- console.log(' ::', this, line);
- }
-
- // Show definition points
- if ( this.drawDefinitionPoints ) {
- this.point(p1.x,p1.y, 'rgba(69,150,255,0.4)');
- this.point(p2.x,p2.y, 'rgba(69,150,255,0.4)');
- }
- },
-
-
- toString : function toString(){
- return this.className+'['+this.x1+','+this.y1+', '+this.x2+','+this.y2+']';
- }
-
-
-});
-Line.fromPoints = function fromPoints(x1,y1, x2,y2){
- return new Line(x2-x1, y2-y1).position(x1,y1);
-};
-
-
-
-Rect = new Y.Class('Rect', Shape, {
- _cssClasses : 'portal layer shape rect',
-
- init : function initRect(w, h){
- Layer.init.call(this);
-
- this.width(w)
- .height(h);
- // .origin(w/2, h/2);
- },
-
- drawShape : function drawShape(ctx){
- ctx.rect(0,0, this.canvasWidth,this.canvasHeight);
- ctx.fill();
- }
-
-});
-
-Circle = new Y.Class('Circle', Shape, {
- _cssClasses : 'portal layer shape circle',
-
- init : function initCircle(radius){
- Layer.init.call(this);
-
- var d = radius * 2;
- this.radius = this.negBleed.x = this.negBleed.y = radius;
- this.width(d).height(d);
- // .origin(radius,radius);
- },
-
- drawShape : function drawShape(ctx){
- var r = this.radius;
- ctx.arc(0,0, r, 0, Math.PI*2, false);
- ctx.fill();
- ctx.stroke();
- }
-
-});
-
-Polygon = new Y.Class('Polygon', Shape, {
- _cssClasses : 'portal layer shape polygon',
-
- /**
- * Expects two arrays of coordinate-halfs, which could be zipped
- * together to make the numbered coordinates.
- * x0 and y0 will always be 0.
- */
- init : function initPolygon(xs, ys){
- Layer.init.call(this);
-
- var xs = this._calcDimension('x', xs)
- , ys = this._calcDimension('y', ys)
- , w = Math.max.apply(Math, xs)
- , h = Math.max.apply(Math, ys)
- ;
-
- this.points = Y(xs).zip(ys).map(Loc.instantiate, Loc);
- this.width(w)
- .height(h);
- // .origin(w/2, h/2);
- },
-
- drawShape : function drawShape(ctx){
- this.points.forEach(function(loc, i){
- ctx.lineTo(loc.x, loc.y);
- });
- ctx.fill();
- }
-});
-
-
-Triangle = new Y.Class('Triangle', Polygon, {
- _cssClasses : 'portal layer shape polygon triangle',
-
- init : function initTriangle(x1,y1, x2,y2){
- Polygon.init.call(this, [x1,x2], [y1,y2]);
- },
-
- circumcenter : function circumcenter(){
- var offX = this.offsetX, offY = this.offsetY
- , x1 = this.x1 - offX, y1 = -1 * (this.y1 - offY) // remember, DOM is Y-inverted
- , x2 = this.x2 - offX, y2 = -1 * (this.y2 - offY) // which affects the signs
-
- , D = 2 * (x1*y2 - y1*x2)
- , B = Math.pow(x1,2) + Math.pow(y1,2)
- , C = Math.pow(x2,2) + Math.pow(y2,2)
- ;
- return { 'x' : offX + (y2*B - y1*C)/D
- , 'y' : offY + (x1*C - x2*B)/D * -1 // fix inverted Y-axis
- };
- },
-});
-
-Quad = new Y.Class('Quad', Polygon, {
- _cssClasses : 'portal layer shape polygon quad',
-
- init : function initQuad(x1,y1, x2,y2, x3,y3){
- Polygon.init.call(this, [x1,x2,x3], [y1,y2,y3]);
- }
-
-});
--- /dev/null
+
+Circle = new Y.Class('Circle', Shape, {
+ _cssClasses : 'portal layer shape circle',
+
+ init : function initCircle(radius){
+ Layer.init.call(this);
+
+ var d = radius * 2;
+ this.radius = this.negBleed.x = this.negBleed.y = radius;
+ this.width(d).height(d);
+ // .origin(radius,radius);
+ },
+
+ drawShape : function drawShape(ctx){
+ var r = this.radius;
+ ctx.arc(0,0, r, 0, Math.PI*2, false);
+ ctx.fill();
+ ctx.stroke();
+ }
+
+});
--- /dev/null
+
+Line = new Y.Class('Line', Shape, {
+ _cssClasses : 'portal layer shape line',
+
+ useCanvasScaling : true,
+ fillStyle : 'transparent',
+ strokeStyle : "#000000",
+ lineWidth : 1,
+
+ drawDefinitionPoints : false,
+ invertY : false,
+
+
+ init : function initLine(x,y){
+ Layer.init.call(this);
+
+ this.sublayer = jQuery('<div style="overflow:hidden" />')
+ .append(this.canvas)
+ .appendTo(this.layer);
+
+ this.x2 = x; this.y2 = y;
+ this.position(0,0);
+ },
+
+ position : function position(left, top){
+ if (top === undefined && left === undefined)
+ return this.line.p1;
+
+ var pos = Y.isPlainObject(top) ? top : {'top':top, 'left':left};
+
+ this.x1 = pos.left; this.x2 += this.x1;
+ this.y1 = pos.top; this.y2 += this.y1;
+
+ this.line = new math.Line(this.x1,this.y1, this.x2,this.y2, (this.line||{}).tdist);
+
+ return this;
+ },
+
+ origin : function origin(x,y){
+ var o = this.transform.origin;
+ if (arguments.length === 0)
+ return o.absolute(this.layerWidth, this.layerHeight);
+
+ o.x = x;
+ o.y = y;
+ this.ctx.translate(x,y);
+ this.dirty = true;
+ return this._applyTransforms();
+ },
+
+ appendTo : function appendTo(parent){
+ var r = Layer.prototype.appendTo.call(this, parent);
+ this._fixSize();
+ return r;
+ },
+
+ _fixSize : function _fixSize(){
+ var p = this.parent
+ , pw = p.canvasWidth, ph = p.canvasHeight
+ , w = this.canvasWidth, h = this.canvasHeight
+ ;
+
+ if (w !== pw) {
+ this.width(pw);
+ this.sublayer.width(pw);
+ }
+ if (h !== ph) {
+ this.height(ph);
+ this.sublayer.height(ph);
+ }
+ return this;
+ },
+
+ drawShape : function drawShape(ctx){
+ this._fixSize();
+ var x1,y1, x2,y2
+ , line = this.line, p1 = line.p1, p2 = line.p2
+ , t = this.transform.translate
+ , minW = -t.x, minH = -t.y
+ , maxW = this.canvasWidth+minW, maxH = this.canvasHeight+minH
+ ;
+
+ // We need endpoints at the edges of the viewport to draw the full line.
+ x1 = minW; y1 = line.calcY(x1);
+ if (isNaN(y1) || !isFinite(y1)) {
+ y1 = minH; x1 = line.calcX(y1);
+ }
+
+ x2 = maxW; y2 = line.calcY(x2);
+ if (isNaN(y2) || !isFinite(y2)) {
+ y2 = maxH; x2 = line.calcX(y2);
+ }
+
+ if (this.invertY){
+ y1 = -y1;
+ y2 = -y2;
+ }
+
+ try {
+ ctx.moveTo(x1,y1);
+ ctx.lineTo(x2,y2);
+ ctx.stroke();
+ ctx.closePath();
+ } catch(e) {
+ if (window.console) {
+ console.error(this+'.drawShape()');
+ console.log(' points:', x1,y1, ' ', x2,y2);
+ console.log(' bounds:', minW,minH, ' ', maxW,maxH);
+ console.log(' ::', this, line);
+ }
+ }
+
+ // Show definition points
+ if ( this.drawDefinitionPoints ) {
+ this.point(p1.x,p1.y, 'rgba(69,150,255,0.4)');
+ this.point(p2.x,p2.y, 'rgba(69,150,255,0.4)');
+ }
+ },
+
+
+ toString : function toString(){
+ return this.className+'['+this.x1+','+this.y1+', '+this.x2+','+this.y2+']';
+ }
+
+
+});
+Line.fromPoints = function fromPoints(x1,y1, x2,y2){
+ return new Line(x2-x1, y2-y1).position(x1,y1);
+};
+
--- /dev/null
+
+Polygon = new Y.Class('Polygon', Shape, {
+ _cssClasses : 'portal layer shape polygon',
+
+ /**
+ * Expects two arrays of coordinate-halfs, which could be zipped
+ * together to make the numbered coordinates.
+ * x0 and y0 will always be 0.
+ */
+ init : function initPolygon(xs, ys){
+ Layer.init.call(this);
+
+ var xs = this._calcDimension('x', xs)
+ , ys = this._calcDimension('y', ys)
+ , w = Math.max.apply(Math, xs)
+ , h = Math.max.apply(Math, ys)
+ ;
+
+ this.points = Y(xs).zip(ys).map(Loc.instantiate, Loc);
+ this.width(w)
+ .height(h);
+ // .origin(w/2, h/2);
+ },
+
+ drawShape : function drawShape(ctx){
+ this.points.forEach(function(loc, i){
+ ctx.lineTo(loc.x, loc.y);
+ });
+ ctx.fill();
+ }
+});
+
+
+Triangle = new Y.Class('Triangle', Polygon, {
+ _cssClasses : 'portal layer shape polygon triangle',
+
+ init : function initTriangle(x1,y1, x2,y2){
+ Polygon.init.call(this, [x1,x2], [y1,y2]);
+ },
+
+ circumcenter : function circumcenter(){
+ var offX = this.offsetX, offY = this.offsetY
+ , x1 = this.x1 - offX, y1 = -1 * (this.y1 - offY) // remember, DOM is Y-inverted
+ , x2 = this.x2 - offX, y2 = -1 * (this.y2 - offY) // which affects the signs
+
+ , D = 2 * (x1*y2 - y1*x2)
+ , B = Math.pow(x1,2) + Math.pow(y1,2)
+ , C = Math.pow(x2,2) + Math.pow(y2,2)
+ ;
+ return { 'x' : offX + (y2*B - y1*C)/D
+ , 'y' : offY + (x1*C - x2*B)/D * -1 // fix inverted Y-axis
+ };
+ },
+});
+
+Quad = new Y.Class('Quad', Polygon, {
+ _cssClasses : 'portal layer shape polygon quad',
+
+ init : function initQuad(x1,y1, x2,y2, x3,y3){
+ Polygon.init.call(this, [x1,x2,x3], [y1,y2,y3]);
+ }
+
+});
--- /dev/null
+
+Rect = new Y.Class('Rect', Shape, {
+ _cssClasses : 'portal layer shape rect',
+
+ init : function initRect(w, h){
+ Layer.init.call(this);
+
+ this.width(w)
+ .height(h);
+ // .origin(w/2, h/2);
+ },
+
+ drawShape : function drawShape(ctx){
+ ctx.rect(0,0, this.canvasWidth,this.canvasHeight);
+ ctx.fill();
+ }
+
+});
--- /dev/null
+Shape = new Y.Class('Shape', Layer, {
+ _cssClasses : 'portal layer shape',
+ fillStyle : 'rgba(231,48,117, 1)',
+ strokeStyle : 'transparent',
+ lineWidth : 0,
+
+ _calcDimension : function _calcDimension(which, values){
+ values.unshift(0);
+ var self = this
+ , neg = -1 * Math.min.apply(Math, values)
+ // , pos = Math.min(0, Math.max.apply(Max, values) - max)
+ ;
+
+ self.negBleed.attr(which, neg);
+ // self.posBleed.attr(which, pos);
+
+ return values.map(function(v, i){
+ return (self[which+i] = v);
+ });
+ }
+
+});
+
+++ /dev/null
-Transform = new Y.Class('Transform', {
-
- scale : function scale(x,y, layer, ctx){
-
- },
-
- translate : function translate(x,y, layer, ctx){
-
- },
-
- crop : function crop(){
-
- }
-
-});
-
-Transform.Rotation = new Y.Class('Rotation', Transform, {
-
- init : function initRotation(theta, x,y){
- this.theta = theta;
- this.x = x;
- this.y = y;
- },
-
- apply : function applyRotation(layer, ctx){
- ctx = ctx || layer.ctx;
- ctx.translate(this.x, this.y);
- ctx.rotate(this.theta);
- ctx.translate(-this.x, -this.y);
- }
-
-});
-
-Transform.Scale = new Y.Class('Scale', Transform, {
-
- init : function initScale(x,y){
- this.x = x;
- this.y = y;
- },
-
- apply : function apply(layer, ctx){
- ctx = ctx || layer.ctx;
- ctx.scale(this.x, this.y);
- }
-
-});
-
-Transform.Translate = new Y.Class('Translate', Transform, {
-
- init : function init(x,y){
- this.x = x;
- this.y = y;
- },
-
- apply : function apply(layer, ctx){
- ctx = ctx || layer.ctx;
- ctx.translate(this.x, this.y);
- }
-
-});
-
+++ /dev/null
-jQuery(function($){
-
-v = $('#viewport');
-LBT = new Game();
-
-var sq = REF_SIZE
-, wall = new Wall(6*sq,1*sq, 1*sq,4*sq);
-LBT.level.append(wall);
-
-
-T = new Tank(0);
-LBT.addUnit(T, 1,2);
-T.shape.hide();
-
-B = new Bullet(T, 5*REF_SIZE,5*REF_SIZE);
-LBT.addUnit(B);
-B.render( LBT.level );
-
-B = new Bullet(T, 25,25);
-LBT.addUnit(B);
-B.render( LBT.level );
-
-B = new Bullet(T, 1*REF_SIZE,3*REF_SIZE);
-LBT.addUnit(B);
-B.render( LBT.level );
-
-P = new Player(LBT, T);
-
-
-ctx = LBT.level.ctx;
-tr = B.trajectory;
-
-
-
-});
\ No newline at end of file
--- /dev/null
+jQuery(main);
+
+function main(){
+
+ v = $('#viewport');
+ LBT = new Game();
+
+
+ var sq = REF_SIZE
+ , wall = new Wall(6*sq,1*sq, 1*sq,4*sq);
+ LBT.level.append(wall);
+
+
+ T = new Tank(0);
+ LBT.addUnit(T, 1,2);
+ T.shape.hide();
+
+ B = new Bullet(T, 5*REF_SIZE,5*REF_SIZE);
+ LBT.addUnit(B);
+ B.render( LBT.level );
+
+ B = new Bullet(T, 25,25);
+ LBT.addUnit(B);
+ B.render( LBT.level );
+
+ B = new Bullet(T, 1*REF_SIZE,3*REF_SIZE);
+ LBT.addUnit(B);
+ B.render( LBT.level );
+
+ P = new Player(LBT, T);
+
+
+ ctx = LBT.level.ctx;
+ tr = B.trajectory;
+
+
+
+}
+
// [x,y]
Loc = new Y.Class('Loc', math.Vec, {
- init : function init(x, y){
- if ( Array.isArray(x) ) {
- y = x[1];
- x = x[0];
- }
-
- this.length = 2;
- this.x = this[0] = x;
- this.y = this[1] = y;
- },
+ // init : function init(x,y){
+ // math.Vec.init.call(this, x,y);
+ // },
set : function set(k, v, def){
v = (v !== undefined ? v : def);
return Loc.Square.fromLoc(this.x, this.y);
},
+ /**
+ * Converts relative locations like ('50%','50%') to a numeric location.
+ */
absolute : function absolute(w,h){
var x = this.x, y = this.y
return new Loc( Y.isString(x) ? parseFloat(x.slice(0,-1))/100 * w : x
+++ /dev/null
-
-// Update performance info periodically
-function updateInfo(){
- var loop = LBT.loop
- , fps = loop.fps()
- , n_units = LBT.units.size()
- , n_projs = LBT.bullets.size()
- ;
-
- $('#info [name=fps]').val( fps.toFixed(2) + " / " + loop.framerate );
- $('#info [name=frame]').val( loop.frametime().toFixed(3)+" ms" );
- $('#info #state').text( loop.running ? 'Running!' : ('Paused (tick '+TICKS+')') );
-
- $('#info [name=objects]').val( n_units+n_projs );
- $('#info [name=units]').val( n_units );
- $('#info [name=bullets]').val( n_projs );
-
- spark.drawTimes();
-
- return false;
-}
-
-function toggleGame(evt){
- if (LBT.loop.running)
- LBT.stop();
- else
- LBT.start();
-
- updateInfo();
- return false;
-}
-
-function fixStartText(){
- var txt = (LBT.loop.running ? 'pause' : 'start');
- $('.start_btn').text(txt).attr('title', txt);
- return false;
-}
-function fixOverlayText(){
- var txt = (LBT.showOverlay ? 'hide' : 'show') + ' bounds';
- $('.overlay_btn').text(txt).attr('title', txt);
- return false;
-}
-
-
-
-jQuery(function($){
- spark = new FpsSparkline(LBT.loop, '.fps-sparkline', 0,0);
-
- // Tick once to draw grid, initial units
- // LBT.start();
- // LBT.stop();
- // LBT.loop.elapsedAtStop = 1;
-
- LBT.root.draw();
-
-
- setInterval(updateInfo, 1000);
- updateInfo();
-
- // Update Text on Click
- LBT.addEventListener('start', fixStartText);
- LBT.addEventListener('stop', fixStartText);
-
- // Start button (click or return key)
- $('.start_btn').bind('click', toggleGame);
- $(document).bind('keydown', 'return', toggleGame);
-
- $(document).bind('keydown', 'ctrl+o', function(evt){ LBT.showOverlay = !(LBT.showOverlay); });
-
- // Show Overlays
- $('.overlay_btn').bind('click', function(evt){
- LBT.showOverlay = !(LBT.showOverlay);
- fixOverlayText();
- return false;
- });
-
- // Fix Starting text
- fixStartText();
- fixOverlayText();
-
- // Fix grid-size on resize
- // $(window).bind('resize', function(evt){
- // LBT.resize(evt);
- //
- // if (!LBT.loop.running) {
- // LBT.start();
- // LBT.stop();
- // }
- // });
-
-});
\ No newline at end of file
--- /dev/null
+// Set up UI listeners
+function setupUI(){
+ spark = LBT.loop.spark = new FpsSparkline(LBT.loop, '.fps-sparkline', 0,0);
+
+ // Draw grid, initial units
+ LBT.root.draw();
+
+ setInterval(updateInfo, 1000);
+ updateInfo();
+
+ // Start button (click or return key)
+ $(document).bind('keydown', 'return', toggleGame);
+ $(document).bind('keydown', 'ctrl+o', toggleOverlay);
+
+ // Fix grid-size on resize
+ // $(window).bind('resize', resizeGame);
+}
+
+// Update performance info periodically
+function updateInfo(){
+ var loop = LBT.loop
+ , fps = loop.fps()
+ , n_units = LBT.units.size()
+ , n_projs = LBT.bullets.size()
+ ;
+
+ $('#info [name=fps]').val( fps.toFixed(2) + " / " + loop.framerate );
+ $('#info [name=frame]').val( loop.frametime().toFixed(3)+" ms" );
+ $('#info #state').text( loop.running ? 'Running!' : ('Paused (tick '+TICKS+')') );
+
+ $('#info [name=objects]').val( n_units+n_projs );
+ $('#info [name=units]').val( n_units );
+ $('#info [name=bullets]').val( n_projs );
+
+ spark.drawTimes();
+
+ return false;
+}
+
+function toggleGame(evt){
+ if (LBT.loop.running)
+ LBT.stop();
+ else
+ LBT.start();
+
+ updateInfo();
+}
+
+function toggleOverlay(evt){
+ LBT.showOverlay = !(LBT.showOverlay);
+}
+
+function resizeGame(evt){
+ LBT.resize(evt);
+
+ if (!LBT.loop.running) {
+ LBT.start();
+ LBT.stop();
+ }
+}
+
--- /dev/null
+<?php
+
+class Tanks {
+ const MAIN_SCRIPTS = 1;
+ const SRC_SCRIPTS = 2;
+ const LIB_SCRIPTS = 4;
+
+ const ONLY_LIB = 4; // LIB_SCRIPTS; // wtf i can't use expressions of constants?
+ const SRC_AND_LIB = 6; // LIB_SCRIPTS | SRC_SCRIPTS;
+ const ALL_SCRIPTS = 7; // MAIN_SCRIPTS | LIB_SCRIPTS | SRC_SCRIPTS;
+
+
+ static $mainScripts = array(
+ "src/tanks/main.js",
+ "src/tanks/ui.main.js"
+ );
+
+ static $srcScripts = array(
+ "src/tanks/globals.js",
+ "src/tanks/calc.js",
+
+ "src/tanks/map/loc.js",
+ "src/tanks/map/level.js",
+ "src/tanks/map/pathmap.js",
+
+ "src/tanks/thing/thing.js",
+ "src/tanks/thing/bullet.js",
+ "src/tanks/thing/tank.js",
+
+ "src/tanks/ui/grid.js",
+ "src/tanks/ui/player.js",
+
+ "src/tanks/game/game.js",
+ "src/tanks/game/map.game.js"
+ );
+
+ static $libScripts = array(
+ "lib/jquery-1.4.3.js",
+ "lib/jquery.sparkline.min.js",
+ "lib/jquery.hotkeys.js",
+
+ // "http://static.ukijs.org/pkg/0.3.8/uki.js",
+ // "http://static.ukijs.org/pkg/0.3.8/uki-more.js",
+
+ "src/lessly/future.js",
+
+ "src/Y/y.js.php",
+ "src/Y/modules/y.event.js",
+
+ "src/evt/evt.class.js",
+
+ "src/portal/math/math.js",
+ "src/portal/math/vec.js",
+ "src/portal/math/line.js",
+
+ "src/portal/layer.js",
+ "src/portal/shape/shape.js",
+ "src/portal/shape/circle.js",
+ "src/portal/shape/rect.js",
+ "src/portal/shape/line.js",
+ "src/portal/shape/polygon.js",
+
+ "src/portal/util/tree/quadtree.js",
+
+ "src/portal/loop/eventloop.js",
+ "src/portal/loop/fps.js",
+ "src/portal/loop/cooldown.js",
+ );
+
+ static function writeTags($scripts=null, $prefix="") {
+ $scripts = $scripts ? $scripts : Tanks::SRC_AND_LIB;
+ if ($scripts & Tanks::LIB_SCRIPTS) foreach (self::$libScripts as $s) js($s, $prefix);
+ if ($scripts & Tanks::SRC_SCRIPTS) foreach (self::$srcScripts as $s) js($s, $prefix);
+ if ($scripts & Tanks::MAIN_SCRIPTS) foreach (self::$mainScripts as $s) js($s, $prefix);
+ }
+
+}
+
+function js($src, $prefix="") {
+ echo " <script src=\"$prefix$src\" type=\"text/javascript\"></script>\n";
+}
+
+
+
+?>
+
<div id="scripts">
<?php
-$scripts = array(
- "lib/jquery-1.4.3.js",
- "lib/jquery.sparkline.min.js",
- "lib/jquery.hotkeys.js",
-
- // "http://static.ukijs.org/pkg/0.3.8/uki.js",
- // "http://static.ukijs.org/pkg/0.3.8/uki-more.js",
-
- "src/lessly/future.js",
- "src/Y/y.js.php",
- "src/Y/modules/y.event.js",
-
- "src/evt/evt.class.js",
-
- "src/portal/math/math.js",
- "src/portal/math/vec.js",
- "src/portal/math/line.js",
-
- "src/portal/util/loc.js",
- "src/portal/layer.js",
- "src/portal/shape.js",
- "src/tanks/util/grid.js",
-
- "test/math/math.test.js"
-);
-function js($src) {
- echo " <script src=\"../../$src\" type=\"text/javascript\"></script>\n";
-}
+require "../../tanks.php";
+Tanks::writeTags(null, "../../");
+$scripts = array(
+ "math.test.js"
+);
foreach ($scripts as $s) js($s);
+
?>
</div>
</body>