コード例 #1
0
        private static Player MakeWorldAndPlayer(params Rectangle[] immovables)
        {
            var world       = new World();
            var map         = new TiledMap("TestMap", Room.NumTilesWidth, Room.NumTilesHeight, Room.TileWidth, Room.TileHeight, TiledMapTileDrawOrder.RightDown, TiledMapOrientation.Orthogonal);
            var bottomLayer = new TiledMapTileLayer(Dungeon.BottomLayerName, Room.NumTilesWidth, Room.NumTilesHeight, Room.TileWidth, Room.TileHeight);

            for (int y = 0; y < bottomLayer.Height; ++y)
            {
                for (int x = 0; x < bottomLayer.Width; ++x)
                {
                    bottomLayer.SetTile((ushort)x, (ushort)y, 1);
                }
            }
            map.AddLayer(bottomLayer);
            var collidables = new TiledMapRectangleObject[immovables.Length];
            int i           = 0;

            foreach (Rectangle immovable in immovables)
            {
                // Note: Object IDs for Tiled maps start at 1, not 0.
                collidables[i] = new TiledMapRectangleObject(i + 1, "collidable" + (i + 1), new Size2(immovable.Width, immovable.Height), new Vector2(immovable.X, immovable.Y));
                ++i;
            }
            var collisionLayer = new TiledMapObjectLayer(Dungeon.CollisionLayerName, collidables);

            map.AddLayer(collisionLayer);
            var dungeon = new Dungeon(world, map, null);

            world.Dungeons.Add(dungeon);
            var player = new Player(dungeon, new Point(Room.Width / 2, Room.Height / 2), Direction.Down);

            world.Player = player;
            return(player);
        }
コード例 #2
0
ファイル: Map.cs プロジェクト: CarimA/jrpg
        public void LoadBoundaryData()
        {
            foreach (var objectLayer in MapData.ObjectLayers)
            {
                foreach (var obj in objectLayer.Objects)
                {
                    if (objectLayer.Name.Contains("collision") && obj is TiledMapRectangleObject)
                    {
                        if (obj is TiledMapPolygonObject)
                        {
                            Point2[] points = (obj as TiledMapPolygonObject).Points;

                            List <Vector2> newPoints = points.Select(point => new Vector2(point.X, point.Y)).ToList();
                            World.Insert(new Polygon(obj.Position, newPoints));
                        }
                        else if (obj is TiledMapRectangleObject)
                        {
                            TiledMapRectangleObject rect = obj as TiledMapRectangleObject;
                            Polygon p = ShapePrimitives.Rectangle(obj.Position, (obj as TiledMapRectangleObject).Size.Width, (obj as TiledMapRectangleObject).Size.Height);
                            World.Insert(p);
                        }
                        else
                        {
                            throw new Exception("uhh something's missing :>");
                        }
                    }

                    if (objectLayer.Name.Contains("scripts") && obj is TiledMapRectangleObject)
                    {
                        Vector2 pos  = (obj as TiledMapRectangleObject).Position;
                        Size2   size = (obj as TiledMapRectangleObject).Size;

                        Rectangle rect = new Rectangle(
                            (int)(pos.X / MapData.TileWidth),
                            (int)(pos.Y / MapData.TileHeight),
                            (int)(size.Width / MapData.TileWidth),
                            (int)(size.Height / MapData.TileHeight));

                        for (int x = rect.Left; x < rect.Right; x++)
                        {
                            for (int y = rect.Top; y < rect.Bottom; y++)
                            {
                                InteractScripts.Add(new MapObject <ScriptData>()
                                {
                                    X    = x,
                                    Y    = y,
                                    Data = new ScriptData()
                                    {
                                        Script = obj.Name
                                    }
                                });
                            }
                        }
                    }

                    // todo: handle scripts, warps, etc etc
                }
            }
        }
コード例 #3
0
ファイル: TileMap.cs プロジェクト: helluvamatt/MazeGame
        private bool RectangleHitTest(Point location, TiledMapRectangleObject obj)
        {
            var shape = new Rectangle(obj.Position.ToPoint(), new Point((int)obj.Size.Width, (int)obj.Size.Height));

            return(!shape.Contains(location));
        }