From d5cc40768d911b0bd0e524357b31c34843d6a25a Mon Sep 17 00:00:00 2001 From: dsc Date: Fri, 3 Dec 2010 21:56:22 -0800 Subject: [PATCH] Culls dead source. Moves future.js to act as a package itself. --- src/ezl/index.cjs | 7 +- src/future.js | 109 +++++++++++++++++ src/lessly/future.js | 109 ----------------- src/simoon/ability/ability.js | 61 ---------- src/simoon/ability/laser.js | 75 ------------ src/simoon/ability/projectile.js | 28 ----- src/simoon/game/calc.js | 24 ---- src/simoon/game/draw.js | 73 ------------ src/simoon/game/game.js | 54 --------- src/simoon/game/map.js | 89 -------------- src/simoon/globals.js | 32 ----- src/simoon/player/test-player.js | 48 -------- src/simoon/simoon.js | 16 --- src/simoon/ui.js | 99 --------------- src/simoon/unit/agent.js | 243 -------------------------------------- src/simoon/unit/creep.js | 47 -------- src/simoon/unit/tower.js | 43 ------- src/simoon/unit/unit.js | 26 ---- 18 files changed, 113 insertions(+), 1070 deletions(-) create mode 100644 src/future.js delete mode 100644 src/lessly/future.js delete mode 100644 src/simoon/ability/ability.js delete mode 100644 src/simoon/ability/laser.js delete mode 100644 src/simoon/ability/projectile.js delete mode 100644 src/simoon/game/calc.js delete mode 100644 src/simoon/game/draw.js delete mode 100644 src/simoon/game/game.js delete mode 100644 src/simoon/game/map.js delete mode 100644 src/simoon/globals.js delete mode 100644 src/simoon/player/player.js delete mode 100644 src/simoon/player/test-player.js delete mode 100644 src/simoon/simoon.js delete mode 100644 src/simoon/ui.js delete mode 100644 src/simoon/unit/agent.js delete mode 100644 src/simoon/unit/creep.js delete mode 100644 src/simoon/unit/tower.js delete mode 100644 src/simoon/unit/unit.js diff --git a/src/ezl/index.cjs b/src/ezl/index.cjs index 955dc17..f1eefdc 100644 --- a/src/ezl/index.cjs +++ b/src/ezl/index.cjs @@ -1,5 +1,6 @@ // -*- mode: JavaScript; tab-width: 4; indent-tabs-mode: nil; -*- -//@require('jquery') -//@require('lessly/future') -//@require('Y') +//@package ezl +//@require jquery +//@require lessly/future +//@require Y diff --git a/src/future.js b/src/future.js new file mode 100644 index 0000000..5531d95 --- /dev/null +++ b/src/future.js @@ -0,0 +1,109 @@ +(function(_Object, _Array, _Function){ + +var P = "prototype" +, AP = _Array[P] +, FP = _Function[P] +, slice = AP.slice +, objToString = _Object[P].toString +; + +if ( !_Array.slice ) { + _Array.slice = function slice(a){ + return slice.apply(a, slice.call(arguments, 1)); + }; +} + +// JavaScript 1.6 & 1.7 + +if ( !AP.indexOf ) { + AP.indexOf = function indexOf( value ){ + for ( var A = this, i = 0, l = A.length; i < l; ++i ) + if ( A[i] === value ) + return i; + return -1; + }; +} + +if ( !AP.lastIndexOf ) { + AP.lastIndexOf = function lastIndexOf( value ){ + for ( var A = this, i = A.length-1; i >= 0; --i ) + if ( A[i] === value ) + return i; + return -1; + }; +} + + +if ( !AP.map ) { + AP.forEach = function forEach( fn, context ){ + for ( var A = this, context = context||A, i = 0, l = A.length; i < l; ++i ) + fn.call( context, A[i], i, A ); + }; + + AP.map = function map( fn, context ){ + for ( var A = this, context = context||A, i = 0, l = A.length, r = new _Array(l); i < l; ++i ) + r[i] = fn.call( context, A[i], i, A ); + return r; + }; + + AP.filter = function filter( fn, context ){ + for ( var A = this, context = context||A, i = 0, l = A.length, r = [], v = A[0]; i < l; v = A[++i] ) + if ( fn.call( context, v, i, A ) ) + r.push(v); + return r; + }; + + AP.every = function every( fn, context ){ + var A = this, context = context||A; + for (var i=0, l = A.length; i= 0; --i ) - if ( A[i] === value ) - return i; - return -1; - }; -} - - -if ( !AP.map ) { - AP.forEach = function forEach( fn, context ){ - for ( var A = this, context = context||A, i = 0, l = A.length; i < l; ++i ) - fn.call( context, A[i], i, A ); - }; - - AP.map = function map( fn, context ){ - for ( var A = this, context = context||A, i = 0, l = A.length, r = new _Array(l); i < l; ++i ) - r[i] = fn.call( context, A[i], i, A ); - return r; - }; - - AP.filter = function filter( fn, context ){ - for ( var A = this, context = context||A, i = 0, l = A.length, r = [], v = A[0]; i < l; v = A[++i] ) - if ( fn.call( context, v, i, A ) ) - r.push(v); - return r; - }; - - AP.every = function every( fn, context ){ - var A = this, context = context||A; - for (var i=0, l = A.length; i= this.duration) - this.game.killAgent(this); - else - Agent.prototype.act.call(this); - }, - - drawShape : function(ctx){ - var thick = 4.0 - , obox = this.owner.boundingBox - , tbox = this.target.boundingBox - , omid = obox.midpoint() - , tmid = tbox.midpoint() - , x1 = tbox.right.x + 2 - , y1 = omid.y - , x2 = obox.left.x - 2 - , y2 = omid.y - ; - - ctx.beginPath(); - ctx.lineWidth = thick; - // ctx.fillStyle = '#FFF6AE'; - ctx.strokeStyle = '#FFF6AE'; - - ctx.moveTo(x1,y1); - ctx.lineTo(x2,y2); - - // ctx.fill(); - ctx.stroke(); - ctx.closePath(); - }, - - attack : function(target){ - this.target = target; - - var full_damage = Calc.unitDamage(this, target) - , damage = full_damage * (ELAPSED / this.duration) - , killed = false - ; - - target.stats.hp -= damage; - if ( target.stats.hp <= 0 ) { - killed = true; - // this.game.killAgent(target); - target.destroy(); - } - - if ( killed || (this.elapsed >= this.duration) ) { - this.destroy(); - // this.game.killAgent(this); - logger(this.owner+"'s", this, 'hits', target, 'for', full_damage, 'damage'+(killed? ', killing it!' : '!')); - } - } - -}); diff --git a/src/simoon/ability/projectile.js b/src/simoon/ability/projectile.js deleted file mode 100644 index 9567d77..0000000 --- a/src/simoon/ability/projectile.js +++ /dev/null @@ -1,28 +0,0 @@ -Projectile = Ability.subclass('Projectile', { - stats : { - move : 2.0, // move speed (squares/sec) - range : 0.1 // attack range (squares) - }, - - - - drawShape : function(ctx){ - var radius = 5.0 - , x1 = this.loc.x - , y1 = this.loc.y - , x2 = x1 + radius*2 - , y2 = y1 - ; - - ctx.beginPath(); - ctx.lineWidth = 3; - ctx.fillStyle = '#5992FF'; - ctx.strokeStyle = '#244792'; - - ctx.arc(x1,y1, radius, 0, TWO_PI, false); - - ctx.fill(); - ctx.stroke(); - ctx.closePath(); - } -}); diff --git a/src/simoon/game/calc.js b/src/simoon/game/calc.js deleted file mode 100644 index 9632226..0000000 --- a/src/simoon/game/calc.js +++ /dev/null @@ -1,24 +0,0 @@ -(function(){ - -/* Inline all these */ -Calc = { - moveX : function(unit){ - return unit.loc.x + (unit.facing * unit.stats.move * REF_SIZE * FRAMETH); - }, - - rangeX : function(unit){ - return unit.loc.x + (unit.facing * unit.stats.range * REF_SIZE); - }, - - damage : function(power, armor, hard){ - return Math.max(0, (power - hard) * (armor ? 1 - Math.log(armor/2)/5 : 1)); - }, - - unitDamage : function(attacker, defender){ - var a = attacker.stats, d = defender.stats; - return Calc.damage(a.power, d.armor, d.hard); - } - -}; - -})(); diff --git a/src/simoon/game/draw.js b/src/simoon/game/draw.js deleted file mode 100644 index 5eb677a..0000000 --- a/src/simoon/game/draw.js +++ /dev/null @@ -1,73 +0,0 @@ -Y(Game.prototype).extend({ - - initDraw : function(){ - this.canvas = $('').appendTo(this.el); - this.ctx = this.canvas[0].getContext('2d'); - this.resize(); - }, - - clearGrid : function(){ - var ctx = this.ctx; - ctx.beginPath(); - ctx.clearRect(0,0, this.canvas.width(),this.canvas.height()); - ctx.closePath(); - }, - - drawGrid : function(){ - var ctx = this.ctx - , w = REF_SIZE* COLUMNS - , h = REF_SIZE* ROWS; - - ctx.beginPath(); - ctx.lineWidth = 1; - ctx.strokeStyle = '#6E6E6E'; - - for (var row=0, y=0; row<=ROWS; y = (++row) * REF_SIZE){ - ctx.moveTo(0,y); - ctx.lineTo(w,y); - } - - for (var col=0, x=0; col<=COLUMNS; x = (++col) * REF_SIZE){ - ctx.moveTo(x,0); - ctx.lineTo(x,h); - } - - ctx.stroke(); - ctx.closePath(); - }, - - resize : function(){ - 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/simoon/game/game.js b/src/simoon/game/game.js deleted file mode 100644 index 82af1ff..0000000 --- a/src/simoon/game/game.js +++ /dev/null @@ -1,54 +0,0 @@ - -Game = new Y.Class('Game', { - - init : function(el){ - this.loop = new EventLoop(this, FRAME_RATE); - - // Seal all methods - // Y.bindAll(this); - this.resize = this.resize.bind(this); - this.tick = this.tick.bind(this); - - this.el = $(el); - this.initMap(); - this.initDraw(); - - this.addEventListener('tick', this.tick); - }, - showOverlay : false, - - /** - * Main Event Loop. - */ - tick : function(evt){ - var d = evt.data; - - NOW = d.now; - ELAPSED = d.elapsed; - TICKS = d.ticks; - - var ctx = this.ctx - , Ps = this.abilities.clone() - , Us = this.units.clone().sort(Unit.turnOrdering) // Copy to avoid mutation under iteration - ; - - this.clearGrid(); - this.drawGrid(); - - // Prompt all projectiles and units to act - Ps.invoke('act'); - Us.invoke('act'); - - // Prompt all remaining units to draw - this.abilities.invoke('draw', ctx); - this.units.invoke('draw', ctx); - - // XXX: Collect the dead - - this.grid.removeOverlay(this.el); - if (this.showOverlay) this.grid.overlay(this.el); - } - -}); - - diff --git a/src/simoon/game/map.js b/src/simoon/game/map.js deleted file mode 100644 index 7a6668f..0000000 --- a/src/simoon/game/map.js +++ /dev/null @@ -1,89 +0,0 @@ -Y(Game.prototype).extend({ - - initMap : function(){ - var self = this; - - // this.blockers = new Y.YArray(); - this.byId = {}; - this.units = new Y.YArray(); - this.abilities = new Y.YArray(); - this.grid = new Grid(0,0, COLUMNS*REF_SIZE, ROWS*REF_SIZE, GRID_CAPACITY); - - Agent.addEventListener('create', function(evt){ - self.addAgent(evt.instance); - }); - Agent.addEventListener('destroy', function(evt){ - self.killAgent(evt.instance); - }); - }, - - - // *** Path Map Management *** // - - addBlocker : function(agent){ - var bb = agent.boundingBox; - if (agent.blocking && bb) - agent.region = this.grid.set(bb.x1,bb.y1, bb.x2,bb.y2, agent); - return agent; - }, - - removeBlocker : function(agent){ - if (agent.region) - this.grid.remove(agent.region); - return agent; - }, - - updateBlocker : function(agent){ - this.removeBlocker(agent); - this.addBlocker(agent); - }, - - - // *** Agent Management *** // - - addAgent : function(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(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(agent, x,y){ - this.removeBlocker(agent); - agent.setLocation(x,y); - this.addBlocker(agent); - return agent; - }, - - getUnitAt : function(x,y){ - return this.grid.get(x,y); - }, - - getUnitsAt : function(x1,y1, x2,y2){ - return this.grid.get(x1,y1, x2,y2); - } - -}); - - diff --git a/src/simoon/globals.js b/src/simoon/globals.js deleted file mode 100644 index 5cbd160..0000000 --- a/src/simoon/globals.js +++ /dev/null @@ -1,32 +0,0 @@ -var logger = new Log('#log') - -, PI = Math.PI -, TWO_PI = PI*2 -, HALF_PI = PI/2 - -, COLUMNS = 10 -, ROWS = 8 -, GRID_CAPACITY = 32 - -, REF_SIZE = 50 -, CELL_SIZE = REF_SIZE -, GRID_OFFSET = 10 - -, VIEWPORT_DIST = 100 -, MIN_X_DIST = -1*VIEWPORT_DIST -, MAX_X_DIST = COLUMNS*REF_SIZE + VIEWPORT_DIST - -, FRAME_RATE = 30 -, MS_PER_FRAME = 1000 / FRAME_RATE -, FRAMETH = 1.0 / FRAME_RATE - -, SCALE = CELL_SIZE / REF_SIZE -, SCALE_SPEED = SCALE / FRAME_RATE - -, FACING_RIGHT = 1 -, FACING_LEFT = -1 - -, NOW = new Date().getTime() // Current tick's timestamp (ms) -, ELAPSED = FRAMETH // Time (ms) since previous tick -, TICKS = 0 // Ticks since start of game -; diff --git a/src/simoon/player/player.js b/src/simoon/player/player.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/simoon/player/test-player.js b/src/simoon/player/test-player.js deleted file mode 100644 index b314e01..0000000 --- a/src/simoon/player/test-player.js +++ /dev/null @@ -1,48 +0,0 @@ -TestPlayer = new Y.Class('TestPlayer', { - init : function(game){ - var self = this; - this.game = game; - this.game.el.bind('click', function(evt){ - evt.preventDefault(); - evt.stopPropagation(); - if (evt.shiftKey) - self.addTowerClick(evt); - else - self.addCreepClick(evt); - }); - }, - - pageToGrid : function(x,y){ - var off = this.game.el.offset(); - return { - 'x' : (x - off.left)/SCALE, - 'y' : (y - off.top)/SCALE - }; - }, - - pageToCell : function(x,y){ - var pos = this.pageToGrid(x,y); - return { - 'x' : Math.floor(pos.x / REF_SIZE) * REF_SIZE, - 'y' : Math.floor(pos.y / REF_SIZE) * REF_SIZE - }; - }, - - addTowerClick : function(evt){ - var cell = this.pageToCell(evt.pageX,evt.pageY) - , units = this.game.getUnitsAt(cell.x,cell.y, cell.x+REF_SIZE,cell.y+REF_SIZE); - if (units.size() === 0) - new Creep(this.game, 1).addToSquare(cell.x/REF_SIZE, cell.y/REF_SIZE); - else - logger("Cannot create Creep -- unit exists there!"); - }, - - addCreepClick : function(evt){ - var cell = this.pageToCell(evt.pageX,evt.pageY) - , units = this.game.getUnitsAt(cell.x,cell.y, cell.x+REF_SIZE,cell.y+REF_SIZE); - if (units.size() === 0) - new Tower(this.game, 0).addToSquare(cell.x/REF_SIZE, cell.y/REF_SIZE); - else - logger("Cannot create Tower -- unit exists there!"); - } -}); \ No newline at end of file diff --git a/src/simoon/simoon.js b/src/simoon/simoon.js deleted file mode 100644 index 3af3351..0000000 --- a/src/simoon/simoon.js +++ /dev/null @@ -1,16 +0,0 @@ -jQuery(function(){ - Simoon = new Game('#grid'); - - pl = Simoon.player = new TestPlayer(Simoon); - - for (var row=0; row', ' | ', '', ' || '); - - setInterval(updateInfo, 1000); - updateInfo(); - - // Update Text on Click - Simoon.addEventListener('start', fixStartText); - Simoon.addEventListener('stop', fixStartText); - - // Start button (click or return key) - $('.start_btn').bind('click', toggleGame); - $(document).bind('keydown', 'return', toggleGame); - - $(document).bind('keydown', 'ctrl+l', function(evt){ $('#log').toggle(); }); - $(document).bind('keydown', 'ctrl+o', function(evt){ Simoon.showOverlay = !(Simoon.showOverlay); }); - - // Show Overlays - $('.overlay_btn').bind('click', function(evt){ - Simoon.showOverlay = !(Simoon.showOverlay); - fixOverlayText(); - return false; - }); - - // Fix Starting text - fixStartText(); - fixOverlayText(); - - // Fix grid-size on resize - $(window).bind('resize', function(evt){ - Simoon.resize(evt); - - if (!Simoon.loop.running) { - Simoon.start(); - Simoon.stop(); - } - }); - - // -}); \ No newline at end of file diff --git a/src/simoon/unit/agent.js b/src/simoon/unit/agent.js deleted file mode 100644 index a25406d..0000000 --- a/src/simoon/unit/agent.js +++ /dev/null @@ -1,243 +0,0 @@ -(function(){ -var uid = 0; - -this.Agent = new Y.Class('Agent', { - init : function(game, align){ - this.id = uid++; - this.align = align; - this.game = game; - - this.projectiles = new Y.YArray(); - - // this.filterTarget = this.filterTarget.bind(this); - this.fillStats(); - this.createCooldowns(); - - this.fire('ready'); - }, - - // Attributes - stats: { - hp : 100, // hitpoints - move : 0.2, // move speed (squares/sec) - - range : 2.0, // attack range (squares) - power : 1, // attack power - speed : 1.0, // attacks/sec - - armor : 0.0, // armor - hard : 0 // hardness (damage reduction) - }, - - // *** Bookkeeping *** // - - dead : false, - - destroy : function(){ - if (this.dead) return; - - this.dead = true; - this.fire('destroy', this); - }, - - loc : null, - boundingBox : null, - - facing : FACING_LEFT, - - // Bounding box size - width : REF_SIZE, - height : REF_SIZE, - - // Offset from top-left when squaring this unit - offsetX : 0, - offsetY : 0, - - setLocation : function(x,y){ - var loc = this.loc; - if (loc && loc.x === x && loc.y === y) - return loc; - loc = this.loc = new Loc(x,y); - this.boundingBox = new Rect(x,y, x+this.width,y+this.height); - return loc; - }, - - /** - * Front-most point of the agent, accounting for facing. - */ - front : function(){ - return this.boundingBox[ this.facing === FACING_LEFT ? 'x1' : 'x2' ]; - }, - - - - // *** Gameplay Methods *** // - - addToSquare : function(col,row){ - var x = col*REF_SIZE + this.offsetX - , y = row*REF_SIZE + this.offsetY; - this.setLocation(x,y); - this.game.addAgent(this); - return this; - }, - - fillStats : function(){ - this.stats = Agent.fillStats(this.stats); - }, - - createCooldowns : function(){ - this.cooldowns = Y({ - attack: new Cooldown(1000 * this.stats.speed) - }); - }, - - /** - * Determines what the creep should do -- move, attack, etc. - */ - act : function(){ - if (this.dead) return this; - - this.cooldowns.invoke('update', NOW); - - var bb = this.boundingBox - , x1 = Calc.rangeX(this), x2 = bb.left.x - , y1 = bb.top.y, y2 = bb.bottom.y - , units = this.game - .getUnitsAt(x1,y1, x2,y2) - .filter(this.filterTarget, this) - , target = this.closest(units) - ; - if (target) - this.attack(target); - else - this.move(); - - if (bb.x1 <= MIN_X_DIST || bb.x2 >= MAX_X_DIST) - this.destroy(); - - return this; - }, - - filterTarget : function(unit){ return unit.align !== this.align; }, - - closest : function(units){ - if (units.length === 0 || units.size() === 0) return; - - var bb = this.boundingBox - , d = this.facing - , p = (d === FACING_LEFT ? 'x2' : 'x1') - , x = (d === FACING_LEFT ? bb.x1 : bb.x2) - , sign = (d === FACING_LEFT ? 1 : -1) - , best = units - .reduce(function(best, unit){ - var ub = unit.boundingBox - , dist = (x - ub[p]) * sign - - if (dist < 0) dist = Infinity; - - if (!best || dist <= best.distance) - return { unit:unit, distance:dist }; - else - return best; - }, null); - return best.end().unit; - }, - - move : function(){ - this.game.moveAgentTo(this, Calc.moveX(this), this.loc.y); - return this; - }, - - attack : function(unit){ - var atk_cool = this.cooldowns.attr('attack'); - if ( atk_cool.activate(NOW) ) { - // logger(this+'.attack(', unit, ')'); - this.doAttack(unit); - } - return this; - }, - - doAttack : function(target){ - this.fireProjectile(target); - }, - - fireProjectile : function(target){ - var AbilityType = this.projectile - , p = new AbilityType(this, target); - this.projectiles.push(p); - this.game.addAgent(p); - return p; - }, - - - - draw : function(ctx){ - if (this.dead) return; - - this.drawShape(ctx); - if (this.blocking) this.drawHealth(ctx); - }, - - drawShape : function(ctx){}, - - drawHealth : function(ctx){ - var stats = this.stats - , ratio = stats.hp / stats.hp_max - , x = this.loc.x - this.offsetX - , sq = this.loc.toSquare() - , x1 = x + 5, x2 = x + REF_SIZE - 5 - , w = x2-x1, h = 5 - , y1 = sq.y2 - h - 3; - - // draw box outline - ctx.beginPath(); - ctx.lineWidth = 1; - ctx.strokeStyle = "#ffffff"; - ctx.fillStyle = "#980011"; - ctx.rect(x1,y1, w,h); - ctx.fill(); - // ctx.stroke(); - ctx.closePath(); - - // draw hp - ctx.beginPath(); - ctx.fillStyle = "#83BB32"; - ctx.rect(x1,y1, w*ratio,h); - ctx.fill(); - ctx.closePath(); - - }, - - toString : function(){ - return this.className+'(id='+this.id+', loc='+this.loc+')'; - } -}); - - - -Y(Agent).extend({ - - fillStats : function(stats){ - var st = Y(stats) - , stats = st.clone().end() - ; - - st.forEach(function(v, k){ - var k = Y(k) - , k_ = k.rtrim('_max') - ; - - if ( k.endsWith('_max') ) { - if ( stats[k_] === undefined ) - stats[k_] = v; - - } else if ( stats[k+'_max'] === undefined ) - stats[k+'_max'] = v; - - }); - - return stats; - } -}); - -})(); diff --git a/src/simoon/unit/creep.js b/src/simoon/unit/creep.js deleted file mode 100644 index c713fea..0000000 --- a/src/simoon/unit/creep.js +++ /dev/null @@ -1,47 +0,0 @@ -(function(){ -var -OFF = 10, -SIZE = REF_SIZE - 2*OFF, -HALF = SIZE/2; - -this.Creep = Unit.subclass('Creep', { - facing : FACING_LEFT, - projectile : Laser, - - // Attributes - stats: { - hp : 10, // hitpoints - move : 0.25, // move speed (squares/sec) - - range : 2.0, // attack range (squares) - power : 2.0, // attack power - speed : 0.5, // attacks/sec - - armor : 0.0, // armor - hard : 0 // hardness (damage reduction) - }, - offsetX : OFF, - offsetY : OFF, - width : SIZE, - height : SIZE, - - drawShape : function(ctx){ - var x = this.loc.x - , y = this.loc.y; - - ctx.beginPath(); - ctx.lineWidth = 0; - ctx.fillStyle = '#E73075'; - - ctx.moveTo(x,y+HALF); - ctx.lineTo(x+SIZE,y); - ctx.lineTo(x+SIZE,y+SIZE); - ctx.lineTo(x,y+HALF); - - ctx.fill(); - ctx.closePath(); - } - -}); - -})(); diff --git a/src/simoon/unit/tower.js b/src/simoon/unit/tower.js deleted file mode 100644 index 0f4b2e7..0000000 --- a/src/simoon/unit/tower.js +++ /dev/null @@ -1,43 +0,0 @@ -(function(){ -var -OFFSET = 10, -SIZE = REF_SIZE - 2*OFFSET, - -Tower = Unit.subclass('Tower', { - facing : FACING_RIGHT, - projectile : Projectile, - - // Attributes - stats: { - hp : 10, // hitpoints - move : 0, // move speed (squares/sec) - - range : 5, // attack range (squares) - power : 1, // attack power - speed : 1.0, // attacks/sec - - armor : 10.0, // armor - hard : 0 // hardness (damage reduction) - }, - - offsetX : OFFSET, - offsetY : OFFSET, - width : SIZE, - height : SIZE, - - drawShape : function(ctx){ - var x = this.loc.x - , y = this.loc.y; - - ctx.beginPath(); - ctx.lineWidth = 0; - ctx.fillStyle = "#F25522"; - ctx.rect(x,y, SIZE,SIZE); - ctx.fill(); - ctx.closePath(); - } - -}); -this.Tower = Tower; - -})(); diff --git a/src/simoon/unit/unit.js b/src/simoon/unit/unit.js deleted file mode 100644 index 4a66316..0000000 --- a/src/simoon/unit/unit.js +++ /dev/null @@ -1,26 +0,0 @@ -Unit = Agent.subclass('Unit', { - blocking : true, - projectile : Projectile, - - move : function(){ - var d = this.facing - , bb = this.boundingBox - , x1 = Calc.moveX(this), x2 = bb.right.x - d - , y1 = bb.top.y, y2 = bb.bottom.y - , units = this.game.getUnitsAt(bb.left.x+(d*5),y1, x2,y2).remove(this); - if (units.size() === 0) - try { - this.game.moveAgentTo(this, x1,this.loc.y); - } catch (e) { - console.log('Error moving units to ('+x1+','+this.loc.y+')', e); - } - } - -}); - -Y(Unit).extend({ - turnOrdering : function(u1, u2){ - return Y(u1.stats.speed).compare( u2.stats.speed ); - } - -}); -- 1.7.0.4