Skip to content

Instantly share code, notes, and snippets.

17:05 < hughfdjackson> Indian: in js, there's an idea called 'truthiness'
17:05 < hughfdjackson> and 'falsiness'
17:05 < Indian> ok
17:05 < hughfdjackson> "" is considered falsy
17:06 < yansanmo> >> [!!"female", !!""]
17:06 < ecmabot> yansanmo: (object) [true, false]
17:06 < hughfdjackson> meaning if you put it in an if statement as the predicate expression, it will *not* run the if branch
17:06 < hughfdjackson> >> if ( "" ) console.log('yay')
17:06 < ecmabot> hughfdjackson: undefined
17:06 < hughfdjackson> >> if ( "i'm not empty" ) console.log('yay')
@hughfdjackson
hughfdjackson / FXYnVZaZ
Created April 28, 2012 12:42 — forked from anonymous/FXYnVZaZ
a guest on Apr 28th, 2012 - JSON
{
"cmd": "init",
"payload": {
"blackboard_id": 2,
"data": [
"{\"id\":1,\"z\":1,\"class\":\"Rectangle\",\"x\":234.5,\"y\":130.5,\"width\":297,\"height\":147,\"style\":{\"fillColor\":\"#FFFFFF\",\"strokeColor\":\"#000000\",\"strokeSize\":\"1\"},\"minWidth\":10,\"minHeight\":10,\"text\":\"Test\",\"font\":\"verdana\",\"fontSize\":\"16px\",\"fontStyle\":{\"bold\":false,\"italic\":false},\"boundingBox\":{\"x\":[234.5,383,531.5],\"y\":[130.5,204,277.5]}}",
"{\"id\":1,\"z\":1,\"class\":\"Rectangle\",\"x\":234.5,\"y\":130.5,\"width\":297,\"height\":147,\"style\":{\"fillColor\":\"#FFFFFF\",\"strokeColor\":\"#000000\",\"strokeSize\":\"1\"},\"minWidth\":10,\"minHeight\":10,\"text\":\"Test\",\"font\":\"verdana\",\"fontSize\":\"16px\",\"fontStyle\":{\"bold\":false,\"italic\":false},\"boundingBox\":{\"x\":[234.5,383,531.5],\"y\":[130.5,204,277.5]}}"
]
}
}
var after = function(fn, cb){
return function(){
fn.apply(this, arguments)
cb()
}
}
var fn = after(function(){ /* handle callback here */ }, function(){ /* setup next here */ })
// this API sucks. :p what a fail.
var call = function(fun) {
var args = Array.prototype.slice.call(arguments, 1);
if (typeof fun === typeof Function) fun.apply(this, args);
}
@hughfdjackson
hughfdjackson / gist:2429586
Created April 20, 2012 15:24
BBGChallenge6 genre pool additions
* education game
var Deck = function() {
}
Deck.prototype.shuffle = function() {
}
@hughfdjackson
hughfdjackson / gist:2424715
Created April 19, 2012 22:47
Cute defaults (i saw someone do this somewhere, can't remember where)
void function(){
var slice = Array.prototype.slice
Function.prototype.defaults = function(){
var args = slice.apply(arguments)
, orgf = this
, retf = function(){
var innerargs = slice.apply(arguments)
args.forEach(function(arg, i){
if ( innerargs[i] === undefined ) innerargs[i] = arg
@hughfdjackson
hughfdjackson / GLnJSGFx
Created April 18, 2012 13:26 — forked from anonymous/GLnJSGFx
a guest on Apr 18th, 2012 - pastebin.com/GLnJSGFx
The JSON:
{"markers": [
{"title":"Varisia", "lat":74.37118, "lng":-49.61677, "type":"region", "info":"Varisia (region): Bibbity <strong>Boo!</strong>"}
]
}
function loadMarkers(url) {
$.getJSON(url, function(data) {
$.each(data, function(index, entry) {
console.log(index);
@hughfdjackson
hughfdjackson / 9m4ZyX9k
Created April 14, 2012 16:01 — forked from anonymous/9m4ZyX9k
a guest on Apr 14th, 2012 - pastebin.com/9m4ZyX9k
// Create our test array.
var arr = [ "one", "one", "one" ]
var foo = function(){
var curr = 0
, bar = function(){
console.log(arr[curr])
curr += 1
if ( curr < arr.length ) setTimeout(bar, 3000)
}

Peek Manifesto

Peek should make it as painless as possible to render your game objects to canvas. The idea is that, amongst its bad parts, the DOM has the great advantage that it does this work for us, implicitly. It's really bad part is that it does not act like normal js objects, which makes interaction with it painful. Like the DOM, it should handle input as well as output - that is, clicks, touches, etc, that happen to the entities visually, should produce events.

It should also be reasonably effecient. That is, it should be structured in such a way that we can optimise to the point where your average 2d game will run on a 3-4 yo mid-spec computer w/ latest FF, Chrome, or ie.

As much as possible, it mustn't feel like you have to change your game object in order for it to be rendered in a natural way.

Guiding principles