name: buffs
defaults:
symbol: tanks/effects/buff.Buff
- timeout: -1 # the Infinity literal is not valid JSON
+ timeout: -1 # the YAML .Inf (Infinity literal) is not valid JSON according to the native decoders
priority: 0
stack_limit: 1
types:
name: Speed Up
desc: Speeds up your tank temporarily.
tags: [ 'movement' ]
- timeout: 5.0
+ timeout: 3.0
stats:
- move: 2.0
+ move: 0.5
effects: []
art:
icon: ''
tags: [ 'movement' ]
passives: []
effects: [ 'speedup' ]
+ # effects:
+ # - include: speedup
cooldowns:
- activate: 10
+ activate: 30.0
art:
map_icon: ''
- inv_icon: ''
+ inv_icon: '/img/items/green-sq.png'
desc: A test level.
width: 500
height: 500
+ bounds:
+ - [-50,-50, 600,50]
+ - [-50,0, 50,500]
+ - [501,0, 50,500]
+ - [-50,501, 600,50]
+ walls:
+ - type: wall
+ args: [300,50, 50,200] # [x,y, w,h]
+ - type: wall
+ args: [300,350, 50,100]
+ - type: wall
+ args: [100,100, 50,50]
+
+ - type: fence
+ args: [360,210, 30,30]
+ - type: rock
+ args: [400,200, 25,25]
+ - type: rock
+ args: [425,225, 25,25]
+ - type: fence
+ args: [460,210, 30,30]
+
+ - type: fence
+ args: [10,210, 30,30]
+ - type: fence
+ args: [110,210, 30,30]
+ - type: fence
+ args: [210,210, 30,30]
+
+ - type: rock
+ args: [50,350, 50,50]
+ - type: rock
+ args: [100,350, 50,50]
+ - type: rock
+ args: [50,400, 50,50]
+ - type: rock
+ args: [100,400, 50,50]
+ - type: rock
+ args: [150,300, 50,50]
+ units:
+ - type: player
+ align: 1
+ loc: [375,475]
+ - type: green
+ align: 2
+ loc: [75,25]
+ - type: green
+ align: 2
+ loc: [175,25]
+ # - type: green
+ # align: 2
+ # loc: [425,125]
+ items:
+ - type: nitro
+ loc: [325,475]
+
+ three_test:
+ name: Three Test
+ desc: A more complex test level.
+ width: 500
+ height: 500
# bounds: [[-1,-1], [501,-1], [501,351], [351,351], [351,501], [-1,501]]
# bounds:
# top: [[-50,-50, 600,50]]
- type: fence
args: [360,210, 30,30]
- - type: rock
- args: [400,200, 25,25]
- - type: rock
- args: [425,225, 25,25]
+ # - type: rock
+ # args: [400,200, 25,25]
+ # - type: rock
+ # args: [425,225, 25,25]
- type: fence
args: [460,210, 30,30]
units:
- type: blue
align: 1
- loc: [425,425]
+ loc: [475,425]
- type: blue
align: 1
loc: [125,475]
- type: green
align: 2
loc: [225,325]
+
speed : 0.5
shots : 3
ai:
- path : 1.0
- dodge : 1.0
+ path : 1.00
+ dodge : 0.75
shootIncoming : 0.25
shootEnemy : 0.75
colors:
var g =
groups[chain] =
jQuery('<fieldset/>')
- .attr('id', chain)
+ .attr('id', 'group-'+chain)
.addClass('group')
.append( jQuery('<legend/>').text(chain.split('.').pop()) )
.appendTo(el);
/// Setup ///
- init : function init(){
+ init : function init(props, attrs, html){
+ if (props)
+ Y.core.extend(this, props);
+
this.children = new Y.YArray();
this.animActive = new Y.YArray();
this.animQueue = new Y.YArray();
translate : new Loc(0,0) // translates canvas
};
- this.layer = jQuery('<div/>')
+ this.layer = jQuery(html || '<div/>')
.addClass(this._cssClasses)
.data('layer', this);
this.layer[0].layer = this;
+ if (attrs) this.layer.attr(attrs);
if (this.hasCanvas) {
this.canvas = jQuery('<canvas />')
var p = cool.ratio()
, w = this.layerWidth, h = this.layerHeight
, x = w*0.5, y = h*0.5
- , amt = HALF_PI + (1 - p)*PI_AND_HALF;
+ , amt = -HALF_PI + (1 - p)*TWO_PI;
- ctx.arc(x,y, w, HALF_PI, amt, false);
+ ctx.arc(x,y, w, -HALF_PI, amt, false);
ctx.lineTo(x,y);
ctx.lineTo(x,0);
ctx.fill();
, Level = require('tanks/map/level').Level
, Grid = require('tanks/ui/grid').Grid
, PathMapUI = require('tanks/ui/pathmapui').PathMapUI
+, Backpack = require('tanks/ui/inventory/backpack').Backpack
, Thing = thing.Thing
, Tank = thing.Tank
if (levelId) this.levelId = levelId;
this.byId = {};
+ this.toTick = new Y.YArray();
this.active = new Y.YArray();
this.units = new Y.YArray();
this.bullets = new Y.YArray();
this.animations = new Y.YArray();
- this.viewport = $(GRID_ELEMENT);
+ // this.el = $(GAME_ELEMENT);
this.loop = new EventLoop(FRAME_RATE, this);
this.root =
- new Layer()
- .appendTo(this.viewport);
+ new Layer({ hasCanvas:false }, { 'id':'game' })
+ .prependTo( $('body') );
+ // this.root.shape.remove();
+ // this.root.layer.attr('id', 'viewport');
+
+ this.viewport =
+ new Layer({ hasCanvas:false }, { 'id':'viewport' })
+ .appendTo( this.root );
+
this.level =
Level.create(this.levelId, this, CAPACITY, REF_SIZE)
- .appendTo(this.root);
+ .appendTo( this.viewport );
this.grid =
new Grid(this.level, REF_SIZE)
- .prependTo(this.root);
+ .prependTo( this.viewport );
this.viewport
.width(this.level.width)
.height(this.level.height);
this.map = this.level.map;
this.map.ui = new PathMapUI(this, this.map);
- this.root.append(this.map.ui);
+ this.viewport.append(this.map.ui);
// automatically keep track of units
- Thing.addEventListener('created', this.addThing);
- Thing.addEventListener('destroy', this.killThing);
+ Thing.addEventListener('created', this.addUnit);
+ Thing.addEventListener('destroy', this.killUnit);
this.addEventListener('tick', this.tick);
this.level.setup();
+ if (this.player) {
+ this.backpack = new Backpack(this.player)
+ .appendTo( this.root )
+ .refresh();
+ }
if (replayFile) {
this.isReplay = true;
},
destroy : function destroy(){
- Thing.removeEventListener('created', this.addThing);
- Thing.removeEventListener('destroy', this.killThing);
+ Thing.removeEventListener('created', this.addUnit);
+ Thing.removeEventListener('destroy', this.killUnit);
+ this.root.remove();
+ // this.backpack && this.backpack.remove();
this.stop();
this.resetGlobals();
},
draw : function draw(){
this.root.draw();
+ // this.backpack.draw();
},
/**
SECONDTH = this.SECONDTH = ELAPSED / 1000;
SQUARETH = this.SQUARETH = REF_SIZE * SECONDTH;
- this.active.invoke('updateCooldowns', ELAPSED, NOW);
- this.active.invoke('act', ELAPSED, NOW);
+ this.toTick.invoke('tick', ELAPSED, NOW, TICKS);
+ this.active.invoke('act', ELAPSED, NOW, TICKS);
this.animations = this.animations.filter(this.tickAnimations, this);
this.draw();
},
tickAnimations : function tickAnimations(animation){
- var running = animation.tick(ELAPSED, NOW);
+ var running = animation.tick(ELAPSED, NOW, TICKS);
if (!running)
animation.remove();
return running;
return animation;
},
- noteThing : function noteThing(unit){
+ noteUnit : function noteUnit(unit){
unit.game = this;
if (unit.dead) return unit;
- if ( unit.active && !this.byId[unit.__id__] ) {
+ if ( !this.byId[unit.__id__] ) {
this.byId[unit.__id__] = unit;
- this.active.push(unit);
+ if (unit.active)
+ this.active.push(unit);
if (unit.isProjectile)
this.bullets.push(unit);
if (unit.isCombatant)
this.units.push(unit);
+ if (unit.tick)
+ this.toTick.push(unit);
}
if (unit instanceof Player) {
return unit;
},
- addThing : function addThing(unit, x,y){
+ addUnit : function addUnit(unit, x,y){
if (unit instanceof Event)
unit = unit.trigger;
if (unit.dead) return unit;
- this.noteThing(unit);
+ this.noteUnit(unit);
if (x !== undefined) {
unit.position(x,y);
return unit;
},
- killThing : function killThing(unit){
+ killUnit : function killUnit(unit){
if (unit instanceof Event)
unit = unit.data.unit;
delete this.byId[unit.__id__];
- this.active.remove(unit);
this.map.removeBlocker(unit);
- if (unit instanceof Bullet)
+ if (unit.active)
+ this.active.remove(unit);
+ if (unit.tick)
+ this.toTick.remove(unit);
+ if (unit.isProjectile)
this.bullets.remove(unit);
- else
+ if (unit.isCombatant)
this.units.remove(unit);
return unit;
},
+ removeUnitFromMap : function removeUnitFromMap(unit){
+ unit.remove();
+ this.map.removeBlocker(unit);
+ return unit;
+ },
+
moveThingTo : function moveThingTo(agent, x,y){
this.map.removeBlocker(agent);
if (agent.dead) return agent;
var undefined
, Y = require('Y').Y
-, GRID_ELEMENT = '#viewport'
+, GAME_ELEMENT = '#game'
, REF_SIZE = 50
, CELL_SIZE = REF_SIZE
// if (isReplay && x.type === 'player')
// return null;
var obj = data[x.type].instantiate(x.align);
- return game.addThing(obj, x.loc[0], x.loc[1]);
+ return game.addUnit(obj, x.loc[0], x.loc[1]);
});
var data = tanks.data.items;
this.items.map(function(x){
var obj = data[x.type].instantiate();
- return game.addThing(obj, x.loc[0], x.loc[1]);
+ return game.addUnit(obj, x.loc[0], x.loc[1]);
});
// I =
- // game.addThing(Item.create('nitro'), 8,8);
+ // game.addUnit(Item.create('nitro'), 8,8);
return this;
}
},
- canSee : function canSee(obj, ignore){
- ignore = [this.owner].concat(ignore || []);
- // var blockers = this.map.denseWalls
- // .apply('remove', ignore)
- // .filter(this.intersects)
- // .sort( this.compare )
- var blockers = this.map.denseWalls
- , blockers = blockers.apply('remove', ignore).concat([ obj ])
- , blockers = blockers.filter(this.intersects)
- , blockers = blockers.sort(this.compare)
- , blocker = blockers.first()
- ;
- return !!(blocker === obj);
- },
-
intersects : function intersects(x,y){
var o = x;
if (o.bbox)
return ( t <= ft && (dw <= w || dh <= h) );
},
+ canSee : function canSee(obj, ignore){
+ ignore = [this.owner].concat(ignore || []);
+ // var blockers = this.map.denseWalls
+ // .apply('remove', ignore)
+ // .filter(this.intersects)
+ // .sort( this.compare )
+ var blockers = this.map.denseWalls
+ .apply('remove', ignore).concat([ obj ])
+ .filter(this.intersects)
+ .sort(this.compare)
+ , blocker = blockers.first()
+ ;
+ return !!(blocker === obj);
+ },
+
pathBlocked : function pathBlocked(obj, ignore){
// var walls, blockers
// if (this.owner.isProjectile)
return (blocker === obj ? false : blocker);
},
+ calcIntersectTraj : function calcIntersectTraj(fireLoc, speed){
+ // targetVelocityVector = math.Vector3(0, 0, 0) * aTargetSpeed
+ // interceptVelocityVector = math.Vector3(0, 0, 0) * aBulletSpeed
+ //
+ // tDelta = aTargetPosition - aFiringPosition
+ //
+ // Vr = targetVelocityVector - interceptVelocityVector
+ // a = Vr.Dot( Vr ) - aBulletSpeed * aBulletSpeed
+ // b = 2 * Vr.Dot( tDelta )
+ // c = tDelta.Dot ( tDelta )
+ //
+ // deter = b * b - 4 * ( a * c )
+ //
+ // if deter < 0:
+ // return -1
+ // else:
+ // ETN = 2 * ( c / pdmath.sqrt(deter) - b )
+ // return ETN
+
+ },
+
+
toString : function(){
return 'T['+this.p1+', '+this.p2+', slope='+this.slope.toFixed(3)+']';
}
if ( gapOk && (x <= gapX && gapX <= nextX) && (y <= gapY && gapY <= nextY) ) {
rock.dead = true; // Don't recursively fire destroy event
rock.divide(gap).remove();
- this.game.killThing(rock);
+ this.game.killUnit(rock);
}
}
}
// inactive
active : false,
createCooldowns : op.nop,
+ tick : op.nop,
stats : {
hp : Infinity,
'item1' : 'consumable',
'item2' : 'consumable'
},
- max : 10, // Backpack capacity
+ max : 12, // Backpack capacity
size : 0, // Number of items
items : null, // item id -> Item { backpack:backpack[i], slot:slotName }
backpack : null, // Array of positions of items in backpack: backpack idx -> item id
},
- _fireItemChange : function _fireItemChange(evt, item){
- var data = { 'unit':this, 'item':item };
+ _fireItemChange : function _fireItemChange(evt, item, data){
+ data = Y.extend({ 'unit':this, 'item':item }, data || {});
this.fire(evt, item, data);
item.fire(evt, this, data);
return this;