Commits

Pedro Ferreira  committed 4231da7

- remove old code related to collision detection

  • Participants
  • Parent commits a4508f3

Comments (0)

Files changed (2)

 }
     
     
-    
-    
-
-
-function checkIfBulletsHitAnything( ships, bullets )
-{
-var bulletX, bulletY;
-
-var bulletLeftSide, bulletRightSide, bulletUpSide, bulletDownSide;
-var enemyLeftSide, enemyRightSide, enemyUpSide, enemyDownSide;
-
-    // jquery 'equivalent'  of forEach()
-$( ships ).each(function( ship_index, ship )
-    {
-    $( bullets ).each(function( bullet_index, bullet )
-        {
-        bulletX = bullet.shape.x;
-        bulletY = bullet.shape.y;
-        
-        var bulletHalfWidth = bullet.width / 2;
-        var bulletHalfHeight = bullet.height / 2;
-        
-        
-            // to simplify, lets use a rectangle for the collision detection (each type of bullet/weapon has a width/height property to tell the bullet dimensions)
-        bulletLeftSide = bulletX - bulletHalfWidth;
-        bulletRightSide = bulletX + bulletHalfWidth;
-        bulletUpSide = bulletY - bulletHalfHeight;
-        bulletDownSide = bulletY + bulletHalfHeight;
-        
-            // the ship is centered on 0
-        var halfWidth = ship.width / 2;
-        var halfHeight = ship.height / 2; 
-        
-            // same for the enemy
-        enemyLeftSide = ship.x - halfWidth;
-        enemyRightSide = ship.x + halfWidth;
-        enemyUpSide = ship.y - halfHeight;
-        enemyDownSide = ship.y + halfHeight;
-
-            // check if it hits the EnemyShip
-        if ( !(bulletRightSide < enemyLeftSide || bulletLeftSide > enemyRightSide || bulletDownSide < enemyUpSide || bulletUpSide > enemyDownSide) )
-            
-        //if ( enemy.hitTest(bulletX, bulletY) )
-            {
-                // remove the bullet
-            bullet.remove( bullet_index );
-            
-                // remove the EnemyShip
-            ship.tookDamage();
-            
-                // breaks this loop
-            return false;   
-            }
-        });
-    });
-
-}
-
-
 
 
 function addNewEnemy( enemyObject )
     i--;
     }
 
-    // check if enemy bullets hit our ship
-//checkIfBulletsHitAnything( [ MAIN_SHIP ], Weapons.enemyBullets );
-
-    // check if our bullets hit the enemy
-//checkIfBulletsHitAnything( EnemyShip.all, Weapons.allyBullets );
 
     // call the tick() of the current game mode
 GAME_MODE.tick();
 
 return false;
 };
- 
-     
-Ship.checkIfCollidedWithEnemies = function()
-{
-var i, k;
-var enemies = EnemyShip.all;
-
-
-
-var ship;
-var enemy;
-
-var shipLeftSide, shipRightSide, shipUpSide, shipDownSide;
-var enemyLeftSide, enemyRightSide, enemyUpSide, enemyDownSide;
-
-for (k = 0 ; k < Ship.all.length ; k++)
-    {
-    ship = Ship.all[k];
-    
-    shipLeftSide = ship.shape.x - 5;
-    shipRightSide = ship.shape.x + 5;
-    shipUpSide = ship.shape.y - 5;
-    shipDownSide = ship.shape.y + 5;
-    
-    for (i = 0 ; i < enemies.length ; i++)
-        {
-        enemy = enemies[i];
-            
-            // we'll assume a square of the impact area
-        enemyLeftSide = enemy.x - 10;
-        enemyRightSide = enemy.x + 10;
-        enemyUpSide = enemy.y - 10;
-        enemyDownSide = enemy.y + 10;
-        
-            // check if they collide
-        if ( !(shipRightSide < enemyLeftSide || shipLeftSide > enemyRightSide || shipDownSide < enemyUpSide || shipUpSide > enemyDownSide) )
-            {
-            ship.tookDamage( enemy.damageGiven() );
-
-                // if so, remove the enemy, and reduce the energy
-            enemy.tookDamage();
-            
-                // the array changed in length (since we removed one element. Update the index)
-            i--;
-            }
-        }
-    }
-
-};
 
 
 
     }
 
     
-//Ship.checkIfCollidedWithEnemies();
-
 this.updateShape();
 
 this.updateAmmo();