Skip to content

Instantly share code, notes, and snippets.

View martinwells's full-sized avatar

Martin Wells martinwells

View GitHub Profile
<script type="text/JavaScript" src="gamecore.js/src/class.js"></script>
<script type="text/JavaScript" src="gamecore.js/src/gamecore.js"></script>
<script type="text/JavaScript" src="gamecore.js/src/jhashtable.js"></script>
<script type="text/JavaScript" src="gamecore.js/src/linkedlist.js"></script>
<script type="text/JavaScript" src="gamecore.js/src/pooled.js"></script>
Bullet = gamecore.Base(‘Bullet’,
{
// Statics
},
{
// Instance
x: 0,
y: 0,
// the init method serves as a constructor
var newBullet = Bullet(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;
// construct a new bullet
var newBullet = Bullet.create(10, 10);
// check to see if the bullet needs to go away
if (bullet.collidesWith(wall))
bullet.release();
var Fighter = gamecore.Base.extend('Fighter',
{
// static (this is inherited as well)
firingSpeed: 1000
},
{
// instance
hp: 0,
init: function(hp) // instance constructor
// inherit from the fighter class
var HeavyFighter = Fighter.extend('HeavyFighter',
{
// override the (static) firing delay (rapid fire)
firingSpeed: 300
},
{ });
var heavyGunship = new HeavyFighter(500);
// 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;
}
},
var list = new gamecore.LinkedList();
list.add(gunship);
var next = list.first();
while( next )
{
next.obj.draw( ... );
next = next.nextLinked;
}