Commits

Pedro Ferreira committed 86118e6

- rocks separate in 3 when take damage

Comments (0)

Files changed (4)

         .spawnTick_function : reference to a function that is called in the .tick() during the spawn of the enemy
         .tick_function      : reference to a function that is called in the .tick() after the spawn (in the normal behaviour)
         
+    Override is necessary:
+    
+        .damageTaken()
+        
  */
 
 function EnemyShip()
 };
 
 
-EnemyShip.prototype.damageTaken = function( position )
+EnemyShip.prototype.damageTaken = function()
 {
-    //HERE for now just remove it
-this.remove( position );
+    // just remove it (override this for something different)
+this.remove();
 };
 
 
     Remove the enemy ship, and update the game statistics
  */
 
-p.remove = function( position )
+p.remove = function()
 {
 STAGE.removeChild( this );
 
 Ticker.removeListener( this );
 
+var position = EnemyShip.all.indexOf( this );
+
 EnemyShip.all.splice( position, 1 );
 
 

js/enemy_rocks.js

 
 "use strict";
 
+/*
+    Arguments:
+    
+        scale: scale the original image (1 -> 100%, no scaling)
+ */
 
-function EnemyRocks()
+function EnemyRocks( scale )
 {
 this.shape = null;
 
 this.width = 50;
 this.height = 50;
 
+if (typeof scale != "undefined" && $.isNumeric( scale ))
+    {
+    this.scale = scale;
+    }
+
+else
+    {
+    this.scale = 1;
+    }
+
     // inherits from the EnemyShip class
 EnemyShip.call( this );
 }
 rock.regX = this.width / 2;
 rock.regY = this.height / 2;
 
+rock.scaleX = this.scale;
+rock.scaleY = this.scale;
+
+    // don't update these variables before the scaling (they're are used in the config above, and the scaling is applied later)
+this.width *= this.scale;
+this.height *= this.scale;
+
     // it moves 
 this.angleRadians = getRandomFloat( 0, 2 * Math.PI );
 
 };
 
 
+/*
+    When it takes damage, create new smaller rocks
+ */
 
+EnemyRocks.prototype.damageTaken = function()
+{
+if (this.width >= 50)
+    {
+    var i;
+    
+    for (i = 0 ; i < 3 ; i++)
+        {
+        var rock = new EnemyRocks( 0.5 );
+        
+            // spawn from the current position
+        rock.x = this.x;
+        rock.y = this.y;
+        
+        addNewEnemy( rock );
+        }
+    }
 
+this.remove();
+};
 
 
+
             bullet.remove( bullet_index );
             
                 // remove the EnemyShip
-            ship.damageTaken( ship_index );
+            ship.damageTaken();
             
                 // breaks this loop
             return false;   
 
 
 
+function addNewEnemy( enemyObject )
+{
+enemyObject.beforeAddToStage();
+      
+STAGE.addChild( enemyObject );
+
+ZIndex.update();
+
+Ticker.addListener( enemyObject );
+}
+
+
+
+
 function tick()
 {
 COUNT_TICKS_NEXT_ENEMY--;
     enemy.x = x;
     enemy.y = y;
     
-    enemy.beforeAddToStage();
-          
-    STAGE.addChild( enemy );
-    
-    ZIndex.update();
-    
-    Ticker.addListener( enemy );
+    addNewEnemy( enemy );
     }
     
 
             ship.tookDamage( enemy.damageGiven() );
 
                 // if so, remove the enemy, and reduce the energy
-            enemy.remove( i );
+            enemy.damageTaken();
             
                 // the array changed in length (since we removed one element. Update the index)
             i--;
 };
 
 
-Ship.prototype.damageTaken = function( position )
+Ship.prototype.damageTaken = function()
 {
 //HERE
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.