From 83ab0d4d9634b02f71ab7a40ffb7e9a6a7f85b9a Mon Sep 17 00:00:00 2001 From: dsc Date: Tue, 11 Jan 2011 00:59:05 -0800 Subject: [PATCH] Adds config to toggle rock gap on divide. --- data/config.yaml | 3 +- data/types/levels.yaml | 25 ++++++------- src/tanks/effects/stat.cjs | 37 +++++++++++++++++-- src/tanks/map/drywall.cjs | 63 -------------------------------- src/tanks/map/index.cjs | 2 +- src/tanks/map/rock.cjs | 86 ++++++++++++++++++++++++++++++++++++++++++++ src/tanks/map/wall.cjs | 2 +- 7 files changed, 134 insertions(+), 84 deletions(-) delete mode 100644 src/tanks/map/drywall.cjs create mode 100644 src/tanks/map/rock.cjs diff --git a/data/config.yaml b/data/config.yaml index 9c01445..52788cd 100644 --- a/data/config.yaml +++ b/data/config.yaml @@ -8,7 +8,8 @@ debug: # showGridCoords : false map: refSize : &ref_size 50 - minSplitSize : 12.5 + rockSizeMin : 12.5 + rockGapOnDivide : true pathing: pathSquare : *ref_size overlayAiPaths : false diff --git a/data/types/levels.yaml b/data/types/levels.yaml index 43fc167..f400949 100644 --- a/data/types/levels.yaml +++ b/data/types/levels.yaml @@ -29,9 +29,9 @@ types: - type: fence args: [360,210, 30,30] - - type: drywall + - type: rock args: [400,200, 25,25] - - type: drywall + - type: rock args: [425,225, 25,25] - type: fence args: [460,210, 30,30] @@ -43,26 +43,23 @@ types: - type: fence args: [210,210, 30,30] - - type: drywall + - type: rock args: [50,350, 50,50] - - type: drywall + - type: rock args: [100,350, 50,50] - - type: drywall + - type: rock args: [50,400, 50,50] - - type: drywall + - type: rock args: [100,400, 50,50] - - type: drywall + - type: rock args: [150,300, 50,50] units: - type: player align: 1 - loc: [325,475] + loc: [425,425] - type: blue align: 1 - loc: [75,475] - # - type: blue - # align: 1 - # loc: [175,475] + loc: [175,475] - type: green align: 2 loc: [75,25] @@ -71,10 +68,10 @@ types: loc: [25,375] - type: green align: 2 - loc: [425,75] + loc: [425,125] items: - type: nitro - loc: [425,425] + loc: [325,475] events: [] art: bg: '' diff --git a/src/tanks/effects/stat.cjs b/src/tanks/effects/stat.cjs index 82209f9..763aa20 100644 --- a/src/tanks/effects/stat.cjs +++ b/src/tanks/effects/stat.cjs @@ -55,6 +55,34 @@ Y.subclass('Stat', { }, /** + * @param {Number} dv Amount to add to base and max value. + * @param {StatInvariant} [inv=FULL] Invariant to restore for current value. + * @return {this} + */ + setBase : function setBase(v, inv){ + var dv = v - this.base; + this.base = v; + return this.modifyMax(dv, inv || FULL); + }, + + /** + * @param {Number} dv Amount to add to current value. + * @param {StatInvariant} [inv=FULL] Invariant to restore for current value. + * @return {this} + */ + setMax : function setMax(v, inv){ + return this.modifyMax(v - this.max, inv); + }, + + setPart : function setPart(part, v, inv){ + var method = + (part === 'max' ? 'setMax' : + (part === 'base' ? 'setBase' : 'set')); + return this[method](v, inv); + }, + + + /** * @param {Number} dv Amount to add to current value. Values above the max will be set to max. * @return {this} */ @@ -79,14 +107,14 @@ Y.subclass('Stat', { */ modifyMax : function modifyMax(dv, inv){ var v = this.val - , oldmax = this.max; - this.max += dv; + , oldmax = this.max + , max = this.max = oldmax + dv; switch ( inv ) { case NONE: break; case RATIO: - v = (v / oldmax) * this.max; + v = (v / oldmax) * max; break; case FULL: @@ -94,8 +122,9 @@ Y.subclass('Stat', { v += dv; break; } + if (v > max) v = max; this.val = (this.integer ? Math.round(v) : v); - this.ratio = this.val / this.max; + this.ratio = this.val / max; return this; }, diff --git a/src/tanks/map/drywall.cjs b/src/tanks/map/drywall.cjs deleted file mode 100644 index 4d2c4c4..0000000 --- a/src/tanks/map/drywall.cjs +++ /dev/null @@ -1,63 +0,0 @@ -var Y = require('Y').Y -, clamp = require('ezl/math').clamp -, Vec = require('ezl/math/vec').Vec - -, config = require('tanks/config').config -, Wall = require('tanks/map/wall').Wall -, - - -Drywall = -exports['Drywall'] = -Wall.subclass('Drywall', { - // config - minSplitSize : null, - get canSplit() { return (this.width > this.minSplitSize); }, - - // instance - isReflective : false, - isBoundary : false, - - fillStyle : 'rgba(196,167,158, 0.25)', - strokeStyle : 'rgba(0,0,0, 0.25)', - lineWidth : 1, - - stats : { - hp : 1, - }, - - - - init : function initDrywall(x,y, w,h, hp){ - this.lineWidth = clamp(Math.round(Math.min(w,h) * 0.2), 1, 3); - Wall.init.call(this, x,y, w,h, this.isBoundary); - }, - - 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 - , x, y, wall - ; - for (x = _x; x this.rockSizeMin); }, + + + fillStyle : 'rgba(196,167,158, 0.25)', + strokeStyle : 'rgba(0,0,0, 0.25)', + lineWidth : 1, + lineRatio : 0.2, // ratio of min(width,height) to lineWidth + + stats : { + hp : 1, + }, + + + + init : function initRock(x,y, w,h, hp){ + this.lineWidth = clamp(Math.round(Math.min(w,h) * this.lineRatio), 1, 3); + Wall.init.call(this, x,y, w,h, this.isBoundary); + if (hp) this.stats.hp.setMax(hp); + }, + + divide : function divide(gap){ + if (!this.isDivisible) + return this; + + var _x = this.loc.x, _y = this.loc.y + , xMax = _x+this.width, yMax = _y+this.height + , size = this.width * 0.5 + + , gapOk = this.rockGapOnDivide + , 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, rock + ; + + for (x = _x; x