예제 #1
0
        public bool CheckDownCollisions()
        {
            //foreach (List<Tile> subList in CurrentLevel.CollisionTileList)
            {
                foreach (CollisionTile tile in CurrentLevel.CollisionTileList)
                {
                    for (int i = 0; i < CollisionRectangle.Width; i++)
                    {
                        if (tile.BoundingBox.Contains(new Point((int)(CollisionRectangle.Left + i),
                                                                (int)(CollisionRectangle.Bottom + Velocity.Y + 1))) == true)
                        {
                            if (Velocity.Y > 8 && tile.TopDecal == null && (tile as CollisionTile) != null)
                            {
                                Decal newDecal = new Decal();
                                newDecal.Size = tile.Size;
                                newDecal.Initialize(DecalTexture, tile, new Vector2(0, 1));
                                tile.TopDecal = newDecal;
                            }

                            Position.Y += (tile.BoundingBox.Top - CollisionRectangle.Bottom);
                            Velocity.Y  = -Velocity.Y * 0.5f;
                            Velocity.X *= 0.95f;
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
예제 #2
0
        public bool CheckLeftCollisions()
        {
            //foreach (List<Tile> subList in CurrentLevel.CollisionTileList)
            {
                foreach (CollisionTile tile in CurrentLevel.CollisionTileList)
                {
                    for (int i = 0; i < CollisionRectangle.Height; i++)
                    {
                        if (tile.BoundingBox.Contains(new Point((int)(CollisionRectangle.Left + Velocity.X - 1), (int)(CollisionRectangle.Top + i))) == true)
                        {
                            if (Velocity.X < -6 && tile.RightDecal == null && (tile as CollisionTile) != null)
                            {
                                Decal newDecal = new Decal();
                                newDecal.Size = tile.Size;
                                newDecal.Initialize(DecalTexture, tile, new Vector2(1, 0));
                                tile.RightDecal = newDecal;
                            }

                            Position.X += (tile.BoundingBox.Right - CollisionRectangle.Left);
                            Velocity.X  = -Velocity.X * 0.5f;
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }