Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
Created January 25, 2012 00:41
Show Gist options
  • Select an option

  • Save hughfdjackson/1673818 to your computer and use it in GitHub Desktop.

Select an option

Save hughfdjackson/1673818 to your computer and use it in GitHub Desktop.
CoffeeScript trial.
(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;
# 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
@boxxxie

boxxxie commented Jan 25, 2012

Copy link
Copy Markdown

_meta?: is checking for null/undefined?

push child: parens are optional?

@hughfdjackson

Copy link
Copy Markdown
Author

@boxxxie

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