align: 2
loc: [775,325]
items:
+ # - type: rockets # right next to start
+ # loc: [325,475]
- type: rockets
loc: [75,275]
- - type: rockets
- loc: [325,475]
- type: nitro
loc: [325,25]
import yaml, json, os, sys, re
from termcolor import colored
+APP_FILE = 'lttlst.min.js'
BUILD_DIR = path('build')
SRC_DIRS = [ path('src')/d for d in ('Y', 'ezl', 'tanks') ]
DATA_DIR = path('data')
f.write(tags.replace('src="build/', 'src="build/{}/'.format(git_version)))
with path('build/versioned-build.html').open('w') as f:
f.write('<script>BUILD="build/{}";</script>\n'.format(git_version))
+ with path('build/versioned-app.html').open('w') as f:
+ f.write('<script src="build/{}/{}";</script>\n'.format(git_version, APP_FILE))
+
@task
def build_version():
pass
@task
+@needs('build')
+def compress(outfile='build/'+APP_FILE, yuic_jar='~/bin/yuic.jar'):
+ yuic_jar = path(yuic_jar).expand()
+ info('Concatenating and Compressing Source (YUI Compressor=%s)' % yuic_jar)
+ mods = commonjs(file_list=True, capture=True)
+ sh('cat %s | java -jar %s --type js -o %s' % (mods.replace('\n', ' '), yuic_jar, outfile))
+
+@task
def clean():
"Cleans dep cache and build files"
commonjs(clean=True)
@task
-@needs('build')
+@needs('compress')
@cmdopts([
('exclude=', 'x', 'Exclude listed files (separate with commas).')
])
function createInitialise(cls){
function initialise(){
var instance = this
- , proto = cls.fn // use prototype so super() calls pick up the right lists
+ , proto = cls.fn // use prototype so getSuper() calls pick up the right lists
, binds = proto.__bind__ // list of names to bind
, inits = proto.__inits__ // init functions
, args = Y(arguments)
if ( inits && inits.length )
inits.invoke('apply', instance, args);
else if ( cls.__bases__ ) {
- var superInits = super(cls, '__inits__');
+ var superInits = getSuper(cls, '__inits__');
if ( superInits && superInits.length )
superInits.invoke('apply', instance, args);
}
* @param {String} key Key to lookup.
* @return {*} First non-undefined value found in the prototypes of the __bases__ chain. (nb. This does not include cls.)
*/
-function super(cls, key){
+function getSuper(cls, key){
if ( !key )
return;
if ( !(cls instanceof Class) && cls.__class__ )
- return super(cls.__class__, key); // cls = cls.__class__;
+ return getSuper(cls.__class__, key); // cls = cls.__class__;
return cls.__bases__ // don't check cls.fn[key] -- we want super only
.reduce(function(v, base){
return (v !== undefined ? v : base.prototype[key]);
* @param {String} key Key to lookup.
* @return {*} First non-undefined value found in the __bases__ chain. (nb. This does not include cls.)
*/
-function superStatic(cls, key){
+function getSuperStatic(cls, key){
if ( !(cls instanceof Class) && cls.__class__ )
- return superStatic(cls.__class__, key); // cls = cls.__class__;
+ return getSuperStatic(cls.__class__, key); // cls = cls.__class__;
return cls.__bases__ // don't check cls[key] -- we want super only
.reduce(function(v, base){
return (v !== undefined ? v : base[key]);
exports['lookupClass'] = lookupClass;
exports['mixin'] = mixin;
exports['aggregate'] = aggregate;
-exports['superStatic'] = superStatic;
+exports['getSuperStatic'] = getSuperStatic;
-//#exports BoundsType.{PASSABLE,ZONE,BLOCKING,IRREGULAR}
+//#exports BoundsType.{PASSABLE,ZONE,BLOCKING,IRREGULAR,COMPLEX}
//#exports DensityType.{PASSABLE,BOUNDARY,DENSE,SPARSE,IRREGULAR}
//#exports StatInvariant.{NONE,RATIO,FULL}
BLOCKING : 2,
/** Potentially obstructs other objects, but requires a special test once a BoundingBox collision has been detected. */
- IRREGULAR : 3
+ IRREGULAR : 3,
+
+ /** Potentially obstructs other objects, but requires a special test, and may instruct a different object become the target of the collision. */
+ COMPLEX : 4
},
},
_filterBlockers : function _filterBlockers(v){
- return (v.blocking === BoundsType.BLOCKING || v.blocking === BoundsType.IRREGULAR);
+ return (v.blocking === BoundsType.BLOCKING
+ || v.blocking === BoundsType.IRREGULAR
+ || v.blocking === BoundsType.COMPLEX );
},
wallObstructs : function wallObstructs(line){
* @private
*/
_filterBlocked : function filterBlocked(v, r){
+ // FIXME: calc bbox for new loc to testCollide()
+ var bbox = null;
return ( v.blocking === BoundsType.BLOCKING && !(v.isBoundary || v.isProjectile) )
- || ( v.blocking === BoundsType.IRREGULAR && v.testCollide(this.agent,this,null) ); // FIXME: hm. calc bbox?
+ || ((v.blocking === BoundsType.IRREGULAR || v.blocking === BoundsType.COMPLEX) && v.testCollide(this.agent,this,bbox));
},
getNeighbors : function getNeighbors(){
|| (blocking === BoundsType.PASSABLE)
// Ask irregular objects if we hit
- || (blocking === BoundsType.IRREGULAR && !blocker.testCollide(this.thing,this.to,this.bbox))
+ || (blocking === BoundsType.IRREGULAR && !blocker.testCollide(this.thing,this.to,this.bbox,this))
+
+ // Ask complex objects if we hit, and recall they might go busta on us
+ || blocking === BoundsType.COMPLEX && !blocker.testCollide(this.thing,this.to,this.bbox,this)
// Filter out Sparse objects if bullet
|| (density === DensityType.SPARSE && this.thing.isProjectile) )
}
this.isBlocked = true;
- this.blocker = blocker;
+ if (!this.blocker) this.blocker = blocker; // BoundsType.COMPLEX might switch blockers on us
return true;
},
--- /dev/null
+var Y = require('Y').Y
+, constants = require('tanks/constants')
+, BoundsType = constants.BoundsType
+, DensityType = constants.DensityType
+, Thing = require('tanks/thing/thing').Thing
+,
+
+Accessory =
+exports['Accessory'] =
+Thing.subclass('Accessory', {
+ __bind__ : [ 'onCollide' ],
+
+ // Instance
+ blocking : BoundsType.BLOCKING,
+
+ isAccessory : true,
+
+ active : true, // Agent takes actions?
+ isRenderable : true, // Agent will present itself for rendering when ready // FIXME: stupid hack
+ isReflective : false, // Projectiles bounce off agent rather than explode?
+ hasInventory : false, // Agent can acquire items?
+ dropOnDeath : false, // Agent drops all items in inventory on death?
+
+ width : 6,
+ height : 6,
+
+ color : '#0A9CFF',
+
+ stats : {}, // radial speed in revolutions/sec
+
+
+
+ init : function initAccessory(owner){
+ this.owner = owner;
+ this.game = owner.game;
+
+ Thing.init.call(this, owner.align);
+
+ },
+
+ testCollide : function testCollide(agent, to, bbox, traversal){
+ return false;
+ },
+
+ onCollide : function onCollide(evt){
+
+ },
+
+ render : function render(parent){
+ this.remove();
+
+ var loc = this.loc;
+ this.shape = new Circle(this.width/2)
+ .position(loc.x, loc.y)
+ .fill(this.color)
+ .appendTo( parent );
+
+ return this;
+ }
+})
+;
Bullet =
exports['Bullet'] =
Thing.subclass('Bullet', {
+ __bind__ : [ 'onCollide' ],
+
// Config
traceTrajectories : false,
this.position(x1,y1);
this.trajectory = new Trajectory(this, x1,y1, x2,y2, this.movePerMs);
- this.on('collide', this.onCollide.bind(this));
+ this.on('collide', this.onCollide);
},
createStats : function createStats(){
.position(loc.x, loc.y)
.fill(this.color)
.appendTo( parent );
- this.shape.layer.attr('title', ''+loc);
+ // this.shape.layer.attr('title', ''+loc);
return this;
}
-exports['Thing'] = require('tanks/thing/thing').Thing;
-exports['Bullet'] = require('tanks/thing/bullet').Bullet;
-exports['Tank'] = require('tanks/thing/tank').Tank;
-exports['Player'] = require('tanks/thing/player').Player;
-exports['Item'] = require('tanks/thing/item').Item;
+var Y = require('Y').Y
+, tank = require('tanks/thing/tank')
+, bullet = require('tanks/thing/bullet')
+, item = require('tanks/thing/item')
+, accessory = require('tanks/thing/accessory')
+, player = require('tanks/thing/player')
+, thing = require('tanks/thing/thing')
+;
+Y.core.extend(exports, {
+ 'Tank' : tank.Tank,
+ 'Bullet' : bullet.Bullet,
+ 'Item' : item.Item,
+ 'Accessory' : accessory.Accessory,
+ 'Player' : player.Player,
+ 'Thing' : thing.Thing
+});
, config = require('tanks/config').config
, constants = require('tanks/constants')
-, BoundsType = constants.BoundsType
+, BoundsType = constants.BoundsType
, DensityType = constants.DensityType
, stat = require('tanks/effects/stat')
, Quantified = require('tanks/mixins/quantified').Quantified
isCombatant : false,
isWall : false,
isProjectile : false,
+ isAccessory : false,
active : true, // Agent takes actions?
isRenderable : false, // Agent will present itself for rendering when ready // FIXME: stupid hack
loc : null,
bbox : null,
+ // subclasses with BoundsType.{IRREGULAR,COMPLEX} should override:
+ testCollision : function testCollide(agent, to, bbox, traversal){ return false; },
+
// Rotation (rads)
rotation : 0,
}
ctx.stroke();
- }
+ } else
+ this.canvas.remove();
}
});
overlayAiPaths : null,
// Shape Config
- _layerClasses : 'map rect shape layer ezl',
+ _layerClasses : 'pathmap rect shape layer ezl',
// Blocking objects