Ejemplo n.º 1
0
        public void load(TmxMap map, bool createObjects)
        {
            this.map = map;
            // structural recreation
            structure    = map.GetLayer <TmxLayer>(LAYER_STRUCTURE);
            features     = map.GetLayer <TmxLayer>(LAYER_FEATURES);
            nature       = map.GetObjectGroup(LAYER_NATURE);
            worldTileset = map.Tilesets[TILESET_WORLD];
            if (NGame.context.config.enableWalls)
            {
                createWallColliders();                                   // comment out to disable wall collision
            }
            // analysis
            mapRepr        = new MapRepr();
            mapRepr.tmxMap = map;
            analyzeRooms();
            mapRepr.sng = createStructuralNavigationGraph(mapRepr.roomGraph);

            // load entities
            loadFeatures();
            if (createObjects)
            {
                loadNature();
            }

            Global.log.info("loaded data from map");
        }
Ejemplo n.º 2
0
        private void SetupCustomCollision()
        {
            TmxLayer CustomCollisionLayer = (TmxLayer)TileMap.GetLayer("CustomCollision");

            foreach (TmxLayerTile tile in CustomCollisionLayer.Tiles)
            {
                if (tile != null && tile.TilesetTile != null)
                {
                    TmxList <TmxObjectGroup> objgl = tile.TilesetTile.ObjectGroups;

                    if (objgl != null && objgl.Count > 0)
                    {
                        TmxObjectGroup objg = objgl[0];
                        if (objg.Objects != null && objg.Objects.Count > 0)
                        {
                            TmxObject     obj  = objg.Objects[0];
                            TmxObjectType type = obj.ObjectType;

                            if (type == TmxObjectType.Ellipse)
                            {
                                //Draw Ellipse as collision
                                Entity.Scene.CreateEntity(obj.Name, new Vector2(Entity.Position.X + tile.Position.X * tile.Tileset.TileWidth + obj.Width / 2, Entity.Position.Y + tile.Position.Y * tile.Tileset.TileHeight + obj.Height / 2))
                                .AddComponent(new FSCollisionEllipse(obj.Width / 2, obj.Height / 2))
                                .AddComponent(new CircleCollider((obj.Width + obj.Height) / 4));     // have to get an average of sides, hence / 4
                            }
                            else if (type == TmxObjectType.Polygon)
                            {
                                Vector2[] points = obj.Points;

                                Entity.Scene.CreateEntity(obj.Name, new Vector2(Entity.Position.X + tile.Tileset.TileWidth * tile.Position.X + obj.X, Entity.Position.Y + tile.Tileset.TileHeight * tile.Position.Y + obj.Y))
                                .AddComponent(new FSCollisionPolygon(points))
                                .AddComponent(new PolygonCollider(points));
                            }
                            //basic is rectangle
                            else if (type == TmxObjectType.Basic)
                            {
                                Entity.Scene.CreateEntity(obj.Name, new Vector2(Entity.Position.X + tile.Position.X * tile.Tileset.TileWidth + obj.Width / 2, Entity.Position.Y + tile.Position.Y * tile.Tileset.TileHeight + obj.Height / 2))
                                .AddComponent(new FSCollisionBox(obj.Width, obj.Height))
                                .AddComponent(new BoxCollider(obj.Width, obj.Height));
                                Entity.AddComponent(new FSCollisionBox(obj.Width, obj.Height)).AddComponent(new BoxCollider(obj.Width, obj.Height));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void SetupTiles()
        {
            if (Core.Scene == null || enabled)
            {
                return;
            }
            //enabled = true;
            TmxMap map    = Core.Scene.Content.LoadTiledMap("Assets/map.tmx");
            Entity entity = Core.Scene.CreateEntity("tiled-map");

            TiledMapRenderer tmr = entity.AddComponent(new TiledMapRenderer(map, "Collision", true));
            TmxLayer         CustomCollisionLayer = (TmxLayer)map.GetLayer("CustomCollision");

            foreach (TmxLayerTile tile in CustomCollisionLayer.Tiles)
            {
                if (tile != null && tile.TilesetTile != null)
                {
                    TmxList <TmxObjectGroup> objgl = tile.TilesetTile.ObjectGroups;

                    if (objgl != null && objgl.Count > 0)
                    {
                        TmxObjectGroup objg = objgl[0];
                        if (objg.Objects != null && objg.Objects.Count > 0)
                        {
                            TmxObject     obj  = objg.Objects[0];
                            TmxObjectType type = obj.ObjectType;

                            if (type == TmxObjectType.Ellipse)
                            {
                                //Draw Ellipse as collision
                                Core.Scene.CreateEntity(obj.Name, new Vector2(tile.Position.X * tile.Tileset.TileWidth + obj.Width / 2, tile.Position.Y * tile.Tileset.TileHeight + obj.Height / 2))
                                .AddComponent(new FSCollisionEllipse(obj.Width / 2, obj.Height / 2))
                                .AddComponent(new CircleCollider((obj.Width + obj.Height) / 4));     // have to get an average of sides, hence / 4
                            }
                            else if (type == TmxObjectType.Polygon)
                            {
                                Vector2[] points = obj.Points;

                                Core.Scene.CreateEntity(obj.Name, new Vector2(tile.Tileset.TileWidth * tile.Position.X + obj.X, tile.Tileset.TileHeight * tile.Position.Y + obj.Y))
                                .AddComponent(new FSCollisionPolygon(points))
                                .AddComponent(new PolygonCollider(points));
                            }
                            //basic is rectangle
                            else if (type == TmxObjectType.Basic)
                            {
                                Core.Scene.CreateEntity(obj.Name, new Vector2(tile.Position.X * tile.Tileset.TileWidth + obj.Width / 2, tile.Position.Y * tile.Tileset.TileHeight + obj.Height / 2))
                                .AddComponent(new FSCollisionBox(obj.Width, obj.Height))
                                .AddComponent(new BoxCollider(obj.Width, obj.Height));
                            }
                        }
                    }
                }
            }
            tmr.SetLayersToRender(new string[] { });
        }
Ejemplo n.º 4
0
        public override void Initialize()
        {
            SetDesignResolution(360, 180, Scene.SceneResolutionPolicy.ShowAllPixelPerfect);
            Screen.SetSize(360 * ScalingFactor, 180 * ScalingFactor);
            AddRenderer(new DefaultRenderer());

            // load up our TiledMap
            map = Content.LoadTiledMap("Content/Tilemaps/testMap.tmx");
            var spawnObject = map.GetObjectGroup("objects").Objects["spawn"];

            var tiledEntity      = CreateEntity("tiled-map-entity");
            var tiledMapRenderer = tiledEntity.AddComponent(new TiledMapRenderer(map, "main"));

            tiledMapRenderer.SetRenderLayer(3);


            // set up the player/char controller
            var playerEntity = CreateEntity("player", new Vector2(30, 60));

            playerEntity.AddComponent(new PlayerController());
            playerEntity.AddComponent(new CameraShake());
            playerEntity.AddComponent(new BoxCollider(-8, -16, 16, 32));
            playerEntity.AddComponent(new TiledMapMover(map.GetLayer <TmxLayer>("main")));
            playerEntity.AddComponent(new TriggerListener());

            //set camera bounds (see Controllers/CameraBounds.cs)
            var topLeft     = new Vector2(map.TileWidth - 13, map.TileWidth - 13);
            var bottomRight = new Vector2(map.TileWidth * (map.Width + 3),
                                          map.TileWidth * (map.Height + 3));

            tiledEntity.AddComponent(new CameraBounds(topLeft, bottomRight));

            // add in spinny Nez logo background
            var Logo = AddEntity(new Entity("Logo Spinner"));

            Logo.AddComponent(new SpriteRenderer(Content.LoadTexture("Content/Textures/Nez.png")));
            Logo.SetPosition(Screen.Center / 2);
            Logo.AddComponent(new LogoRotationComponent());
            Logo.AddComponent(new LogoScalingComponent());
            Logo.GetComponent <SpriteRenderer>().RenderLayer = 5;

            Debug.DrawHollowRect(Camera.Bounds, Color.Green, 10000);

            // make it so camera follows player
            camera = Camera.Entity.AddComponent(new FollowCamera(playerEntity));
            Debug.DrawHollowRect(camera.Deadzone, Color.Red, 10000);

            var effect = Content.LoadEffect("Content/Shaders/HeatDistortionPoint.fxb");

            HeatDistortionPostProcessor = new HeatDistortionPointPostProcessor(0, effect);
            AddPostProcessor(HeatDistortionPostProcessor);
        }
Ejemplo n.º 5
0
        public Pathfinder(TmxMap tilemap)
        {
            _tilemap = tilemap;
            var layer = tilemap.GetLayer <TmxLayer>("main");

            _start = new Point(1, 1);
            _end   = new Point(10, 10);

            _gridGraph         = new UnweightedGridGraph(layer);
            _breadthSearchPath = _gridGraph.Search(_start, _end);

            _weightedGraph      = new WeightedGridGraph(layer);
            _weightedSearchPath = _weightedGraph.Search(_start, _end);

            _astarGraph      = new AstarGridGraph(layer);
            _astarSearchPath = _astarGraph.Search(_start, _end);

            Debug.DrawTextFromBottom = true;
        }
Ejemplo n.º 6
0
        public override void OnAddedToScene()
        {
            base.OnAddedToScene();

            tileMap = Core.Content.LoadTiledMap(System.IO.Path.Combine(
                                                    Core.Content.RootDirectory,
                                                    "Levels/TileMap1.tmx"));

            tileMapRenderer = AddComponent(new TiledMapRenderer(tileMap));

            tileMapRenderer.SetLayersToRender(new string[] { "Foreground", "Background" });

            tileMapRenderer.PhysicsLayer = (int)Physics.PhysicsLayer.Collidable;

            tileMapRenderer.CollisionLayer = tileMap.GetLayer <TmxLayer>("Collision");

            tileMapRenderer.AddColliders();

            tileMapRenderer.LayerDepth = 1;

            TmxObjectGroup objectsLayer = tileMap.GetObjectGroup("Objects");

            objectsLayer.Visible = false;

            foreach (TmxObject obj in objectsLayer.Objects)
            {
                switch (obj.Type)
                {
                case AvatarObjectType:
                    Avatar avatar = Scene.AddEntity(new Avatar(obj.Position() + TiledObjectOffset));
                    Scene.Camera.AddComponent(new FollowCamera(avatar, FollowCamera.CameraStyle.LockOn));
                    break;

                case SlimeObjectType:
                    Slime slime = Scene.AddEntity(
                        new Slime(
                            obj.Position() + TiledObjectOffset,
                            obj.FullName()));

                    break;
                }
            }
        }
Ejemplo n.º 7
0
        public void Load(string filePath)
        {
            TmxMap map   = Scene.Content.LoadTiledMap(filePath);
            var    layer = map.GetLayer <TmxLayer>(Constants.TiledLayerBuildings);

            Scene.AddEntity(new TiledMap(map));

            //foreach(TmxLayerTile t in layer.Tiles) {
            //    if(t == null)
            //        continue;
            //
            //    t.TilesetTile.Properties.TryGetValue(Constants.TiledPropertyID, out var value);
            //
            //    Building b;
            //    if(value == "Building") {
            //        b = Scene.AddEntity(new Building());
            //        b.Position = map.TileToWorldPosition(t.Position);
            //    }
            //}
        }
Ejemplo n.º 8
0
        public static List <Node> GenerateNodes(TmxMap map)
        {
            var layer = map.GetLayer <TmxLayer>(Constants.TiledLayerBackground);

            List <Node> nodes = new List <Node>();

            foreach (TmxLayerTile t in layer.Tiles)
            {
                if (t == null)
                {
                    continue;
                }

                t.TilesetTile.Properties.TryGetValue(Constants.TiledPropertyID, out var value);

                if (value == Constants.TiledIDIntersection)
                {
                    nodes.Add(new Node(map.TileToWorldPosition(t.Position) + new Vector2(Constants.TiledCellSize / 2), t.Position.ToPoint()));
                }
            }

            return(ConnectNodes(nodes, layer));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// sets this component to only render a single layer
 /// </summary>
 /// <param name="layerName">Layer name.</param>
 public void SetLayerToRender(string layerName)
 {
     LayerIndicesToRender    = new int[1];
     LayerIndicesToRender[0] = TiledMap.Layers.IndexOf(TiledMap.GetLayer(layerName));
 }