From: dsc Date: Wed, 10 Nov 2010 06:24:56 +0000 (-0800) Subject: Reorg of packages. X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=11bce9446f42f7eed3d5bfbeb8024ce5eea35df5;p=tanks.git Reorg of packages. --- diff --git a/src/tanks/game/map.game.js b/src/tanks/game/map.game.js deleted file mode 100644 index a6dc4f7..0000000 --- a/src/tanks/game/map.game.js +++ /dev/null @@ -1,158 +0,0 @@ - -Y(Game.prototype).extend({ - - initMap : function initMap(){ - // var self = this; - - this.byId = {}; - this.units = new Y.YArray(); - this.bullets = new Y.YArray(); - this.blockers = new Y.YArray(); - - this.pathmap = new PathMap(0,0, COLUMNS*REF_SIZE, ROWS*REF_SIZE, CAPACITY); - - var root = - this.root = - this.grid = - new Grid(COLUMNS,ROWS, CELL_SIZE) - .appendTo(this.viewport); - this.level = - new Level(this, root.layerWidth, root.layerHeight ) - .appendTo(this.root); - - // Agent.addEventListener('create', function(evt){ - // self.addAgent(evt.instance); - // }); - // Agent.addEventListener('destroy', function(evt){ - // self.killAgent(evt.instance); - // }); - }, - - - // *** Path Map Management *** // - - addBlocker : function addBlocker(agent){ - var bb = agent.boundingBox; - if (agent.blocking && bb) - agent.region = this.pathmap.set(bb.x1,bb.y1, bb.x2,bb.y2, agent); - return agent; - }, - - removeBlocker : function removeBlocker(agent){ - if (agent.region) - this.pathmap.remove(agent.region); - return agent; - }, - - updateBlocker : function updateBlocker(agent){ - this.removeBlocker(agent); - this.addBlocker(agent); - }, - - - // *** Agent Management *** // - - addUnit : function addUnit(unit, col,row){ - unit.game = this; - - if (col !== undefined) { - // Center unit in square - var sqX = (col || 0) * REF_SIZE - , sqY = (row || 0) * REF_SIZE - , x = sqX + (REF_SIZE-unit.width) /2 - , y = sqY + (REF_SIZE-unit.height)/2 ; - - unit.setLocation(x,y); - unit.render( this.level ); - } - - this.addBlocker(unit); - - if ( !this.byId[unit.id] ) { - this.byId[unit.id] = unit; - this.units.push(unit); - } - - return unit; - }, - - addAgent : function addAgent(agent){ - agent.game = this; - if (agent.id === undefined) return agent; - - this.addBlocker(agent); - - if ( !this.byId[agent.id] ) { - this.byId[agent.id] = agent; - if (agent instanceof Ability) - this.abilities.push(agent); - else - this.units.push(agent); - } - - return agent; - }, - - killAgent : function killAgent(agent){ - delete this.byId[agent.id]; - if (agent instanceof Ability) - this.abilities.remove(agent); - else - this.units.remove(agent); - - this.removeBlocker(agent); - return agent; - }, - - moveAgentTo : function moveAgentTo(agent, x,y){ - this.removeBlocker(agent); - agent.setLocation(x,y); - this.addBlocker(agent); - return agent; - }, - - getUnitAt : function getUnitAt(x,y){ - return this.grid.get(x,y); - }, - - getUnitsAt : function getUnitsAt(x1,y1, x2,y2){ - return this.grid.get(x1,y1, x2,y2); - } - -}); - -Y(Game.prototype).extend({ - - resize : function resize(){ - var ratio = COLUMNS / ROWS - , el = this.el - , p = el.parent() - , pw = p.width(), ph = p.height() - , pRatio = pw / ph - ; - - if ( ratio > pRatio ) - CELL_SIZE = Math.floor((pw-GRID_OFFSET*2) / COLUMNS); - else - CELL_SIZE = Math.floor((ph-GRID_OFFSET*2) / ROWS); - - SCALE = CELL_SIZE/REF_SIZE; - - var w = COLUMNS*CELL_SIZE - , h = ROWS*CELL_SIZE - , canvas = this.canvas[0]; - - this.el.width(w).height(h); - this.canvas.width(w).height(h); - canvas.width = w; - canvas.height = h; - - this.el.offset({ - top : (ph - h) / 2, - left : (pw - w) / 2 - }); - - this.ctx.scale(SCALE,SCALE); - } - -}); diff --git a/src/tanks/main.js b/src/tanks/main.js index 1d220c7..e992043 100644 --- a/src/tanks/main.js +++ b/src/tanks/main.js @@ -1,10 +1,9 @@ jQuery(main); function main(){ - v = $('#viewport'); LBT = new Game(); - + var sq = REF_SIZE , wall = new Wall(6*sq,1*sq, 1*sq,4*sq); @@ -34,6 +33,6 @@ function main(){ tr = B.trajectory; - + setupUI(); } diff --git a/src/tanks/ui.main.js b/src/tanks/ui.main.js deleted file mode 100644 index ad074a0..0000000 --- a/src/tanks/ui.main.js +++ /dev/null @@ -1,61 +0,0 @@ -// 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/tanks.php b/tanks.php index 1be4094..f0aad60 100644 --- a/tanks.php +++ b/tanks.php @@ -12,7 +12,7 @@ class Tanks { static $mainScripts = array( "src/tanks/main.js", - "src/tanks/ui.main.js" + "src/tanks/main-ui.js" ); static $srcScripts = array( @@ -31,7 +31,7 @@ class Tanks { "src/tanks/ui/player.js", "src/tanks/game/game.js", - "src/tanks/game/map.game.js" + "src/tanks/game/game-map.js" ); static $libScripts = array(