Skip to content

Instantly share code, notes, and snippets.

View martinwells's full-sized avatar

Martin Wells martinwells

View GitHub Profile
Bullet = gamecore.Base(‘Bullet’,
{
// Statics
},
{
// Instance
x: 0,
y: 0,
// the init method serves as a constructor
<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>
git clone https://github.com/playcraft/gamecore.js.git
function getNewBullet(x, y)
{
// ... previous code
// initialize the bullet
b.x = x;
b.y = y;
b.state = NORMAL;
return b;
if (bullet.collidingWith(enemyShip)) // boom!
freeBullet(bullet); // return it to the pool
if (bullet.collidingWith(enemyShip)) // boom!
freeBullet(bullet); // return it to the pool
var b = getNewBullet();
var b = new Bullet();
// declare bullet pools
var activeBullets = [];
var bulletPool = [];
// construct some bullets ready for use
for (var i=0; i < 20; i++)
bulletPool.push( new Bullet() );
// a constructor/factory function
function getNewBullet()
var lastUsedHeap = 0; // remember the heap size
function checkMemory()
{
// check if the heap size is this cycle is LESS than what we had last
// cycle; if so, then the garbage collector has kicked in
if (window.performance.memory.usedJSHeapSize < lastUsedHeap)
console.log('Garbage collected!');
lastUsedHeap = window.performance.memory.usedJSHeapSize;