Adds item-specs to level configs.
authordsc <david.schoonover@gmail.com>
Sun, 9 Jan 2011 06:43:59 +0000 (22:43 -0800)
committerdsc <david.schoonover@gmail.com>
Sun, 9 Jan 2011 06:43:59 +0000 (22:43 -0800)
data/game.yaml
data/types/levels.yaml
src/tanks/map/level.cjs
src/tanks/mixins/speciated.cjs
src/tanks/thing/fence.cjs
src/tanks/thing/index.cjs
src/tanks/thing/wall.cjs

index e69de29..adc646b 100644 (file)
@@ -0,0 +1,4 @@
+# single-player game plotline
+levels:
+    - sitting_duck
+    - capt_derf
index e6321db..df2c2f5 100644 (file)
@@ -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: ''
index 3e155ad..328de4a 100644 (file)
@@ -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);
index 544c3d6..091225d 100644 (file)
@@ -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));
         }
         
     },
index 25e1c2b..b08b7b0 100644 (file)
@@ -77,3 +77,4 @@ Wall.subclass('Fence', {
     }
 });
 
+Wall.register('fence', Fence);
index 8fcc613..d36e903 100644 (file)
@@ -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;
index 05cdf84..f59831f 100644 (file)
@@ -80,3 +80,4 @@ Thing.subclass('Wall', {
     }
 });
 
+Wall.register('wall', Wall);