예제 #1
0
        /// <summary>
        /// Returns true if projectile is still alive
        /// </summary>
        /// <param name="gameTime"></param>
        /// <returns>True if projectile is still alive</returns>
        public bool Update(GameTime gameTime, Map map, ParticleTools particleTools)
        {
            offset += (float)gameTime.ElapsedGameTime.TotalMilliseconds * ProjectileSpeed;

            TileInfo.SideType    direction      = TileInfo.FromFacing(horizontalDirection, verticalDirection);
            Rectangle            rectangle      = CollisionRectangle;
            List <CollisionTile> collidingTiles = map.GetCollidingTiles(rectangle, direction);

            for (int i = 0; i < collidingTiles.Count; i++)
            {
                TileInfo.SideType side = TileInfo.OppositeSide(direction);
                GameUnit          perpendicularPosition = TileInfo.Vertical(side) ?
                                                          rectangle.Center.X : rectangle.Center.Y;
                GameUnit          leadingPosition  = rectangle.Side(direction);
                bool              shouldTestSlopes = true;
                TestCollisionInfo testInfo         = collidingTiles[i].TestCollision(side, perpendicularPosition,
                                                                                     leadingPosition, shouldTestSlopes);
                if (testInfo.isColliding)
                {
                    GameUnit collisionX;
                    if (TileInfo.Vertical(side))
                    {
                        collisionX = perpendicularPosition;
                    }
                    else
                    {
                        collisionX = testInfo.position;
                    }
                    GameUnit collisionY;
                    if (TileInfo.Vertical(side))
                    {
                        collisionY = testInfo.position;
                    }
                    else
                    {
                        collisionY = perpendicularPosition;
                    }
                    particleTools.FrontSystem.AddNewParticle(ProjectileWallParticle.Create(particleTools.Content,
                                                                                           collisionX - Units.HalfTile, collisionY - Units.HalfTile));
                    return(false);
                }
            }
            if (!alive)
            {
                return(false);
            }
            else if (offset >= ProjectileMaxOffsets[gunLevel - 1])
            {
                particleTools.FrontSystem.AddNewParticle(ProjectileStarParticle.Create(particleTools.Content, X, Y));
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #2
0
        CollisionInfo?TestMapStickyCollision(Map map, Rectangle rectangle,
                                             TileInfo.SideType direction, BitArray maybeGroundTile)
        {
            List <CollisionTile> tiles = map.GetCollidingTiles(rectangle, direction);

            for (int i = 0; i < tiles.Count; i++)
            {
                TileInfo.SideType side = TileInfo.OppositeSide(direction);
                GameUnit          perpendicularPosition;
                if (TileInfo.Vertical(side))
                {
                    perpendicularPosition = rectangle.Center.X;
                }
                else
                {
                    perpendicularPosition = rectangle.Center.Y;
                }
                GameUnit          leadingPosition  = rectangle.Side(direction);
                bool              shouldTestSlopes = TileInfo.Vertical(side);
                TestCollisionInfo testInfo         = tiles[i].TestCollision(side, perpendicularPosition,
                                                                            leadingPosition, shouldTestSlopes);
                if (testInfo.isColliding)
                {
                    CollisionInfo info = new CollisionInfo(testInfo.position, tiles[i].Position, tiles[i].TileType);
                    return(info);
                }
                else if (maybeGroundTile != null && direction == TileInfo.SideType.BottomSide)
                {
                    BitArray tallSlope = TileInfo.CreateTileType();
                    tallSlope.Set((int)TileInfo.TileFlag.Slope, true);
                    tallSlope.Set((int)TileInfo.TileFlag.TallSlope, true);
                    if ((maybeGroundTile[(int)TileInfo.TileFlag.Slope] && tiles[i].TileType[(int)TileInfo.TileFlag.Slope]) ||
                        (maybeGroundTile[(int)TileInfo.TileFlag.Wall] &&
                         (tallSlope.And(tiles[i].TileType).Equals(tallSlope))))
                    {
                        CollisionInfo info = new CollisionInfo(testInfo.position, tiles[i].Position, tiles[i].TileType);
                        return(info);
                    }
                }
            }
            return(null);
        }
예제 #3
0
        CollisionInfo?TestMapBouncingCollision(Map map, Rectangle rectangle,
                                               TileInfo.SideType direction, BitArray maybeGroundTile)
        {
            List <CollisionTile> tiles  = map.GetCollidingTiles(rectangle, direction);
            CollisionInfo?       result = null;

            for (int i = 0; i < tiles.Count; i++)
            {
                TileInfo.SideType side = TileInfo.OppositeSide(direction);
                GameUnit          perpendicularPosition;
                if (TileInfo.Vertical(side))
                {
                    perpendicularPosition = rectangle.Center.X;
                }
                else
                {
                    perpendicularPosition = rectangle.Center.Y;
                }
                GameUnit          leadingPosition  = rectangle.Side(direction);
                bool              shouldTestSlopes = TileInfo.Vertical(side);
                TestCollisionInfo testInfo         = tiles[i].TestCollision(side, perpendicularPosition,
                                                                            leadingPosition, shouldTestSlopes);
                if (testInfo.isColliding)
                {
                    bool shouldReplaceResult = true;
                    if (result.HasValue)
                    {
                        shouldReplaceResult = TileInfo.IsMin(side) ?
                                              testInfo.position <result.Value.position :
                                                                 testInfo.position> result.Value.position;
                    }
                    if (shouldReplaceResult)
                    {
                        CollisionInfo info = new CollisionInfo(testInfo.position, tiles[i].Position, tiles[i].TileType);
                        result = info;
                    }
                }
            }
            return(result);
        }
예제 #4
0
 CollisionInfo? TestMapBouncingCollision(Map map, Rectangle rectangle,
     TileInfo.SideType direction, BitArray maybeGroundTile)
 {
     List<CollisionTile> tiles = map.GetCollidingTiles(rectangle, direction);
     CollisionInfo? result = null;
     for (int i = 0; i < tiles.Count; i++)
     {
         TileInfo.SideType side = TileInfo.OppositeSide(direction);
         GameUnit perpendicularPosition;
         if (TileInfo.Vertical(side))
         {
             perpendicularPosition = rectangle.Center.X;
         }
         else
         {
             perpendicularPosition = rectangle.Center.Y;
         }
         GameUnit leadingPosition = rectangle.Side(direction);
         bool shouldTestSlopes = TileInfo.Vertical(side);
         TestCollisionInfo testInfo = tiles[i].TestCollision(side, perpendicularPosition,
             leadingPosition, shouldTestSlopes);
         if (testInfo.isColliding)
         {
             bool shouldReplaceResult = true;
             if (result.HasValue)
             {
                 shouldReplaceResult = TileInfo.IsMin(side) ?
                     testInfo.position < result.Value.position :
                     testInfo.position > result.Value.position;
             }
             if (shouldReplaceResult)
             {
                 CollisionInfo info = new CollisionInfo(testInfo.position, tiles[i].Position, tiles[i].TileType);
                 result = info;
             }
         }
     }
     return result;
 }
예제 #5
0
 CollisionInfo? TestMapStickyCollision(Map map, Rectangle rectangle,
     TileInfo.SideType direction, BitArray maybeGroundTile)
 {
     List<CollisionTile> tiles = map.GetCollidingTiles(rectangle, direction);
     for (int i = 0; i < tiles.Count; i++)
     {
         TileInfo.SideType side = TileInfo.OppositeSide(direction);
         GameUnit perpendicularPosition;
         if (TileInfo.Vertical(side))
         {
             perpendicularPosition = rectangle.Center.X;
         }
         else
         {
             perpendicularPosition = rectangle.Center.Y;
         }
         GameUnit leadingPosition = rectangle.Side(direction);
         bool shouldTestSlopes = TileInfo.Vertical(side);
         TestCollisionInfo testInfo = tiles[i].TestCollision(side, perpendicularPosition,
             leadingPosition, shouldTestSlopes);
         if (testInfo.isColliding)
         {
             CollisionInfo info = new CollisionInfo(testInfo.position, tiles[i].Position, tiles[i].TileType);
             return info;
         }
         else if (maybeGroundTile != null && direction == TileInfo.SideType.BottomSide)
         {
             BitArray tallSlope = TileInfo.CreateTileType();
             tallSlope.Set((int)TileInfo.TileFlag.Slope, true);
             tallSlope.Set((int)TileInfo.TileFlag.TallSlope, true);
             if ((maybeGroundTile[(int)TileInfo.TileFlag.Slope] && tiles[i].TileType[(int)TileInfo.TileFlag.Slope]) ||
                 (maybeGroundTile[(int)TileInfo.TileFlag.Wall] &&
                 (tallSlope.And(tiles[i].TileType).Equals(tallSlope))))
             {
                 CollisionInfo info = new CollisionInfo(testInfo.position, tiles[i].Position, tiles[i].TileType);
                 return info;
             }
         }
     }
     return null;
 }
예제 #6
0
        /// <summary>
        /// Returns true if projectile is still alive
        /// </summary>
        /// <param name="gameTime"></param>
        /// <returns>True if projectile is still alive</returns>
        public bool Update(GameTime gameTime, Map map, ParticleTools particleTools)
        {
            offset += (float)gameTime.ElapsedGameTime.TotalMilliseconds * ProjectileSpeed;

            TileInfo.SideType direction = TileInfo.FromFacing(horizontalDirection, verticalDirection);
            Rectangle rectangle = CollisionRectangle;
            List<CollisionTile> collidingTiles = map.GetCollidingTiles(rectangle, direction);
            for (int i = 0; i < collidingTiles.Count; i++)
            {
                TileInfo.SideType side = TileInfo.OppositeSide(direction);
                GameUnit perpendicularPosition = TileInfo.Vertical(side) ?
                    rectangle.Center.X : rectangle.Center.Y;
                GameUnit leadingPosition = rectangle.Side(direction);
                bool shouldTestSlopes = true;
                TestCollisionInfo testInfo = collidingTiles[i].TestCollision(side, perpendicularPosition,
                    leadingPosition, shouldTestSlopes);
                if (testInfo.isColliding)
                {
                    GameUnit collisionX;
                    if (TileInfo.Vertical(side))
                    {
                        collisionX = perpendicularPosition;
                    }
                    else
                    {
                        collisionX = testInfo.position;
                    }
                    GameUnit collisionY;
                    if (TileInfo.Vertical(side))
                    {
                        collisionY = testInfo.position;
                    }
                    else
                    {
                        collisionY = perpendicularPosition;
                    }
                    particleTools.FrontSystem.AddNewParticle(ProjectileWallParticle.Create(particleTools.Content,
                        collisionX - Units.HalfTile, collisionY - Units.HalfTile));
                    return false;
                }
            }
            if (!alive)
            {
                return false;
            }
            else if (offset >= ProjectileMaxOffsets[gunLevel - 1])
            {
                particleTools.FrontSystem.AddNewParticle(ProjectileStarParticle.Create(particleTools.Content, X, Y));
                return false;
            }
            else
            {
                return true;
            }
        }