This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bullet = gamecore.Base(‘Bullet’, | |
{ | |
// Statics | |
}, | |
{ | |
// Instance | |
x: 0, | |
y: 0, | |
// the init method serves as a constructor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone https://github.com/playcraft/gamecore.js.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getNewBullet(x, y) | |
{ | |
// ... previous code | |
// initialize the bullet | |
b.x = x; | |
b.y = y; | |
b.state = NORMAL; | |
return b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (bullet.collidingWith(enemyShip)) // boom! | |
freeBullet(bullet); // return it to the pool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (bullet.collidingWith(enemyShip)) // boom! | |
freeBullet(bullet); // return it to the pool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var b = getNewBullet(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var b = new Bullet(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |