+# single-player game plotline
+levels:
+ - sitting_duck
+ - capt_derf
- [-50,501, 600,50]
# - [351,351, 200,200]
walls:
- - [300,50, 50,200] # [x,y, w,h]
- - [300,350, 50,100]
- - [50,350, 100,100]
- - [150,300, 50,50]
- - [100,100, 50,50]
+ - type: wall
+ args: [300,50, 50,200] # [x,y, w,h]
+ - type: wall
+ args: [300,350, 50,100]
+ - type: wall
+ args: [50,350, 100,100]
+ - type: wall
+ args: [150,300, 50,50]
+ - type: wall
+ args: [100,100, 50,50]
units:
- type: player
align: 1
- type: green
align: 2
loc: [425,75]
- items: []
+ items:
+ - type: nitro
+ loc: [425,425]
events: []
art:
bg: ''
this.walls =
Y(this.walls).map(function(wall){
- return Wall.instantiate.apply(Wall, wall);
+ return Wall.createApply(wall.type, wall.args);
});
- var unitdata = tanks.data.units;
- this.units.map(function(u){
- var unit = unitdata[u.type].instantiate(u.align);
- return game.addThing(unit, u.loc[0], u.loc[1]);
+ var data = tanks.data.units;
+ this.units.map(function(x){
+ var obj = data[x.type].instantiate(x.align);
+ return game.addThing(obj, x.loc[0], x.loc[1]);
});
- // P =
- // game.player = game.addThing(Player.create('player', 1), 5,9);
- // game.addThing(Tank.create('blue', 1), 3,9);
-
- // E =
- // game.addThing(Tank.create('green', 2), 0,7);
- // game.addThing(Tank.create('green', 2), 1,0);
- // game.addThing(Tank.create('green', 2), 8,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]);
+ });
// I =
// game.addThing(Item.create('nitro'), 8,8);
return Species;
},
+ register : function register(id, cls){
+ id = (id+'').toLowerCase();
+ if ( this.__known__[id] )
+ throw new Error('A species of '+this.className+' already exists with the id '+id+'!');
+ this.__known__[id] = cls;
+ return cls;
+ },
+
lookup : function lookup(id){
+ id = (id+'').toLowerCase();
return this.__known__[id];
},
create : function create(id){
var args = Y(arguments,1)
- , Species = this.__known__[id];
+ , Species = this.lookup(id);
+ if (!Species)
+ throw new Error('Unknown Species of '+this.className+' with id "'+id+'"!');
return Species.instantiate.apply(Species, args);
+ },
+
+ createApply : function createApply(id, args){
+ return this.create.apply(this, [id].concat(args));
}
},
}
});
+Wall.register('fence', Fence);
-exports['Thing'] = require('tanks/thing/thing').Thing;
-exports['Wall'] = require('tanks/thing/wall').Wall;
-exports['Bullet'] = require('tanks/thing/bullet').Bullet;
-exports['Tank'] = require('tanks/thing/tank').Tank;
+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;
-// exports['CustomTank'] = require('tanks/thing/customtank').CustomTank;
+exports['Item'] = require('tanks/thing/item').Item;
+exports['Wall'] = require('tanks/thing/wall').Wall;
+exports['Fence'] = require('tanks/thing/fence').Fence;
}
});
+Wall.register('wall', Wall);