Guest User

Untitled

a guest
Mar 1st, 2013
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*********************************************************8
  2.  * Main.js
  3.  * Base initialization class for Impact game
  4.  * Dave Voyles, via Jesse Freeman 2/2013
  5.  *********************************************************/
  6. ig.module(
  7.     'game.main'
  8. )
  9.     .requires(
  10.     'impact.game',
  11.     'impact.debug.debug',
  12.     'game.levels.Space1',
  13.     'impact.font',
  14.     'game.entities.EntityDeathExplosionParticle'
  15.  
  16. )
  17.     .defines(function(){
  18.  
  19.         MyGame = ig.Game.extend({
  20.  
  21.             /******************************************8
  22.              * Property Definitions
  23.              *******************************************/
  24.             instructText: new ig.Font( 'media/04b03.font.png' ),
  25.             lifeSprite: new ig.Image('media/ship_lifebar.png'),
  26.             statMatte: new ig.Image('media/stat-matte.png'),
  27.             statText: new ig.Font( 'media/04b03.font.png' ),
  28.             showStats: true,
  29.             stats: { kills: 0, deaths: 0},
  30.             lives: 3,
  31.             backdrop: new ig.Image('media/Desert1.png'),
  32.  
  33.             /******************************************8
  34.              * Initialization
  35.              ******************************************/
  36.             init: function()
  37.             {
  38.                 // Input
  39.                 ig.input.bind(ig.KEY.LEFT_ARROW, 'leftArrow');
  40.                 ig.input.bind(ig.KEY.RIGHT_ARROW, 'rightArrow');
  41.                 ig.input.bind(ig.KEY.UP_ARROW, 'upArrow');
  42.                 ig.input.bind(ig.KEY.DOWN_ARROW, 'downArrow');
  43.                 ig.input.bind(ig.KEY.C, 'shoot');
  44.  
  45.                 // Also used for BG scrolling. Taken from Xtype
  46.                 var bgmap = new ig.BackgroundMap(620, [
  47.                     [1]
  48.                 ], this.grid);
  49.                 bgmap.repeat = true;
  50.                 this.backgroundMaps.push(bgmap);
  51.  
  52.                 // Loading
  53.                 this.loadLevel(LevelSpace1);
  54.             },
  55.  
  56.             /******************************************8
  57.              * Load Level
  58.              ******************************************/
  59.             loadLevel: function( data ) {
  60.                 this.stats = { kills: 0, deaths: 0};
  61.                 this.parent(data);
  62.             },
  63.  
  64.             /******************************************8
  65.              * Update
  66.              ******************************************/
  67.             update: function()
  68.             {
  69.                 // Screen follows the player
  70.                 var player = this.getEntitiesByType( EntityPlayer )[0];
  71.                 if( player ) {
  72.                     this.screen.x = player.pos.x - ig.system.width/10+40;
  73.                     this.screen.y = player.pos.y - ig.system.height/2;
  74.                 }
  75.  
  76.                 // Background would scroll, if it worked for me. Taken from Xtype
  77.                 this.backgroundMaps[0].scroll.Y -= 300 * ig.system.tick;
  78.                
  79.                 // Update all entities and BackgroundMaps
  80.                 this.parent();
  81.             },
  82.  
  83.  
  84.             /******************************************8
  85.              * Draw
  86.              ******************************************/
  87.             draw: function()
  88.             {
  89.                 // Draw all entities and backgroundMaps
  90.                 this.parent();
  91.  
  92.                 // Draws lifebar
  93.                 this.statText.draw("Lives", 5,5);
  94.                 for(var i=0; i < this.lives; i++)
  95.                     this.lifeSprite.draw(((this.lifeSprite.width + 2) * i)+5, 15);
  96.             }
  97.         });
  98.  
  99.  
  100.         /******************************************8
  101.          * Default Settings
  102.          *******************************************/
  103.         ig.main( '#canvas', MyGame, 60, 480, 320, 2 );
  104.  
  105.     });
Advertisement
Add Comment
Please, Sign In to add comment