Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************8
- * Main.js
- * Base initialization class for Impact game
- * Dave Voyles, via Jesse Freeman 2/2013
- *********************************************************/
- ig.module(
- 'game.main'
- )
- .requires(
- 'impact.game',
- 'impact.debug.debug',
- 'game.levels.Space1',
- 'impact.font',
- 'game.entities.EntityDeathExplosionParticle'
- )
- .defines(function(){
- MyGame = ig.Game.extend({
- /******************************************8
- * Property Definitions
- *******************************************/
- instructText: new ig.Font( 'media/04b03.font.png' ),
- lifeSprite: new ig.Image('media/ship_lifebar.png'),
- statMatte: new ig.Image('media/stat-matte.png'),
- statText: new ig.Font( 'media/04b03.font.png' ),
- showStats: true,
- stats: { kills: 0, deaths: 0},
- lives: 3,
- backdrop: new ig.Image('media/Desert1.png'),
- /******************************************8
- * Initialization
- ******************************************/
- init: function()
- {
- // Input
- ig.input.bind(ig.KEY.LEFT_ARROW, 'leftArrow');
- ig.input.bind(ig.KEY.RIGHT_ARROW, 'rightArrow');
- ig.input.bind(ig.KEY.UP_ARROW, 'upArrow');
- ig.input.bind(ig.KEY.DOWN_ARROW, 'downArrow');
- ig.input.bind(ig.KEY.C, 'shoot');
- // Also used for BG scrolling. Taken from Xtype
- var bgmap = new ig.BackgroundMap(620, [
- [1]
- ], this.grid);
- bgmap.repeat = true;
- this.backgroundMaps.push(bgmap);
- // Loading
- this.loadLevel(LevelSpace1);
- },
- /******************************************8
- * Load Level
- ******************************************/
- loadLevel: function( data ) {
- this.stats = { kills: 0, deaths: 0};
- this.parent(data);
- },
- /******************************************8
- * Update
- ******************************************/
- update: function()
- {
- // Screen follows the player
- var player = this.getEntitiesByType( EntityPlayer )[0];
- if( player ) {
- this.screen.x = player.pos.x - ig.system.width/10+40;
- this.screen.y = player.pos.y - ig.system.height/2;
- }
- // Background would scroll, if it worked for me. Taken from Xtype
- this.backgroundMaps[0].scroll.Y -= 300 * ig.system.tick;
- // Update all entities and BackgroundMaps
- this.parent();
- },
- /******************************************8
- * Draw
- ******************************************/
- draw: function()
- {
- // Draw all entities and backgroundMaps
- this.parent();
- // Draws lifebar
- this.statText.draw("Lives", 5,5);
- for(var i=0; i < this.lives; i++)
- this.lifeSprite.draw(((this.lifeSprite.width + 2) * i)+5, 15);
- }
- });
- /******************************************8
- * Default Settings
- *******************************************/
- ig.main( '#canvas', MyGame, 60, 480, 320, 2 );
- });
Advertisement
Add Comment
Please, Sign In to add comment