From: dsc Date: Sun, 9 Jan 2011 06:43:59 +0000 (-0800) Subject: Adds item-specs to level configs. X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=b6dc74732907cb3e745ade9ce609b03ccd381196;p=tanks.git Adds item-specs to level configs. --- diff --git a/data/game.yaml b/data/game.yaml index e69de29..adc646b 100644 --- a/data/game.yaml +++ b/data/game.yaml @@ -0,0 +1,4 @@ +# single-player game plotline +levels: + - sitting_duck + - capt_derf diff --git a/data/types/levels.yaml b/data/types/levels.yaml index e6321db..df2c2f5 100644 --- a/data/types/levels.yaml +++ b/data/types/levels.yaml @@ -20,11 +20,16 @@ types: - [-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 @@ -41,7 +46,9 @@ types: - type: green align: 2 loc: [425,75] - items: [] + items: + - type: nitro + loc: [425,425] events: [] art: bg: '' diff --git a/src/tanks/map/level.cjs b/src/tanks/map/level.cjs index 3e155ad..328de4a 100644 --- a/src/tanks/map/level.cjs +++ b/src/tanks/map/level.cjs @@ -53,23 +53,20 @@ new evt.Class('Level', { 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); diff --git a/src/tanks/mixins/speciated.cjs b/src/tanks/mixins/speciated.cjs index 544c3d6..091225d 100644 --- a/src/tanks/mixins/speciated.cjs +++ b/src/tanks/mixins/speciated.cjs @@ -44,14 +44,29 @@ Mixin.subclass('Speciated', { 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)); } }, diff --git a/src/tanks/thing/fence.cjs b/src/tanks/thing/fence.cjs index 25e1c2b..b08b7b0 100644 --- a/src/tanks/thing/fence.cjs +++ b/src/tanks/thing/fence.cjs @@ -77,3 +77,4 @@ Wall.subclass('Fence', { } }); +Wall.register('fence', Fence); diff --git a/src/tanks/thing/index.cjs b/src/tanks/thing/index.cjs index 8fcc613..d36e903 100644 --- a/src/tanks/thing/index.cjs +++ b/src/tanks/thing/index.cjs @@ -1,7 +1,7 @@ -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; diff --git a/src/tanks/thing/wall.cjs b/src/tanks/thing/wall.cjs index 05cdf84..f59831f 100644 --- a/src/tanks/thing/wall.cjs +++ b/src/tanks/thing/wall.cjs @@ -80,3 +80,4 @@ Thing.subclass('Wall', { } }); +Wall.register('wall', Wall);