From 12ec112a2baa75608075c9b18ae32241b6d4c620 Mon Sep 17 00:00:00 2001 From: dsc Date: Sun, 9 Jan 2011 09:20:59 -0800 Subject: [PATCH] Fixes config; shores up fences and drywall. --- data/types/levels.yaml | 8 +++- src/Y/modules/y.scaffold.cjs | 11 +++-- src/ezl/layer/layer.cjs | 30 ++++++++++++-- src/tanks/effects/stat.cjs | 14 +++++- src/tanks/map/drywall.cjs | 87 +++++++++-------------------------------- src/tanks/map/fence.cjs | 43 +++++++++++++++++++- src/tanks/map/wall.cjs | 10 +---- src/tanks/thing/player.cjs | 1 + src/tanks/ui/configui.cjs | 7 ++- src/tanks/ui/main.cjs | 39 +++++++++---------- 10 files changed, 135 insertions(+), 115 deletions(-) diff --git a/data/types/levels.yaml b/data/types/levels.yaml index dc0aa88..47aa321 100644 --- a/data/types/levels.yaml +++ b/data/types/levels.yaml @@ -35,7 +35,13 @@ types: - type: fence args: [210,210, 30,30] - type: drywall - args: [50,350, 100,100] + args: [50,350, 50,50] + - type: drywall + args: [100,350, 50,50] + - type: drywall + args: [50,400, 50,50] + - type: drywall + args: [100,400, 50,50] - type: drywall args: [150,300, 50,50] units: diff --git a/src/Y/modules/y.scaffold.cjs b/src/Y/modules/y.scaffold.cjs index a17a77e..4fdbfe7 100644 --- a/src/Y/modules/y.scaffold.cjs +++ b/src/Y/modules/y.scaffold.cjs @@ -53,6 +53,7 @@ Y.subclass('Field', { init : function initField(chain, def, val, options){ options = options || {}; this.__emitter__ = new Emitter(this); + this.onChange = this.onChange.bind(this); this.id = chain; this.def = def; @@ -72,7 +73,7 @@ Y.subclass('Field', { this.build() .update(this.val); - jQuery(this.selector).live('change', this.onChange.bind(this)); + jQuery(this.selector).live('change', this.onChange); }, build : function build(){ @@ -99,7 +100,7 @@ Y.subclass('Field', { }, update : function update(val){ - var el = jQuery(this.selector); + var el = jQuery(this.selector).add(this.elField); if (val !== this.val) { this.old = this.val; this.val = val; @@ -107,7 +108,7 @@ Y.subclass('Field', { 'key' : this.id, 'oldval' : this.old, 'newval' : this.val, - 'el' : jQuery(this.selector) + 'el' : el }); el.val(val); } @@ -118,7 +119,7 @@ Y.subclass('Field', { }, onChange : function onChange(evt){ - var el = jQuery(this.selector); + var el = jQuery(evt.target); if (this.type === 'checkbox') this.update( el.attr('checked') ); else @@ -157,9 +158,11 @@ function create(config, el){ fields[chain] = field; group.append(field.el); config.addEventListener('set:'+chain, function onConfigSet(evt){ + // console.log('Config at '+evt.data.key+' changed!', field, evt.newval, evt); field.update(evt.data.newval); }); field.addEventListener('change', function onFieldChange(evt){ + // console.log('Field '+evt.data.key+' changed!', field, evt.newval, evt); config.set(evt.data.key, evt.data.newval); }); diff --git a/src/ezl/layer/layer.cjs b/src/ezl/layer/layer.cjs index 97dcdd3..3cae1c7 100644 --- a/src/ezl/layer/layer.cjs +++ b/src/ezl/layer/layer.cjs @@ -27,7 +27,7 @@ Y.subclass('Layer', { ctx : null, animActive : null, animQueue : null, - + _erased : null, layerWidth : 0, canvasWidth : 0, layerHeight : 0, canvasHeight : 0, @@ -60,6 +60,7 @@ Y.subclass('Layer', { this.children = new Y.YArray(); this.animActive = new Y.YArray(); this.animQueue = new Y.YArray(); + this._erased = new Y.YArray(); this.loc = new Loc(0,0); this.negBleed = new Loc(0,0); @@ -135,7 +136,7 @@ Y.subclass('Layer', { */ empty : function empty(ctx){ this.children.invoke('remove'); - this.clear(ctx); + this.clear(false, ctx); return this; }, @@ -485,6 +486,7 @@ Y.subclass('Layer', { this._openPath(_ctx); this.render(_ctx); this._closePath(_ctx); + this._erased.forEach(this._erase, this); } this.children.invoke('draw', ctx, force); @@ -533,10 +535,30 @@ Y.subclass('Layer', { return this; }, + erase : function erase(x,y, w,h, alsoChildren){ + this._erased.push({ 'x':x,'y':y, 'w':w,'h':h, 'alsoChildren':alsoChildren }); + this.dirty = true; + if (alsoChildren) + this.children.invoke('erase', x,y, w,h, alsoChildren); + return this; + }, + + _erase : function _erase(args){ + var x = args.x, y = args.y + , w = args.w, h = args.h; + + if (w < 0) w = this.canvas.width() + w; + if (h < 0) h = this.canvas.height() + h; + + this.ctx.beginPath(); + this.ctx.clearRect(x,y, w,h); + this.ctx.closePath(); + }, + /** * Clears this layer and optionally all children. */ - clear : function clear(ctx, clearChildren){ + clear : function clear(alsoChildren, ctx){ var w = this.canvas.width() , h = this.canvas.height(); ctx = ctx || this.ctx; @@ -544,7 +566,7 @@ Y.subclass('Layer', { ctx.setTransform(1,0,0,1,0,0); ctx.clearRect(-w,-h, 2*w,2*h); ctx.closePath(); - if (clearChildren) + if (alsoChildren) this.children.invoke('clear'); return this; }, diff --git a/src/tanks/effects/stat.cjs b/src/tanks/effects/stat.cjs index aa3f972..82209f9 100644 --- a/src/tanks/effects/stat.cjs +++ b/src/tanks/effects/stat.cjs @@ -44,17 +44,25 @@ Y.subclass('Stat', { }, /** - * @param {Number} dv Amount to add to current value. + * @param {Number} v New value for this stat. Values above the max will be set to max. * @return {this} */ - modify : function modify(dv){ - var v = Math.min(this.max, this.val+dv); + set : function set(v){ + var v = Math.min(this.max, v); this.val = (this.integer ? Math.round(v) : v); this.ratio = this.val / this.max; return this; }, /** + * @param {Number} dv Amount to add to current value. Values above the max will be set to max. + * @return {this} + */ + modify : function modify(dv){ + return this.set(this.val+dv); + }, + + /** * @param {Number} dv Amount to add to base and max value. * @param {StatInvariant} [inv=FULL] Invariant to restore for current value. * @return {this} diff --git a/src/tanks/map/drywall.cjs b/src/tanks/map/drywall.cjs index d4f8156..4d2c4c4 100644 --- a/src/tanks/map/drywall.cjs +++ b/src/tanks/map/drywall.cjs @@ -10,91 +10,43 @@ var Y = require('Y').Y Drywall = exports['Drywall'] = Wall.subclass('Drywall', { - minSplitSize : 25, + // config + minSplitSize : null, + get canSplit() { return (this.width > this.minSplitSize); }, + // instance isReflective : false, isBoundary : false, - isSplittable : true, - fillColors : [[139,49,20], [245,154,180], [255,246,174]], - - fillStyle : 'rgba(249,190,0, 0.25)', - strokeStyle : 'rgba(249,190,0, 0.5)', + fillStyle : 'rgba(196,167,158, 0.25)', + strokeStyle : 'rgba(0,0,0, 0.25)', lineWidth : 1, stats : { - hp : 3, + hp : 1, }, + init : function initDrywall(x,y, w,h, hp){ - this.stats = Y.extend({}, this.stats); - this.stats.hp = hp || this.stats.hp; - - var line = Math.round(Math.min(w,h) * 0.2); - this.lineWidth = clamp(line, 1, 3); - + this.lineWidth = clamp(Math.round(Math.min(w,h) * 0.2), 1, 3); Wall.init.call(this, x,y, w,h, this.isBoundary); - this.updateColor(); - }, - - updateColor : function updateColor(){ - var L = this.fillColors.length-1 - , i = clamp(Math.floor(this.stats.hp.ratio*L), 0, L) - , color = this.fillColors[i] - ; - this.fillStyle = 'rgba('+color.join(',')+', 0.25)'; - this.strokeStyle = 'rgba('+color.join(',')+', 0.50)'; - console.log(this+'color = '+this.fillStyle+' ('+i+')'); - return this; }, - dealDamage : function dealDamage(d, source){ - Wall.fn.dealDamage.apply(this, arguments); - if (!this.dead) { - var old = this.fillStyle; - if (old !== this.updateColor().fillStyle) - this.render(); - } - return this; - }, - - split : function split(gap){ - if (!this.isSplittable || this.width <= this.minSplitSize) + divide : function divide(){ + if (!this.canSplit) return this; var _x = this.loc.x, _y = this.loc.y , mx = _x+this.width, my = _y+this.height , size = this.width * 0.5 - , gapX = gap ? gap.x : Infinity - , gapY = gap ? gap.y : Infinity - , hp = Math.max(Math.round(this.stats.hp.max * 0.5), 1.0) - - , x, y, nextX, nextY, wall + , x, y, wall ; - - // console.group(this+'.split()'); - // console.log('gap: ('+gapX+','+gapY+')'); - // console.log('loc: '+this.loc); - // console.log('dim: w='+this.width+'; h='+this.height+'; size='+size); - // console.log('max: x='+mx+'; y='+my); - for (x = _x; xYou Win!

Play Again
'); - // Bind to all future restart buttons $('#gameover .restart') .live('click', function(evt){ @@ -89,7 +77,7 @@ function main(){ startGame(); }); - + // Load all data files cfg.dataLoader() .addEventListener('complete', function(evt){ $('#loading').hide(); @@ -282,6 +270,14 @@ function updateInfo(){ return false; } +function parseVisibility(v){ + if (typeof v === 'number') + return v; + if (typeof v === 'string') + return parseInt(v); + return (v ? SHOW : HIDE); +} + jQuery.fn.center = function centerJQ(){ var body = $('body'); this.css({ @@ -303,6 +299,7 @@ function updateOverlay(show){ } function updateUI(selector, action){ + action = parseVisibility(action); var el = $(selector); if (action === TOGGLE){ -- 1.7.0.4