From: dsc Date: Wed, 10 Nov 2010 06:22:01 +0000 (-0800) Subject: Reorg of packages. X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=424e87c3297347dda781db0738d82ec603441a21;p=tanks.git Reorg of packages. --- diff --git a/index.php b/index.php index 330dc95..8b6593d 100644 --- a/index.php +++ b/index.php @@ -25,62 +25,7 @@
-\n"; -} - -foreach ($scripts as $s) js($s); -?> +
diff --git a/src/Y/type.js b/src/Y/type.js index c23970c..11d7360 100644 --- a/src/Y/type.js +++ b/src/Y/type.js @@ -15,16 +15,9 @@ function type_of(obj){ } 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. @@ -42,7 +35,6 @@ function isPlainObject( obj ){ // 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 ) {} diff --git a/src/Y/y-core.js b/src/Y/y-core.js index dced427..ec51cba 100644 --- a/src/Y/y-core.js +++ b/src/Y/y-core.js @@ -4,9 +4,10 @@ Y.set = dset; 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; diff --git a/src/portal/util/cooldown.js b/src/portal/loop/cooldown.js similarity index 100% rename from src/portal/util/cooldown.js rename to src/portal/loop/cooldown.js diff --git a/src/portal/util/eventloop.js b/src/portal/loop/eventloop.js similarity index 100% rename from src/portal/util/eventloop.js rename to src/portal/loop/eventloop.js diff --git a/src/portal/util/fps.js b/src/portal/loop/fps.js similarity index 100% rename from src/portal/util/fps.js rename to src/portal/loop/fps.js diff --git a/src/portal/math/vec.js b/src/portal/math/vec.js index 7ac8e02..76421f6 100644 --- a/src/portal/math/vec.js +++ b/src/portal/math/vec.js @@ -4,14 +4,12 @@ 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){ @@ -22,32 +20,30 @@ math.Vec = new Y.Class('Vec', [], { 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(){ diff --git a/src/portal/path.js b/src/portal/path.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/portal/portal.js b/src/portal/portal.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/portal/shape.js b/src/portal/shape.js deleted file mode 100644 index 50d3895..0000000 --- a/src/portal/shape.js +++ /dev/null @@ -1,252 +0,0 @@ -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('
') - .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]); - } - -}); diff --git a/src/portal/shape/circle.js b/src/portal/shape/circle.js new file mode 100644 index 0000000..10e824f --- /dev/null +++ b/src/portal/shape/circle.js @@ -0,0 +1,21 @@ + +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(); + } + +}); diff --git a/src/portal/shape/line.js b/src/portal/shape/line.js new file mode 100644 index 0000000..fe9ddcd --- /dev/null +++ b/src/portal/shape/line.js @@ -0,0 +1,130 @@ + +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('
') + .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); +}; + diff --git a/src/portal/shape/polygon.js b/src/portal/shape/polygon.js new file mode 100644 index 0000000..a2cf377 --- /dev/null +++ b/src/portal/shape/polygon.js @@ -0,0 +1,63 @@ + +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]); + } + +}); diff --git a/src/portal/shape/rect.js b/src/portal/shape/rect.js new file mode 100644 index 0000000..ef21d2d --- /dev/null +++ b/src/portal/shape/rect.js @@ -0,0 +1,18 @@ + +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(); + } + +}); diff --git a/src/portal/shape/shape.js b/src/portal/shape/shape.js new file mode 100644 index 0000000..609a74a --- /dev/null +++ b/src/portal/shape/shape.js @@ -0,0 +1,23 @@ +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); + }); + } + +}); + diff --git a/src/portal/transform.js b/src/portal/transform.js deleted file mode 100644 index 6e829f6..0000000 --- a/src/portal/transform.js +++ /dev/null @@ -1,61 +0,0 @@ -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); - } - -}); - diff --git a/src/portal/util/pointquadtree.js b/src/portal/util/tree/pointquadtree.js similarity index 100% rename from src/portal/util/pointquadtree.js rename to src/portal/util/tree/pointquadtree.js diff --git a/src/portal/util/quadtree.js b/src/portal/util/tree/quadtree.js similarity index 100% rename from src/portal/util/quadtree.js rename to src/portal/util/tree/quadtree.js diff --git a/src/portal/util/rbtree.js b/src/portal/util/tree/rbtree.js similarity index 100% rename from src/portal/util/rbtree.js rename to src/portal/util/tree/rbtree.js diff --git a/src/tanks/util/calc.js b/src/tanks/calc.js similarity index 100% rename from src/tanks/util/calc.js rename to src/tanks/calc.js diff --git a/src/tanks/game/map.js b/src/tanks/game/map.game.js similarity index 100% rename from src/tanks/game/map.js rename to src/tanks/game/map.game.js diff --git a/src/tanks/lttl.js b/src/tanks/lttl.js deleted file mode 100644 index 2ce4ee3..0000000 --- a/src/tanks/lttl.js +++ /dev/null @@ -1,35 +0,0 @@ -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 diff --git a/src/tanks/main.js b/src/tanks/main.js new file mode 100644 index 0000000..1d220c7 --- /dev/null +++ b/src/tanks/main.js @@ -0,0 +1,39 @@ +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; + + + +} + diff --git a/src/tanks/game/level.js b/src/tanks/map/level.js similarity index 100% rename from src/tanks/game/level.js rename to src/tanks/map/level.js diff --git a/src/portal/util/loc.js b/src/tanks/map/loc.js similarity index 95% rename from src/portal/util/loc.js rename to src/tanks/map/loc.js index 659a6d8..f90f3cf 100644 --- a/src/portal/util/loc.js +++ b/src/tanks/map/loc.js @@ -1,16 +1,9 @@ // [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); @@ -48,6 +41,9 @@ Loc = new Y.Class('Loc', math.Vec, { 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 diff --git a/src/tanks/util/pathmap.js b/src/tanks/map/pathmap.js similarity index 100% rename from src/tanks/util/pathmap.js rename to src/tanks/map/pathmap.js diff --git a/src/tanks/ui.js b/src/tanks/ui.js deleted file mode 100644 index 88c3ddb..0000000 --- a/src/tanks/ui.js +++ /dev/null @@ -1,91 +0,0 @@ - -// 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 diff --git a/src/tanks/ui.main.js b/src/tanks/ui.main.js new file mode 100644 index 0000000..ad074a0 --- /dev/null +++ b/src/tanks/ui.main.js @@ -0,0 +1,61 @@ +// 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(); + } +} + diff --git a/src/tanks/util/grid.js b/src/tanks/ui/grid.js similarity index 100% rename from src/tanks/util/grid.js rename to src/tanks/ui/grid.js diff --git a/src/tanks/game/player.js b/src/tanks/ui/player.js similarity index 100% rename from src/tanks/game/player.js rename to src/tanks/ui/player.js diff --git a/tanks.php b/tanks.php new file mode 100644 index 0000000..1be4094 --- /dev/null +++ b/tanks.php @@ -0,0 +1,86 @@ +\n"; +} + + + +?> + diff --git a/test/math/index.php b/test/math/index.php index 2c6a179..c4ea7f5 100644 --- a/test/math/index.php +++ b/test/math/index.php @@ -63,37 +63,15 @@ h1 { position:fixed; top:0; right:0; margin:0; padding:0; font-size:3em; color:#
\n"; -} +require "../../tanks.php"; +Tanks::writeTags(null, "../../"); +$scripts = array( + "math.test.js" +); foreach ($scripts as $s) js($s); + ?>