Exemplo n.º 1
0
 public int FindLastSideTouched(Map map, Projectile projectile, Point currentPosition, int currentFinalSide, ref Vector2 intersectingPoint)
 {
     Point[] directions = new Point[] { new Point(0, -1), new Point(1, 0), new Point(0, 1), new Point(-1, 0) };
     int finalSide = currentFinalSide;
     Vector2 newPosition = projectile.position + (projectile.velocity * 2);
     //if the new position is not the same as the last position and still in the tileMatrix
     if (currentPosition.X >= 0 && currentPosition.Y >= 0 && currentPosition.X < map.tiles.Length && currentPosition.Y < map.tiles[0].Length)
     {
         Tile tile = map.GetTile(currentPosition);
         //if the tile is a collidable tile then check
         if (tile.collidable)
         {
             //check to see if this tile has a last side touched
             tile.lastSideTouched = Core.Collision.LastSideTouched(tile.GetBounds(), projectile.safePosition, newPosition);
             int actualSide = tile.GetSingleLastSideTouched();
             if (actualSide > -1)
             {
                 //reset projectile position to intersection point of the tile
                 intersectingPoint = tile.lastSideTouched[actualSide];
                 finalSide = FindLastSideTouched(map, projectile, new Point(currentPosition.X + directions[actualSide].X, currentPosition.Y + directions[actualSide].Y), actualSide, ref intersectingPoint);
             }
             tile.lastSideTouched = new Vector2[4] { new Vector2(-1, -1), new Vector2(-1, -1), new Vector2(-1, -1), new Vector2(-1, -1) };
         }
     }
     return finalSide;
 }
Exemplo n.º 2
0
 private int CheckProjectileCollisions(CollidableObject sprite, Projectile projectile)
 {
     int score = 0;
     if (projectile.alive)
         score += projectile.CheckCollision(sprite);
     return score;
 }