Guest User

Untitled

a guest
Aug 12th, 2013
29
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ig.module(
  2.     'game.main'
  3. )
  4. .requires(
  5.     'impact.game',
  6.     'impact.font',
  7.     'impact.debug.debug',
  8.     'plugins.packed-textures',
  9.     'plugins.tween-lite',
  10.     'plugins.menu',
  11.     'plugins.pause',
  12.     'plugins.pause-focus',  
  13.     'game.entities.actor-player',
  14.     'game.entities.object-pickupBulletTime',
  15.     'game.entities.object-pu-miniship',
  16.     'game.entities.object-pu-life',
  17.     'game.screens.start-screen',
  18.     'game.menus'
  19. )
  20. .defines(function(){
  21.  
  22.     window.RType = ig.Game.extend({
  23.    
  24.     font:             new ig.Font ('media/fonts/04b03.font.png'           ),
  25.     backdrop:         new ig.Image('media/backgrounds/tempBG.png'         ),
  26.     grid:             new ig.Image('media/backgrounds/tempBG.png'         ),
  27.     scanlines:        new ig.Image('media/backgrounds/scan-lines.png'     ),
  28.     lifeSprite:       new ig.Image('media/ui/ship_lifebar.png'            ),
  29.     statMatte:        new ig.Image('media/ui/stat-matte.png'              ),
  30.     transTextBG:      new ig.Image('media/ui/transTextBG.png'             ),
  31.     transTextBG_Lg:   new ig.Image('media/ui/transTextBG_Lg.png'          ),
  32.     bulletTimeSprite: new ig.Image('media/ui/BulletTimeDisplayBar1.png'   ),
  33.     stage38Music:     new ig.Sound('media/Music/Stage38.mp3', true        ),
  34.     stage38Music:     new ig.Sound('media/Music/Stage38.ogg', true        ),
  35.     stage38Music:     new ig.Sound('media/Music/Stage38.*',   true        ),
  36.  
  37.     entitiesKilled:  0,
  38.     maxEntites:      6,
  39.     currentEntities: 0,
  40.  
  41.     hudOffsetX:      20,
  42.     hudOffsetY:      20,
  43.     menu:            null,
  44.     mode:            0,
  45.  
  46.  
  47.    
  48.    
  49.     /*******************************************
  50.     * Init
  51.     *******************************************/
  52.     init: function () {
  53.         this.inputControls();
  54.         this.setGame();
  55.     },
  56.    
  57.     /*******************************************
  58.     * Update
  59.     *******************************************/
  60.     update: function() {
  61.         this.parent();
  62.         this.backgroundMaps[0].scroll.x += 30 * ig.system.tick;
  63.  
  64.         if (!this.menu && (ig.input.pressed('menu'))) {
  65.             this.toggleMenu();
  66.         }
  67.         if (this.menu) {
  68.             this.backgroundMaps[0].scroll.x += 100 * ig.system.tick;
  69.             this.menu.update();
  70.             if ( ig.input.pressed('shoot') && ig.input.mouse.x > ig.system.width - 154 && ig.input.mouse.y > ig.system.height - 56) {
  71.                 window.location = 'http://impactjs.com/';
  72.             }
  73.             if (!(this.menu instanceof GameOverMenu)) {
  74.                 return;
  75.             }
  76.         }
  77.  
  78.     },
  79.    
  80.     /*******************************************
  81.     * Draw
  82.     *******************************************/
  83.     draw: function () {
  84.         ig.system.clear(this.clearColor);
  85.         this.backdrop.draw(0, 0);
  86.  
  87.         for (var i = 0; i < this.backgroundMaps.length; i++) {
  88.             this.backgroundMaps[i].draw();
  89.         }
  90.         this.scanlines.draw(0, 0);
  91.  
  92.         for (var i = 0; i < this.entities.length; i++) {
  93.             this.entities[i].draw();
  94.         }
  95.  
  96.         /* HUD in top-left corner
  97.          ************************/
  98.         // Draws transparent background behind text
  99.         this.transTextBG_Lg.draw(this.hudOffsetX -9, this.hudOffsetY - 13);
  100.  
  101.         // Draws lifebar
  102.         this.font.draw("Lives", this.hudOffsetX + 7, this.hudOffsetY - 4);
  103.         for (var i = 0; i < this.stats.lives; i++)
  104.             this.lifeSprite.draw(((this.lifeSprite.width + 1) * i) + this.hudOffsetX +4, this.hudOffsetY + 4);
  105.        
  106.         // Draws bullet time bar
  107.         this.font.draw("Bullet Time", this.hudOffsetX +7, this.hudOffsetY + 22);
  108.         for (var i = 0; i < this.bulletTime.current; i++)
  109.             this.bulletTimeSprite.draw(((this.bulletTimeSprite.width + 4) * i) + this.hudOffsetX +7, this.hudOffsetY + 32);
  110.  
  111.         /* HUD in top-right corner
  112.          ************************/
  113.         // Draws transparent background behind text
  114.         this.transTextBG_Lg.draw(ig.system.width - this.transTextBG_Lg.width - 9, this.hudOffsetY - 13);
  115.  
  116.         // Draws score
  117.         this.font.draw("Current Score", ig.system.width - this.transTextBG_Lg.width + 5, this.hudOffsetY - 4);
  118.         this.font.draw(this.stats.kills * 100, ig.system.width - this.transTextBG_Lg.width + 5, this.hudOffsetY + 10);
  119.  
  120.         // Draw kills until boss
  121.         this.font.draw("Kills untill boss", ig.system.width - this.transTextBG_Lg.width + 5, this.hudOffsetY + 25);
  122.         this.font.draw(-this.stats.kills + this.bossSpawnKills.easy, ig.system.width - this.transTextBG_Lg.width + 5, this.hudOffsetY + 39);
  123.     },
  124.  
  125.    
  126.     /******************************************
  127.     * Input Controls
  128.     ******************************************/
  129.     inputControls: function(){
  130.         ig.input.bind(ig.KEY.A,          'left'          );
  131.         ig.input.bind(ig.KEY.LEFT_ARROW, 'left'          );
  132.         ig.input.bind(ig.KEY.D,          'right'         );
  133.         ig.input.bind(ig.KEY.RIGHT_ARROW,'right'         );
  134.         ig.input.bind(ig.KEY.W,          'up'            );
  135.         ig.input.bind(ig.KEY.UP_ARROW,   'up'            );
  136.         ig.input.bind(ig.KEY.S,          'down'          );
  137.         ig.input.bind(ig.KEY.DOWN_ARROW, 'down'          );
  138.        
  139.         ig.input.bind(ig.KEY.C,          'shoot'         );
  140.         ig.input.bind(ig.KEY.TAB,        'switch'        );
  141.         ig.input.bind(ig.KEY.X,          'slowTime'      );
  142.         ig.input.bind(ig.KEY.Q,          'spawnCompanion');
  143.         ig.input.bind(ig.KEY.MOUSE1,     'shoot'         );
  144.         ig.input.bind(ig.KEY.MOUSE2,     'rightClick'    );
  145.         ig.input.bind(ig.KEY.V,          'shootTest'     );
  146.         ig.input.bind(ig.KEY.SPACE,      'pause'         );
  147.         ig.input.bind(ig.KEY.ESC,        'menu'          );
  148.     },
  149.  
  150.  
  151.     /******************************************
  152.     * gameOver
  153.     * Called by player when lived = 0
  154.     ******************************************/
  155.     gameOver: function () {
  156.         ig.finalStats = ig.game.stats;
  157.         ig.system.setGame(StaffRollScreen);
  158.         ig.game.currentEntities = 0;
  159.         EntityPickupBulletTime.prototype.currentBulletTime = 2;
  160.     },
  161.  
  162.     /*****************************************
  163.     * toggleMenu
  164.     ******************************************/
  165.     toggleMenu: function () {
  166.         if (this.mode == RType.MODE.TITLE) {
  167.             if (this.menu instanceof TitleMenu) {
  168.                 this.menu = new PauseMenu();
  169.             } else {
  170.                 this.menu = new TitleMenu();
  171.             }
  172.         } else {
  173.             if (this.menu) {
  174.                 ig.system.canvas.style.cursor = '';
  175.                 this.menu = null;
  176.             } else {
  177.                 this.menu = new PauseMenu();
  178.             }
  179.         }
  180.     },
  181.  
  182.     /*******************************************
  183.     * setGame
  184.     *******************************************/
  185.     setGame: function () {
  186.         window.scrollTo(0, 0);
  187.         ig.music.add(this.stage38Music, 'stage38Music');
  188.         ig.music.next();
  189.         ig.music.play('stage38Music');
  190.         ig.music.loop     = true;
  191.  
  192.         this.menu         = null;
  193.         var bgmap         = new ig.BackgroundMap(620, [
  194.                             [1]], this.grid);
  195.         bgmap.repeat      = true;
  196.         this.backgroundMaps.push(bgmap);
  197.         this.player       = ig.game.spawnEntity(EntityActorPlayer,       ig.system.width / 2, ig.system.height / 2);
  198.         this.enemySpawner = ig.game.spawnEntity(EntityActorEnemySpawner, ig.system.width / 2, ig.system.height / 2);
  199.         this.mode         = RType.MODE.game;
  200.     },
  201.  
  202.     /*******************************************
  203.     * setTitle
  204.     *******************************************/
  205.     setTitle: function () {
  206.         this.reset();
  207.         this.mode = RType.MODE.TITLE;
  208.         this.menu = new TitleMenu();
  209.     },
  210.  
  211. });
  212.  
  213.     /*******************************************
  214.     * CREDITS SCREEN
  215.     *******************************************/
  216.     StaffRollScreen = ig.Game.extend({      
  217.         instructText:   new ig.Font ('media/fonts/04b03.font.png'      ),
  218.         background:     new ig.Image('media/backgrounds/StaffRoll.png' ),
  219.         staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.mp3'    ),
  220.         staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.ogg'    ),
  221.         staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.*'      ),
  222.  
  223.         init: function () {
  224.             // Loads music, then begins to play track
  225.             ig.music.add(this.staffRollMusic, 'staffRollMusic');
  226.             ig.music.play('staffRollMusic');
  227.  
  228.             ig.input.bind(ig.KEY.SPACE, 'start');
  229.             ig.input.bind(ig.KEY.ENTER, 'start');
  230.         },
  231.  
  232.         /*******************************************
  233.         * Update
  234.         *******************************************/
  235.         update: function () {
  236.             if (ig.input.pressed('start') || ig.input.pressed('click')) {
  237.                 ig.system.setGame(StartScreen);
  238.             }
  239.             this.parent();
  240.         },
  241.  
  242.         /*******************************************
  243.         * Draw
  244.         *******************************************/
  245.         draw: function () {
  246.             this.parent();
  247.             ig.music.play('StaffRoll');
  248.             this.background.draw(0, 0);
  249.             var x = ig.system.width  / 2,
  250.                 y = ig.system.height / 2;
  251.             this.instructText.draw('Thanks for playing!',                                                  x, y,      ig.Font.ALIGN.CENTER);
  252.             this.instructText.draw('Press SpaceBar or Enter to continue',                                  x, y + 40, ig.Font.ALIGN.CENTER);
  253.             this.instructText.draw('All music property of YouTube user Kevvviiinnn',                       x, y - 80, ig.Font.ALIGN.CENTER);
  254.             this.instructText.draw('Developer: Dave Voyles - @DaveVoyles | www.DavidVoyles.Wordpress.com', x, y - 70, ig.Font.ALIGN.CENTER);
  255.         }
  256.     });
  257.  
  258.  
  259.     /*******************************************
  260.     * Instructions Screen
  261.     *******************************************/
  262.     InstructionsScreen = ig.Game.extend({
  263.         backgroundInstructions: new ig.Image('media/backgrounds/instructScreen.png'),
  264.         instructText:           new ig.Font('media/fonts/04b03.font.png'                   ),
  265.  
  266.         init: function () {
  267.             ig.input.bind(ig.KEY.SPACE, 'start');
  268.             ig.input.bind(ig.KEY.ENTER, 'start');
  269.         },
  270.  
  271.         /*******************************************
  272.         * Update
  273.         *******************************************/
  274.         update: function () {
  275.             if (ig.input.pressed('start') || ig.input.pressed('click')) {
  276.                 ig.system.setGame(MyGame);
  277.             }
  278.             this.parent();
  279.         },
  280.  
  281.         /*******************************************
  282.         * Draw
  283.         *******************************************/
  284.         draw: function () {
  285.             this.parent();
  286.             ig.music.play('StaffRoll');
  287.             this.backgroundInstructions.draw(0, 0);
  288.             var x = ig.system.width  / 2;
  289.                 y = ig.system.height / 2;
  290.             this.instructText.draw('Press SpaceBar, Enter, or touch to continue', x, y - 100, ig.Font.ALIGN.CENTER);
  291.         }
  292.     });
  293.  
  294.  
  295.     window.RType.MODE = {
  296.         TITLE: 0,
  297.         GAME: 1,
  298.         GAME_OVER: 2,
  299.         SCORES: 3
  300.     };
  301.  
  302. //if (ig.ua.mobile) {
  303.     //Disable sound for all mobile devices
  304.     ig.Sound.enabled = false;
  305. //}
  306.  
  307. ig.main( '#canvas', RType, 60, 924, 650, 1 );
  308. });
RAW Paste Data