Created
January 25, 2012 00:41
-
-
Save hughfdjackson/1673818 to your computer and use it in GitHub Desktop.
CoffeeScript trial.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| var Actor, Meta, flatten_world, flywheel, inner_loop, pure, render, _; | |
| flywheel = require("./lib/flywheel"); | |
| _ = require("./lib/underscore"); | |
| pure = {}; | |
| Actor = function() { | |
| return { | |
| _meta: Meta(), | |
| x: 0, | |
| y: 0, | |
| height: 10, | |
| width: 10, | |
| color: '#000', | |
| shape: 'rect' | |
| }; | |
| }; | |
| Meta = function() { | |
| return { | |
| parent: null, | |
| children: [], | |
| anim_q: [], | |
| paused: false, | |
| dead: false | |
| }; | |
| }; | |
| pure.run = function(world, canvas) { | |
| var cb; | |
| cb = function(time_delta) { | |
| return inner_loop(world, canvas, time_delta); | |
| }; | |
| return flywheel(cb).start(); | |
| }; | |
| inner_loop = function(world, canvas, time_delta) {}; | |
| render = function(world, canvas) {}; | |
| flatten_world = function(world) {}; | |
| pure.create = function(settings) { | |
| return _.extend(Actor(), settings); | |
| }; | |
| pure.add = function(parent, child) { | |
| var _ref, _ref2; | |
| if ((_ref = parent._meta) != null) _ref.children.push(child); | |
| if ((_ref2 = child._meta) != null) _ref2.parent = parent; | |
| return parent; | |
| }; | |
| pure.remove = function(actor) { | |
| var _ref; | |
| if ((_ref = actor._meta) != null) _ref.dead = true; | |
| return actor; | |
| }; | |
| module.exports = pure; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # imports | |
| flywheel = require "./lib/flywheel" | |
| _ = require "./lib/underscore" | |
| # namespace | |
| pure = {} | |
| # Constructors | |
| Actor = -> | |
| _meta : Meta() | |
| x : 0 | |
| y : 0 | |
| height : 10 | |
| width : 10 | |
| color : '#000' | |
| shape : 'rect' | |
| Meta = -> | |
| parent : null | |
| children : [] | |
| anim_q : [] | |
| paused : false | |
| dead : false | |
| time : 0 | |
| Animation = -> | |
| start : 0 | |
| end : 0 | |
| from : null | |
| to : null | |
| type : null | |
| easing : 'linear' | |
| # Game Loop | |
| pure.run = ( world, canvas ) -> | |
| cb = ( time_delta ) -> | |
| inner_loop(world, canvas, time_delta) | |
| flywheel(cb).start() | |
| inner_loop = ( world, canvas, time_delta ) -> | |
| #todo | |
| render = ( world, canvas ) -> | |
| # World Manip | |
| pure.create = ( settings ) -> | |
| _.extend(Actor(), settings) | |
| pure.add = ( parent, child ) -> | |
| parent._meta?.children.push child | |
| child._meta?.parent = parent | |
| parent | |
| pure.remove = ( actor ) -> | |
| actor._meta?.dead = true | |
| actor | |
| pure.animate = ( actor, settings ) | |
| anim = _.extend(Animation(), settings) | |
| actor._meta?.anim_q.push(anim) | |
| actor | |
| ## Export | |
| module.exports = pure |
Author
yea, meta? is checking that
and yea, parens are optional ^^
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_meta?: is checking for null/undefined?
push child: parens are optional?