Guest User

Untitled

a guest
Mar 8th, 2013
73
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*********************************************************************8
  2.  * StationaryShip.js
  3.  * Small ship that helps the player and remains stationary
  4.  * @copyright (c) 2013 Dave Voyles, under The MIT License (see LICENSE)
  5.  *********************************************************************/
  6.  
  7. // PROBLEM: The "else" statement is always spawning the ship. Why is it defaulting to bCanSpawnShips to
  8. // false? It *should* spawn the top shop (the "if") statement, THEN if pressed again, spawn the "else"
  9. ig.module(
  10.     'game.entities.StationaryShip'
  11. )
  12.     .requires(
  13.         'game.entities.player'
  14. )
  15.     .defines(function()
  16.     {
  17.         EntityStationaryShip = EntityPlayer.extend({
  18.         name: 'StationaryShip',
  19.         parental:null,
  20.         type:ig.Entity.TYPE.NONE,
  21.         checkAgainst: ig.Entity.TYPE.B, // Check Against B - our evil enemy group
  22.         collides: ig.Entity.COLLIDES.PASSIVE,
  23.         angle:0,
  24.         bShipExists: false,
  25.         maxShips: 2,
  26.         currentShips: 0,
  27.         bCanSpawnShips: true,
  28.  
  29.  
  30.             /******************************************8
  31.              * Initialize
  32.              ******************************************/
  33.             init: function(x,y,settings){
  34.                 this.parent( x, y, settings );
  35.                 bShipExists = false;
  36.                 currentShips = 0;
  37.                 maxShips = 2;
  38.                 bCanSpawnShips = true;
  39.             },
  40.  
  41.             /******************************************8
  42.              * Update
  43.              ******************************************/
  44.             update:function(x,y,settings){
  45.                 this.parental = ig.game.getEntitiesByType(EntityPlayer)[0];
  46.  
  47.                 // Spawning location of ships
  48.                 var offsetX = 20;
  49.                 var offsetY = 40;
  50.  
  51.                 // Spawn ships when "X" button is hit
  52.                 if (bCanSpawnShips == true){
  53.                     x = this.parental.pos.x + offsetX;
  54.                     y = this.parental.pos.y + offsetY;
  55.                     bShipExists = true;
  56.                     currentShips++;
  57.                 }
  58.                 else{
  59.                     x = this.parental.pos.x + offsetX;
  60.                     y = this.parental.pos.y - offsetY;
  61.                     currentShips++;
  62.                 }
  63.  
  64.                  if (currentShips > maxShips){
  65.                      canSpawnShips = false;
  66.                      currentShips = maxShips;
  67.                  }
  68.  
  69.                 // Sets current position
  70.                 this.pos.x = x;
  71.                 this.pos.y = y;
  72.             },
  73.  
  74.  
  75.             /******************************************8
  76.              * Handle Movements
  77.              ******************************************/
  78.             handleMovementTrace: function( res ) {
  79.                 this.parent( res );
  80.             },
  81.  
  82.             // This function is called when this entity overlaps anonther entity of the
  83.             // checkAgainst group. I.e. for this entity, all entities in the B group.
  84.             check: function( other ) {
  85.                 other.receiveDamage( 0, this );
  86.                 this.kill();
  87. //                canSpawnShips = true;
  88. //                currentShips --;
  89.             }
  90.  
  91.     });
  92. });
RAW Paste Data