Skip to content

Instantly share code, notes, and snippets.

View iaincarsberg's full-sized avatar

Iain Carsberg iaincarsberg

View GitHub Profile
@iaincarsberg
iaincarsberg / gist:1007712
Created June 4, 2011 08:03
Example of thornys entity system interaction
require('thorny/base')('./config/default.json')(function ($) {
// Grab a copy of the entity system object
var entitySystem = $('thorny entity-system');
// Make the actor template
entitySystem.makeEntity($.defined('template'))
.addTag('actor')
.addComponent('position')
.addComponent('keys')
.addComponent('render-2d');
[
"thorny math vector2",
"./config/other.json"
]
@iaincarsberg
iaincarsberg / app.js
Created July 1, 2011 09:06
Thorny: De-verbos-ing the api
require('./thorny/base')('./config/default.json', function ($) {
if ($.dooooom().makeHappen() === $('thorny some-dooms-day-feature').makeHappen()) {
// serve cake, because cake and dooooom is an ideal pairing.
}
});
@iaincarsberg
iaincarsberg / app.js
Created July 5, 2011 15:11
Example of a possible solution when adding components that require an asynchronous operation to attach to an entity, for example when loading a level.
require('./thorny/base')('./config/default.json', function ($) {
// Register a component so we can use it below.
$.es().registerComponent('load-level', function () {
return {
// Used to enable the isReady function.
asynchronousAttachEvent: 'world-loaded',
// Called in response to .addComponent()
attach: function (entity, filename) {
$.ajax({
@iaincarsberg
iaincarsberg / vector2.spec.js
Created July 12, 2011 09:36
Real world usage of Jasmine compared to Qunit
/*global console window describe xdescribe it expect runs waits*/
(function () {
require.paths.unshift(__dirname + '/../../../');
require('thorny/base')('./config/default.json')(function ($) {
describe('a vector2', function () {
it('should contain the following functions', function () {
var vector2 = $('thorny math vector2');
expect(typeof vector2.factory).toEqual('function');
expect(typeof vector2.centroid).toEqual('function');
@iaincarsberg
iaincarsberg / gist:1216206
Created September 14, 2011 09:43
jQuery snippet for accessing a controller implemented using https://github.com/managedit/kohana-api
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="/js/libs/json2.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$.ajax({
url: '/api/login',
type: 'POST',
data: JSON.stringify({id: 123}),
processData: false,
contentType: 'application/json',
@iaincarsberg
iaincarsberg / app.js
Created September 22, 2011 19:11
RequireJS
/*global define console*/
require.config({
baseUrl: '/src',
packages: [
{
name: 'underscore',
main: 'underscore',
location: '/lib/underscore'
}
],
@iaincarsberg
iaincarsberg / lineIntersection.js
Created September 28, 2011 09:30
The lineIntersection function from the thorny/math/poly2.js class file
/**
* Used to find an intersection between two points.
* @param vector2
* @return obj|false if intersection happened returns array of x/y
* otherwise fales.
*/
lineIntersection: function (v1, v2, v3, v4) {
var
bx,
by,
@iaincarsberg
iaincarsberg / main.js
Created October 4, 2011 10:50
RequireJS - Compose.js together
/*global require*/
require(['whom'], function (Whom) {
var me = new Whom('Iain', 27);
});
@iaincarsberg
iaincarsberg / main.js
Created October 4, 2011 10:58
RequireJS - Compose.js - Utility/Helper functions
/*global require*/
require('whom', function (Whom) {
if (Whom.allOver18(
new Whom('Iain', 27),
new Whom('Bob', 53),
new Whom('Rob', 19)
)) {
console.log('Drink!');
} else {
console.log('Banned');