This file contains hidden or 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 hidden or 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 hidden or 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 newBullet = Bullet(10, 10); |
This file contains hidden or 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.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; |
This file contains hidden or 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
| // construct a new bullet | |
| var newBullet = Bullet.create(10, 10); |
This file contains hidden or 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
| // check to see if the bullet needs to go away | |
| if (bullet.collidesWith(wall)) | |
| bullet.release(); |
This file contains hidden or 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 Fighter = gamecore.Base.extend('Fighter', | |
| { | |
| // static (this is inherited as well) | |
| firingSpeed: 1000 | |
| }, | |
| { | |
| // instance | |
| hp: 0, | |
| init: function(hp) // instance constructor |
This file contains hidden or 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
| // inherit from the fighter class | |
| var HeavyFighter = Fighter.extend('HeavyFighter', | |
| { | |
| // override the (static) firing delay (rapid fire) | |
| firingSpeed: 300 | |
| }, | |
| { }); | |
| var heavyGunship = new HeavyFighter(500); |
This file contains hidden or 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
| // 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; | |
| } | |
| }, |
This file contains hidden or 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 list = new gamecore.LinkedList(); | |
| list.add(gunship); | |
| var next = list.first(); | |
| while( next ) | |
| { | |
| next.obj.draw( ... ); | |
| next = next.nextLinked; | |
| } |