Ejemplo n.º 1
0
		void CustomInitialize()
		{
            mCollision = new TileShapeCollection();
            mCollision.GridSize = 32;
            mCollision.Visible = true;

            for (int i = 0; i < 10; i++)
            {
                mCollision.AddCollisionAtWorld(i * 32 + 16, 16);

            }

		}
Ejemplo n.º 2
0
        public static void AddMergedCollisionFromLayer(this TileShapeCollection tileShapeCollection, MapDrawableBatch layer, LayeredTileMap layeredTileMap,
                                                       Func <List <TMXGlueLib.DataTypes.NamedValue>, bool> predicate)
        {
            var   properties    = layeredTileMap.TileProperties;
            float dimension     = layeredTileMap.WidthPerTile.Value;
            float dimensionHalf = dimension / 2.0f;

            tileShapeCollection.GridSize = dimension;

            Dictionary <int, List <int> > rectangleIndexes = new Dictionary <int, List <int> >();

            AddCollisionFromLayerInternal(tileShapeCollection, predicate, properties, dimension, dimensionHalf, rectangleIndexes, layer);

            ApplyMerging(tileShapeCollection, dimension, rectangleIndexes);
        }
Ejemplo n.º 3
0
        private static void AddRectangleStrip(TileShapeCollection tileShapeCollection, float x, float y, float width, float height)
        {
            AxisAlignedRectangle rectangle = new AxisAlignedRectangle();

            rectangle.X      = x;
            rectangle.Y      = y;
            rectangle.Width  = width;
            rectangle.Height = height;

            if (tileShapeCollection.Visible)
            {
                rectangle.Visible = true;
            }

            tileShapeCollection.Rectangles.Add(rectangle);
        }
Ejemplo n.º 4
0
        public static void AddCollisionFrom(this TileShapeCollection tileShapeCollection, LayeredTileMap layeredTileMap,
                                            Func <List <TMXGlueLib.DataTypes.NamedValue>, bool> predicate)
        {
            var properties = layeredTileMap.TileProperties;

            foreach (var kvp in properties)
            {
                string name        = kvp.Key;
                var    namedValues = kvp.Value;

                if (predicate(namedValues))
                {
                    float dimension     = layeredTileMap.WidthPerTile.Value;
                    float dimensionHalf = dimension / 2.0f;
                    tileShapeCollection.GridSize = dimension;

                    foreach (var layer in layeredTileMap.MapLayers)
                    {
                        var dictionary = layer.NamedTileOrderedIndexes;

                        if (dictionary.ContainsKey(name))
                        {
                            var indexList = dictionary[name];

                            foreach (var index in indexList)
                            {
                                float left;
                                float bottom;
                                layer.GetBottomLeftWorldCoordinateForOrderedTile(index, out left, out bottom);

                                var centerX = left + dimensionHalf;
                                var centerY = bottom + dimensionHalf;
                                tileShapeCollection.AddCollisionAtWorld(centerX,
                                                                        centerY);
                            }
                        }
                    }
                }
            }
        }
        // This was not originally public but made public for situations where users want to
        // manually specify which tiles to use rather than relying on the HasCollision methods.
        public static void AddCollisionFrom(this TileShapeCollection tileShapeCollection,
                                            LayeredTileMap layeredTileMap, IEnumerable <string> namesToUse)
        {
            // prob need to clear out the tileShapeCollection

            float dimension     = float.NaN;
            float dimensionHalf = 0;

            foreach (var layer in layeredTileMap.MapLayers)
            {
                var dictionary = layer.NamedTileOrderedIndexes;

                foreach (var name in namesToUse)
                {
                    if (dictionary.ContainsKey(name))
                    {
                        var indexList = dictionary[name];

                        foreach (var index in indexList)
                        {
                            float left;
                            float bottom;
                            layer.GetBottomLeftWorldCoordinateForOrderedTile(index, out left, out bottom);

                            if (float.IsNaN(dimension))
                            {
                                dimension     = layer.Vertices[(index * 4) + 1].Position.X - left;
                                dimensionHalf = dimension / 2.0f;
                                tileShapeCollection.GridSize = dimension;
                            }

                            tileShapeCollection.AddCollisionAtWorld(left + dimensionHalf,
                                                                    bottom + dimensionHalf);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
		void CustomInitialize()
		{

            FlatRedBallServices.Game.IsMouseVisible = true;

            Camera.Main.OrthogonalHeight /= 2.0f;
            Camera.Main.FixAspectRatioYConstant();

            FlatRedBallServices.GraphicsOptions.TextureFilter = Microsoft.Xna.Framework.Graphics.TextureFilter.Point;

            Visuals.Shift(new Vector3(0, 400, 0));




            mTileSolidCollision = new TileShapeCollection();
            mTileSolidCollision.GridSize = 16;
            mTileSolidCollision.Visible = true;

            foreach (var sprite in Visuals.Sprites)
            {
                if (sprite.Name == "CollisionTile")
                {
                    mTileSolidCollision.AddCollisionAtWorld(sprite.X, sprite.Y);
                }
            }





            PlayerCharacterInstance.X = 32;
            PlayerCharacterInstance.Y = 80;

            Camera.Main.OrthogonalHeight *= 1;
            Camera.Main.FixAspectRatioYConstant();
            Camera.Main.Y = 100;
		}
        static void AddCollisionFrom(this TileShapeCollection tileShapeCollection,
                                     Scene scene, IEnumerable <string> namesToUse)
        {
            // prob need to clear out the tileShapeCollection

            float dimension     = float.NaN;
            float dimensionHalf = 0;

            for (int i = 0; i < scene.Sprites.Count; i++)
            {
                if (namesToUse.Contains(scene.Sprites[i].Name))
                {
                    if (float.IsNaN(dimension))
                    {
                        dimension     = scene.Sprites[i].Width;
                        dimensionHalf = dimension / 2.0f;
                        tileShapeCollection.GridSize = dimension;
                    }

                    tileShapeCollection.AddCollisionAtWorld(scene.Sprites[i].X, scene.Sprites[i].Y);
                }
            }
        }
Ejemplo n.º 8
0
 public static void AddMergedCollisionFromTilesWithType(this TileShapeCollection tileShapeCollection, LayeredTileMap layeredTileMap, string type)
 {
     tileShapeCollection.AddMergedCollisionFrom(
         layeredTileMap, (list) => list.Any(item => item.Name == "Type" && (item.Value as string) == type));
 }
Ejemplo n.º 9
0
 public static void AddMergedCollisionFromTilesWithProperty(this TileShapeCollection tileShapeCollection, LayeredTileMap layeredTileMap, string propertyName)
 {
     tileShapeCollection.AddMergedCollisionFrom(
         layeredTileMap, (list) => list.Any(item => item.Name == propertyName));
 }
Ejemplo n.º 10
0
        void OnEnemyVsFirePitCollisionCollisionOccurred (Entities.Enemy enemy, FlatRedBall.TileCollisions.TileShapeCollection second) 
        {
            enemy.TakeNonLethalDamage(FirePitDps * TimeManager.SecondDifference);

        }
Ejemplo n.º 11
0
 void OnPlayerVsFirePitCollisionCollisionOccurred (Entities.Player player, FlatRedBall.TileCollisions.TileShapeCollection second) 
 {
     player.TakeDamage(FirePitDps * TimeManager.SecondDifference, true);
 }