Permalink
Browse files

separated the component core into a separate module, and started with…

… boilerplate for game server
  • Loading branch information...
1 parent 3fb80d2 commit a722ad360da40636023fbffb6ba81181b38a456a @ehsanul committed Jan 19, 2011
Showing with 119 additions and 56 deletions.
  1. +21 −0 lib/component/component.coffee
  2. +43 −0 lib/component/component.js
  3. +1 −0 lib/component/index.js
  4. +30 −16 xarkon-server.coffee
  5. +24 −40 xarkon-server.js
@@ -0,0 +1,21 @@
+Component = ->
+Component.prototype =
+ extend: (components...) ->
+ for component in components
+ for key, val of component
+ this[key] = val
+ new: (args...) ->
+ F = ->
+ F.prototype = this
+ obj = new F
+ obj.init(args...) if obj.init?
+ return obj
+
+$C = (components...) ->
+ comp = new Component
+ comp.extend components...
+ return comp
+
+exports.$C = $C
+exports.Component = Component
+
@@ -0,0 +1,43 @@
+var $C, Component;
+var __slice = Array.prototype.slice;
+Component = function() {};
+Component.prototype = {
+ extend: function() {
+ var component, components, key, val, _i, _len, _results;
+ components = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ _results = [];
+ for (_i = 0, _len = components.length; _i < _len; _i++) {
+ component = components[_i];
+ _results.push((function() {
+ var _results;
+ _results = [];
+ for (key in component) {
+ val = component[key];
+ _results.push(this[key] = val);
+ }
+ return _results;
+ }).call(this));
+ }
+ return _results;
+ },
+ "new": function() {
+ var F, args, obj;
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ F = function() {};
+ F.prototype = this;
+ obj = new F;
+ if (obj.init != null) {
+ obj.init.apply(obj, args);
+ }
+ return obj;
+ }
+};
+$C = function() {
+ var comp, components;
+ components = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ comp = new Component;
+ comp.extend.apply(comp, components);
+ return comp;
+};
+exports.$C = $C;
+exports.Component = Component;
@@ -0,0 +1 @@
+module.exports = require('./component.js');
View
@@ -1,20 +1,34 @@
#TODO:
# - position/geometry/size/physics components
-Component = ->
-Component.prototype =
- extend: (components...) ->
- for component in components
- for key, val of component
- this[key] = val
- new: (args...) ->
- F = ->
- F.prototype = this
- obj = new F
- obj.init(args...) if obj.init?
- return obj
+http = require('http')
+url = require('url')
+fs = require('fs')
+sys = require('sys')
+path = require('path')
+io = require('./lib/socket.io')
+$C = require('./lib/component').$C
+paperboy = require('./lib/node-paperboy')
-$C = (components...) ->
- comp = new Component
- comp.extend components...
- return comp
+# TODO
+# - use floatarray-based matrix library for position/etc vectors
+
+# temporary, not real implementation
+Pos = $C(
+ setPos: (x, y) ->
+ @x = x
+ @y = y
+)
+
+Physics = $C(Pos
+)
+
+SpaceShip = $C(Physics,
+ init: (x, y) ->
+ setPos(x, y)
+)
+
+myastro = Astro.new(23, 92)
+console.log(myastro.x)
+console.log(myastro.acceleration)
+console.log(myastro.another())
View
@@ -1,41 +1,25 @@
-var $C, Component;
-var __slice = Array.prototype.slice;
-Component = function() {};
-Component.prototype = {
- extend: function() {
- var component, components, key, val, _i, _len, _results;
- components = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
- _results = [];
- for (_i = 0, _len = components.length; _i < _len; _i++) {
- component = components[_i];
- _results.push((function() {
- var _results;
- _results = [];
- for (key in component) {
- val = component[key];
- _results.push(this[key] = val);
- }
- return _results;
- }).call(this));
- }
- return _results;
- },
- "new": function() {
- var F, args, obj;
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
- F = function() {};
- F.prototype = this;
- obj = new F;
- if (obj.init != null) {
- obj.init.apply(obj, args);
- }
- return obj;
+var $C, Physics, Pos, SpaceShip, fs, http, io, myastro, paperboy, path, sys, url;
+http = require('http');
+url = require('url');
+fs = require('fs');
+sys = require('sys');
+path = require('path');
+io = require('./lib/socket.io');
+$C = require('./lib/component').$C;
+paperboy = require('./lib/node-paperboy');
+Pos = $C({
+ setPos: function(x, y) {
+ this.x = x;
+ return this.y = y;
}
-};
-$C = function() {
- var comp, components;
- components = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
- comp = new Component;
- comp.extend.apply(comp, components);
- return comp;
-};
+});
+Physics = $C(Pos);
+SpaceShip = $C(Physics, {
+ init: function(x, y) {
+ return setPos(x, y);
+ }
+});
+myastro = Astro["new"](23, 92);
+console.log(myastro.x);
+console.log(myastro.acceleration);
+console.log(myastro.another());

0 comments on commit a722ad3

Please sign in to comment.