JSFiddle - React, Tailwind, and code Playground

by Warspawn

HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<div ng-app="myApp" ng-controller="gameCtrl">
    <starfield stars="1e3" width="640" height="480"></starfield>
</div>

CSS

canvas { border: 1px solid black; }

JavaScript

Array.prototype.random = function() {
    var self = this;
    var out = parseInt(Math.floor(Math.random() * self.length), 10);
    return self[out];
};

// jacked from Backbone
// Helper function to correctly set up the prototype chain, for subclasses.
// Similar to `goog.inherits`, but uses a hash of prototype properties and
// class properties to be extended.
var extend = function(protoProps, staticProps) {
    var parent = this;
    var child;

    // The constructor function for the new subclass is either defined by you
    // (the "constructor" property in your `extend` definition), or defaulted
    // by us to simply call the parent's constructor.
    if (protoProps && _.has(protoProps, 'constructor')) {
        child = protoProps.constructor;
    } else {
        child = function() {
            parent.apply(this, arguments);
        };
    }

    // Add static properties to the constructor function, if supplied.
    _.extend(child, parent, staticProps);

    // Set the prototype chain to inherit from `parent`, without calling
    // `parent`'s constructor function.
    var Surrogate = function() {
        this.constructor = child;
    };
    Surrogate.prototype = parent.prototype;
    child.prototype = new Surrogate;

    // Add prototype properties (instance properties) to the subclass,
    // if supplied.
    if (protoProps) _.extend(child.prototype, protoProps);

    // Set a convenience property in case the parent's prototype is needed
    // later.
    child.__super__ = parent.prototype;

    return child;
};

Entity = function(){};
Entity.prototype.tick = function(dt) { return false; }
Entity.prototype.draw = function(context) { }
Entity.prototype.getBox = function() { return null; }
Entity.extend = extend;

Sprite = Entity.extend({
    constructor: function(url) {
        this.imageUrl = url;
        this.position = [0,0]; 
        this.size = [0,0];            
    }
});
             
Sprite.prototype.draw = function(context) {

};

Sprite.extend...