Skip to content

Instantly share code, notes, and snippets.

View martinwells's full-sized avatar

Martin Wells martinwells

View GitHub Profile
@martinwells
martinwells / gist:5980517
Created July 12, 2013 00:43
Simple Haxe logging with colors
/**
Simple, colorful logging!
Setup
=====
Somewhere really early in your code do a:
Log.init();
This will setup the logger methods and coloring stuff.
Logging
function test()
{
var myBigObject = {};
setTimeout( function()
{
console.log('' + myBigObject);
}, 1000);
}
var list = new gamecore.LinkedList();
list.add(gunship);
var next = list.first();
while( next )
{
next.obj.draw( ... );
next = next.nextLinked;
}
// derive from gamecore.Pooled, instead of gamecore.Base
var Fighter = gamecore.Pooled.extend('Fighter',
{
create: function(hp)
{
var n = this._super(); // acquire from the pool
n.hp = hp; // (re)setup the object instance
return n;
}
},
// inherit from the fighter class
var HeavyFighter = Fighter.extend('HeavyFighter',
{
// override the (static) firing delay (rapid fire)
firingSpeed: 300
},
{ });
var heavyGunship = new HeavyFighter(500);
var Fighter = gamecore.Base.extend('Fighter',
{
// static (this is inherited as well)
firingSpeed: 1000
},
{
// instance
hp: 0,
init: function(hp) // instance constructor
// check to see if the bullet needs to go away
if (bullet.collidesWith(wall))
bullet.release();
// construct a new bullet
var newBullet = Bullet.create(10, 10);
Bullet = gamecore.Pooled('Bullet',
{
// Statics
// factory constructor -- a static function
create: function(x, y)
{
// sweet static inheritance that comes with gamecore.class
var newBullet = this._super();
newBullet.x = x;
newBullet.y = y;
var newBullet = Bullet(10, 10);