Exemplo n.º 1
0
        private void setupMap()
        {
            var sysManager = Core.getGlobalManager <SystemManager>();
            var mapId      = sysManager.MapId;

            _tiledMap = content.Load <TiledMap>($"maps/map{mapId}");
            sysManager.setTiledMapComponent(_tiledMap);

            var tiledEntity    = createEntity("tiledMap");
            var collisionLayer = _tiledMap.properties["collisionLayer"];
            var defaultLayers  = _tiledMap.properties["defaultLayers"].Split(',').Select(s => s.Trim()).ToArray();

            _tiledMapComponent = tiledEntity.addComponent(new TiledMapComponent(_tiledMap, collisionLayer)
            {
                renderLayer = TILED_MAP_RENDER_LAYER
            });
            _tiledMapComponent.setLayersToRender(defaultLayers);

            if (_tiledMap.properties.ContainsKey("aboveWaterLayer"))
            {
                var aboveWaterLayer = _tiledMap.properties["aboveWaterLayer"];
                var tiledAboveWater = tiledEntity.addComponent(new TiledMapComponent(_tiledMap)
                {
                    renderLayer = WATER_RENDER_LAYER
                });
                tiledAboveWater.setLayerToRender(aboveWaterLayer);
            }

            Core.getGlobalManager <SystemManager>().setTiledMapComponent(_tiledMap);
        }
Exemplo n.º 2
0
        private void addTiledMapComponent( )
        {
            var spriteSheet = scene.content.Load <Texture2D>("images/blocks");
            var tileset     = _tileMap.createTileset(spriteSheet, 0, TILESIZE, TILESIZE, true, 0, 0, TILE_COUNT, TILESET_COLUMNS);

            // Nez' tiledmap implementation will only take 1d arrays,
            // so we have to do this if we want to use the more intuitive
            // 2d array, unfortunatly.
            var _tilesTEMP = new TiledTile[WIDTH * HEIGHT];

            for (int x = 0; x < _tiles.GetLength(0); x++)
            {
                for (int y = 0; y < _tiles.GetLength(1); y++)
                {
                    _tiles[x, y]              = new TiledTile(0);
                    _tiles[x, y].tileset      = tileset;
                    _tilesTEMP[WIDTH * y + x] = _tiles[x, y];
                }
            }

            var layer     = _tileMap.createTileLayer("Default", WIDTH, HEIGHT, _tilesTEMP);
            var component = new TiledMapComponent(_tileMap);

            addComponent(component);
        }
 public override void onAddedToEntity()
 {
     _circleCollider = entity.getComponent <CircleCollider>();
     _mover          = entity.getComponent <Mover>();
     _physicsHandler = entity.getComponent <PhysicsHandler>();
     _mapComponent   = entity.scene.findEntity("tiled-map").getComponent <TiledMapComponent>();
 }
Exemplo n.º 4
0
Arquivo: Scenes.cs Projeto: Pyxlre/Nez
        public static Scene sceneOneBloom()
        {
            var scene = new Scene();
            var bloomLayerRenderer = scene.addRenderer(new RenderLayerRenderer(-1, 1));

            bloomLayerRenderer.renderTarget           = RenderTarget.create(256, 144);
            bloomLayerRenderer.renderTargetClearColor = Color.Transparent;

            scene.addRenderer(new RenderLayerExcludeRenderer(0, 1));
            scene.letterboxColor = Color.MonoGameOrange;
            scene.setDesignResolution(256, 144, Scene.SceneResolutionPolicy.ShowAllPixelPerfect);

            // load a TiledMap and move it back so is drawn before other entities
            var tiledEntity = scene.createEntity("tiled-map-entity");
            var tiledmap    = scene.contentManager.Load <TiledMap>("bin/MacOSX/Tilemap/tilemap");

            var tc1 = new TiledMapComponent(tiledmap, "collision");

            tc1.layerIndicesToRender = new int[] { 0, 1, 2 };
            tiledEntity.addComponent(tc1);


            var tc2 = new TiledMapComponent(tiledmap);

            tiledEntity.addComponent(tc2);
            tc2.renderLayer          = 1;
            tc2.layerIndicesToRender = new int[] { 3 };


            scene.addPostProcessor(new PixelBloomPostProcessor(bloomLayerRenderer.renderTarget, -1));

            return(scene);
        }
Exemplo n.º 5
0
 public override void onAddedToEntity()
 {
     _sprite            = this.getComponent <Sprite>();
     _tiledMapComponent = entity.scene.findEntity("tiled-map").getComponent <TiledMapComponent>();
     _mover             = new Mover();
     entity.addComponent(_mover);
 }
Exemplo n.º 6
0
 private void addAnimation()
 {
     _tiledMapComponent = entity
                          .scene.findEntity("tiled-map")
                          .getComponent <TiledMapComponent>();
     Mover = this.getComponent <TiledMapMover>();
     // _mover = this.getComponent<Mover>();
 }
Exemplo n.º 7
0
 // Scene has loaded, send data so we know how far a player gets
 void Start()
 {
     mapComponent = GetComponent<TiledMapComponent>();
     if(mapComponent) {
         TrackingScript.instance.AddProperty("scene", mapComponent.MapTMX.name);
         TrackingScript.instance.Track("scene loaded");
     }
 }
Exemplo n.º 8
0
        public override void onStart()
        {
            base.onStart();

            Entity            tileMapEntity = createEntity("tileMapEntity");
            TiledMapComponent comp          = tileMapEntity.addComponent(new TiledMapComponent(testmap));

            tileMapEntity.position = new Vector2(100, 100);
        }
        void OnEnable()
        {
            _renderer = GetComponent <Renderer>();
            // Try to get TiledMap from TiledMapComponent

            _tiledMapComponent = GameObject.FindObjectOfType <TiledMapComponent>();
            if (_tiledMapComponent != null)
            {
                _tiledMap = _tiledMapComponent.TiledMap;
            }
        }
		void OnEnable()
		{
			_renderer = GetComponent<Renderer>();
			// Try to get TiledMap from TiledMapComponent
			
			_tiledMapComponent = GameObject.FindObjectOfType<TiledMapComponent>();
			if (_tiledMapComponent != null)
			{
				_tiledMap = _tiledMapComponent.TiledMap;
			}
		}
Exemplo n.º 11
0
        public static Entity Map(TiledMap Map)
        {
            TiledMapComponent M = new TiledMapComponent(Map, "collisions");

            M.layerDepth = 1;

            Entity E = Create(new Vector2(-4), M);

            E.name = "map";

            return(E);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Carga un mapa de Tiled
        /// </summary>
        private void LoadMap()
        {
            mapEntity = createEntity(EntityType.TileMap.ToString());
            tiledMap  = content.Load <TiledMap>(Content.Map.level1);
            mapLayer  = mapEntity.addComponent(new TiledMapComponent(tiledMap, "Map"));

            // Camera bounds
            var topLeft     = new Vector2(tiledMap.tileWidth, tiledMap.tileWidth);
            var bottomRight = new Vector2(tiledMap.tileWidth * (tiledMap.width - 1), tiledMap.tileWidth * (tiledMap.height - 1));

            mapEntity.addComponent(new CameraBounds(topLeft, bottomRight));
            mapEntity.tag = (int)TagType.TileMap;
            //mapLayer.renderLayer = 4;
        }
Exemplo n.º 13
0
        public override void initialize()
        {
            clearColor = Color.PowderBlue;
            addRenderer(new DefaultRenderer());

            Entity tiledEntity = createEntity("tiled-map");

            TiledMap    map   = content.Load <TiledMap>("Temp/Temp");
            TiledObject spawn = map.getObjectGroup("Entrances").objectWithName("Spawn");

            TiledMapComponent mapComponent = new TiledMapComponent(map);

            tiledEntity.addComponent <TiledMapComponent>(mapComponent);
        }
Exemplo n.º 14
0
        private void CustomizeTiles(TiledMapComponent mapComponent)
        {
            var tileSize = new Vector2(mapComponent.tiledMap.tileWidth, mapComponent.tiledMap.tileHeight);

            for (float x = 0; x < mapComponent.width; x += tileSize.X)
            {
                for (float y = 0; y < mapComponent.height; y += tileSize.X)
                {
                    var tilePos = new Vector2(x, y);
                    var tile    = mapComponent.getTileAtWorldPosition(tilePos);
                    CustomizeTile(tile, tilePos, tileSize);
                }
            }
        }
Exemplo n.º 15
0
    void Start()
    {
        map = FindObjectOfType <TiledMapComponent>();

        numberShoots = PlayerPrefs.GetInt("PlayerShoots", numberShoots);
        numberLife   = PlayerPrefs.GetInt("PlayerLife", numberLife);
        // Locate the spawnPoint
        RespawnPoint[] objs = FindObjectsOfType <RespawnPoint>();
        foreach (RespawnPoint r in objs)
        {
            if (r.spawnPointName.Equals(PlayerPrefs.GetString("PlayerRespawn", "Start")))
            {
                transform.position = r.transform.position;
            }
        }
    }
Exemplo n.º 16
0
        public void OnCollisionHitboxLoaded(TiledMapComponent onComponent, Transform2 componentTrans, TmxObject hitbox, float localX, float localY)
        {
            if (hitbox.ObjectType != TmxObjectType.Basic)
            {
                Log.Info("Can only load basic objects (not " + hitbox.ObjectType + ") into physics!" + (++counter));
                return;
            }

            Actor      hitboxActor = stage.CreateActor(onComponent.Actor.Layer + 1);
            Transform2 trans       = hitboxActor.AddComponent <ScaledTransform2>();

            trans.LocalPosition = new Vector2(localX + (float)hitbox.X, localY + (float)hitbox.Y);
            Rigidbody body = hitboxActor.AddComponent <Rigidbody>();

            body.Set(width: (float)hitbox.Width, height: (float)hitbox.Height, isStatic: true, isSquare: true, isTrigger: false);
            trans.Parent = componentTrans;
        }
Exemplo n.º 17
0
        protected void createTileMap(string mapName)
        {
            Entity            tiledEntity       = createEntity("tiled-map-entity");
            TiledMap          tiledMap          = this.content.Load <TiledMap>("Maps/" + mapName);
            TiledMapComponent tiledMapComponent = tiledEntity.addComponent(new TiledMapComponent(tiledMap, "Collisions"));

            tiledMapComponent.setLayersToRender(new string[] { "Ground", "Walls", "Details" });
            tiledMapComponent.renderLayer = 10;

            TiledMapComponent tiledMapDetailsComp = tiledEntity.addComponent(new TiledMapComponent(tiledMap));

            tiledMapDetailsComp.setLayerToRender("Above-Details");
            tiledMapDetailsComp.renderLayer = -1;

            List <TiledObjectGroup> tiledObjects = tiledMap.objectGroups;

            tiledEntity      = TransitionManager.attachTransitionColliders(tiledObjects, tiledEntity, mapName);
            this.PlayerSpawn = TransitionManager.findPlayerSpawn(tiledObjects, PrevMapName);

            tiledMapDetailsComp.material        = Material.stencilWrite();
            tiledMapDetailsComp.material.effect = this.content.loadNezEffect <SpriteAlphaTestEffect>();
        }
        private void setupMap()
        {
            _tiledMap = content.Load <TiledMap>("maps/map");

            var tiledEntity    = createEntity("tiled-map");
            var collisionLayer = _tiledMap.properties["collisionLayer"];
            var defaultLayers  = _tiledMap.properties["defaultLayers"].Split(',').Select(s => s.Trim()).ToArray();

            _tiledMapComponent = tiledEntity.addComponent(new TiledMapComponent(_tiledMap, collisionLayer)
            {
                renderLayer = GlobalConstants.TILED_MAP_RENDER_LAYER
            });
            _tiledMapComponent.setLayersToRender(defaultLayers);

            if (_tiledMap.properties.ContainsKey("aboveWaterLayer"))
            {
                var aboveWaterLayer = _tiledMap.properties["aboveWaterLayer"];
                var tiledAboveWater = tiledEntity.addComponent(new TiledMapComponent(_tiledMap)
                {
                    renderLayer = GlobalConstants.WATER_RENDER_LAYER
                });
                tiledAboveWater.setLayerToRender(aboveWaterLayer);
            }
        }
Exemplo n.º 19
0
        private void setupMap()
        {
            var background = createEntity("map-background");
            var texture    = content.Load <Texture2D>(Content.Maps.background);

            _backgroundSprite = background.addComponent(new Sprite(texture)
            {
                renderLayer = BACKGROUND_RENDER_LAYER
            });
            background.position = (virtualSize.ToVector2() / 2);

            var sysManager = Core.getGlobalManager <SystemManager>();

            _tiledMap = content.Load <TiledMap>("maps/map");
            sysManager.setTiledMapComponent(_tiledMap);

            var tiledEntity    = createEntity("tiled-map");
            var collisionLayer = _tiledMap.properties["collisionLayer"];
            var defaultLayers  = _tiledMap.properties["defaultLayers"].Split(',').Select(s => s.Trim()).ToArray();

            _tiledMapComponent = tiledEntity.addComponent(new TiledMapComponent(_tiledMap, collisionLayer)
            {
                renderLayer = TILED_MAP_RENDER_LAYER
            });
            _tiledMapComponent.setLayersToRender(defaultLayers);

            if (_tiledMap.properties.ContainsKey("aboveWaterLayer"))
            {
                var aboveWaterLayer = _tiledMap.properties["aboveWaterLayer"];
                var tiledAboveWater = tiledEntity.addComponent(new TiledMapComponent(_tiledMap)
                {
                    renderLayer = WATER_RENDER_LAYER
                });
                tiledAboveWater.setLayerToRender(aboveWaterLayer);
            }
        }
Exemplo n.º 20
0
 void Start()
 {
     TMComponent = GetComponent<TiledMapComponent>();
     TMComponent.OnMapComplet = OnMapLoaded;
 }
Exemplo n.º 21
0
        public override void initialize()
        {
            Debug.log("Scene initialized");

            clearColor = Color.CornflowerBlue;
            addRenderer(new DefaultRenderer());


            Entity           tiledEntity      = createEntity("tiled-map");
            PlayerController playerController = new PlayerController();
            Sprite           playerSprite     = new Sprite(content.Load <Texture2D>("Temp/TestPlayerAnimationFiles/Idle/Idle_1"));

            playerSprite.setRenderLayer(1);

            //Load map here************************************************************
            TiledMap          map          = content.Load <TiledMap>("Temp/TestingWorld");
            TiledObject       spawn        = map.getObjectGroup("SpawnPoint").objectWithName("Spawn");
            TiledMapComponent mapComponent = new TiledMapComponent(map, "Ground");

            mapComponent.setRenderLayer(2);
            tiledEntity.addComponent(mapComponent);

            #region SpawnPlayer
            //Create player Entity
            CookieCutterEntity player = new CookieCutterEntity("Player", spawn.position, ref playerSprite, playerController);

            //Add camera to player
            FollowCamera camera = new FollowCamera(player);
            camera.mapLockEnabled = true;
            camera.mapSize        = new Vector2(map.width * map.tileWidth, map.height * map.tileHeight);
            player.addComponent <FollowCamera>(camera);

            //Add collision layers here*******************************************************************
            BoxCollider collider = new BoxCollider(-playerSprite.width / 2, -playerSprite.height / 2, playerSprite.width, playerSprite.height);
            player.addComponent <TiledMapMover>(new TiledMapMover(map.getLayer <TiledTileLayer>("Ground")));
            player.addComponent <BoxCollider>(collider);
            player.addComponent <PhysicsHandler>(new PhysicsHandler(player, playerController.collisionState, 20f, .5f));
            Flags.setFlagExclusive(ref collider.collidesWithLayers, 0); //Prevent collisions with projectiles
            Flags.setFlagExclusive(ref collider.physicsLayer, 1);

            this.addEntity <Entity> (player);
            #endregion

            #region SpawnAI
            //Initialize EnemyController
            EnemyMeleeController enemy = new EnemyMeleeController(map.getLayer <TiledTileLayer>("Ground"));
            Sprite enemySprite         = new Sprite(content.Load <Texture2D>("Temp/TestPlayerAnimationFiles/Idle/Idle_1"));
            enemySprite.setRenderLayer(1);
            TiledObject        enemySpawn  = map.getObjectGroup("SpawnPoint").objectWithName("EnemySpawn");
            CookieCutterEntity enemyEntity = new CookieCutterEntity("Enemy", enemySpawn.position, ref enemySprite, enemy);

            //Add collision layers
            BoxCollider enemyCollider = new BoxCollider(-enemySprite.width / 2, -enemySprite.height / 2, enemySprite.width, enemySprite.height);
            enemy.addComponent <TiledMapMover>(new TiledMapMover(map.getLayer <TiledTileLayer>("Ground")));
            enemy.addComponent <BoxCollider>(enemyCollider);
            enemy.addComponent <PhysicsHandler>(new PhysicsHandler(enemyEntity, enemy.collisionState, 20f, .5f));
            Flags.setFlagExclusive(ref enemyCollider.collidesWithLayers, 0); //Prevent collisions with projectiles
            Flags.setFlagExclusive(ref enemyCollider.physicsLayer, 1);

            //Add target
            enemy.target = player;

            this.addEntity <Entity>(enemyEntity);
            #endregion
        }
        protected bool InitPath()
        {
            // If the path isn't currently set, then set it
            // The path will be set & unset many times over the course of a single chase
            if (Path == null)
            {
                // If the collisions layer hasn't been set yet, set it
                // We need that to find paths around
                if (Layer == null)
                {
                    // First, get the main map
                    Entity Map = Core.scene.findEntity("map");

                    // If the map doesn't exist, there's nothing to find paths around
                    // Just quit, this should never happen
                    if (Map == null)
                    {
                        return(false);
                    }

                    // Get the map data
                    // We use Tiled in this game
                    TiledMapComponent MapData = Map.getComponent <TiledMapComponent>();

                    // If there is no map data, then there's no use
                    // Just quit, this should never happen
                    if (MapData == null)
                    {
                        return(false);
                    }

                    // Set the collision layer
                    Layer = MapData.collisionLayer;

                    // If the collision layer is null, there's no use
                    // Just quit, this should never happen
                    if (Layer == null)
                    {
                        return(false);
                    }
                }

                // If the graph hasn't been set, set it
                // The graph is the object that sets the path
                if (graph == null)
                {
                    graph = new WeightedGridGraph(Layer);

                    // If graph didn't properly set, there's no use
                    // Just quit, this should never happen
                    if (graph == null)
                    {
                        return(false);
                    }
                }

                // Set the path
                SetPath();

                // If the path is somehow still null, it's no use
                // Just quit, this should never happen
                if (Path == null)
                {
                    return(false);
                }

                // If the path is more-or-less empty, make it null, then quit
                // (The first node is usually useless)
                // This should never happen
                if (Path.Count < 1)
                {
                    ChosenPatrolStalkPoint = null;

                    Player = null;

                    Path = null;

                    return(false);
                }

                // Set the place on the map we want to go to
                // We make it a Vector2 as opposed to a Point. It's easier for us to use it that way
                // We also multiply it by the map's tilesize, as the Point it gives us is coordinates
                NextPoint = new Vector2((Path[1].X * 8) + 4, (Path[1].Y * 8) - 4);
            }

            return(true);
        }
Exemplo n.º 23
0
        public override void initialize()
        {
            base.initialize();
            this.addRenderer(new DefaultRenderer());
            SetupPostProcess();

            //var deferredRenderer = addRenderer(new DeferredLightingRenderer(
            //    0, 1, 10, 20));
            //deferredRenderer.setAmbientColor(new Color(10, 10, 10));

            _enemiesContainer = addEntity(new ContainerEntity
            {
                name = "container-enemies"
            });
            EnemyEntity.Container = _enemiesContainer;
            _bulletContainer      = addEntity(new ContainerEntity
            {
                name = "container-bullet"
            });
            BulletEntity.Container = _bulletContainer;
            _itemsContainer        = addEntity(new ContainerEntity()
            {
                name = "container-items"
            });

            _currentMap     = content.Load <TiledMap>(Content.Tilemaps.map1);
            _mapBoundsGroup = _currentMap.getObjectGroup("MapBounds");
            var startPos = _currentMap.getObjectGroup("Points").objectWithName("StartPos");

            _mapEnemies = _currentMap.getObjectGroup("Enemies");
            _mapItems   = _currentMap.getObjectGroup("Upgrades");
            Texture2D freePlayerTexture = content.Load <Texture2D>(Content.Textures.tempFlightSprite);

            Entity            map      = createEntity("map");
            TiledMapComponent tiledMap = map.addComponent(new TiledMapComponent(_currentMap, "Level"));

            // Vector2 halfMapDimensions = new Vector2(tiledMap.width, tiledMap.height) / 2.0f;
            // map.setPosition(-halfMapDimensions);
            tiledMap.setRenderLayer(10);
            var flyingPlayer = new FreemovePlayerEntity(freePlayerTexture)
            {
                name = "player-flying"
            };

            flyingPlayer.addComponent <PositionBoundsLimitComponent>();
            this.addEntity(flyingPlayer);
            EnemyEntity.Player = flyingPlayer;

            var platformPlayer = new PlatformPlayerEntity(freePlayerTexture)
            {
                name = "player-platform"
            };

            platformPlayer.transform.position = new Vector2(startPos.x, startPos.y);
            this.addEntity(platformPlayer);

            CameraFollowComponent cameraFollow = new CameraFollowComponent(platformPlayer.transform);

            camera.addComponent(cameraFollow);

            PlayerManagerComponent p = addSceneComponent <PlayerManagerComponent>();

            p.PlatformPlayer       = platformPlayer.getComponent <PlatformPlayerComponent>();
            p.FreemovePlayer       = flyingPlayer.getComponent <FreemovePlayerComponent>();
            p.CameraFollow         = cameraFollow;
            p.OnTogglePlatforming += OnPlatformToggle;
            p.TogglePlatforming();
            //var scanLines = content.loadEffect(@"nez\effects\Invert.mgfxo");

            _bulletTextures     = new Texture2D[1];
            _enemyTextures      = new Texture2D[1];
            _upgradeTextures    = new Texture2D[1];
            _bulletTextures[0]  = content.Load <Texture2D>(Content.Textures.Enemies.bullet);
            _enemyTextures[0]   = content.Load <Texture2D>(Content.Textures.Enemies.enemy1);
            _upgradeTextures[0] = content.Load <Texture2D>(Content.Textures.tempFlightSprite);
            //// EnemyEntity e = new EnemyEntity(enemyTexture, bullet);
            //e.getComponent<EnemyComponent>().Player = flyingPlayer;
            //addEntity(e);

            addEntityProcessor(new UpgradeTriggerProcessor(new Matcher().all(typeof(UpgradeComponent))));

            CreateUi();
            Time.timeScale = 0.0f;
            Core.startCoroutine(WaitToStart(0.5f));

            ChangeCameraPos();
        }
Exemplo n.º 24
0
        public void Draw(TiledMapComponent map, float layerDepth, MeshBatch batch, Matrix transformMatrix)
        {
            if (map.TiledMap.Orientation != TiledMapOrientation.Orthogonal)
            {
                throw new NotImplementedException();
            }

            for (var i = 0; i < map.TiledMap.Layers.Count; i++)
            {
                if (!map.TiledMap.Layers[i].Visible ||
                    (map.LayerIndicesToRender != null && !map.LayerIndicesToRender.Contains(i)))
                {
                    continue;
                }

                var layer = (TiledTileLayer)map.TiledMap.Layers[i];
                for (var y = 0; y < layer.Height; y++)
                {
                    for (var x = 0; x < layer.Width; x++)
                    {
                        var tile = layer.GetTile(x, y);
                        if (tile == null)
                        {
                            continue;
                        }

                        if (tile.TileSet == null || tile.TileSetTile == null || tile.OldId != tile.Id)
                        {
                            tile.OldId             = tile.Id;
                            tile.TileSet           = map.TiledMap.TileSets.First(a => a.Tiles.Any(b => b.Id + a.FirstGid == tile.Id));
                            tile.TileSetTile       = tile.TileSet.Tiles.First(b => b.Id + tile.TileSet.FirstGid == tile.Id);
                            tile.RenderTileSetTile = tile.TileSetTile;
                            tile.CurrentFrame      = 0;
                            tile.ElapsedTime       = 0;
                        }

                        // for the y position, we need to take into account if the tile is larger than the tileHeight and shift. Tiled uses
                        // a bottom-left coordinate system and MonoGame a top-left
                        var tx       = x * map.TiledMap.TileWidth;
                        var ty       = y * map.TiledMap.TileHeight;
                        var rotation = 0f;

                        var spriteEffects = SpriteEffects.None;
                        if (tile.FlippedHorizonally)
                        {
                            spriteEffects |= SpriteEffects.FlipHorizontally;
                        }
                        if (tile.FlippedVertically)
                        {
                            spriteEffects |= SpriteEffects.FlipVertically;
                        }
                        if (tile.FlippedDiagonally)
                        {
                            if (tile.FlippedHorizonally && tile.FlippedVertically)
                            {
                                spriteEffects ^= SpriteEffects.FlipVertically;
                                rotation       = MathHelper.PiOver2;
                                tx            += map.TiledMap.TileHeight + (tile.RenderTileSetTile.SourceRect.Height - map.TiledMap.TileHeight);
                                ty            -= (tile.RenderTileSetTile.SourceRect.Width - map.TiledMap.TileWidth);
                            }
                            else if (tile.FlippedHorizonally)
                            {
                                spriteEffects ^= SpriteEffects.FlipVertically;
                                rotation       = -MathHelper.PiOver2;
                                ty            += map.TiledMap.TileHeight;
                            }
                            else if (tile.FlippedVertically)
                            {
                                spriteEffects ^= SpriteEffects.FlipHorizontally;
                                rotation       = MathHelper.PiOver2;
                                tx            += map.TiledMap.TileWidth + (tile.RenderTileSetTile.SourceRect.Height - map.TiledMap.TileHeight);
                                ty            += (map.TiledMap.TileWidth - tile.RenderTileSetTile.SourceRect.Width);
                            }
                            else
                            {
                                spriteEffects ^= SpriteEffects.FlipHorizontally;
                                rotation       = -MathHelper.PiOver2;
                                ty            += map.TiledMap.TileHeight;
                            }
                        }

                        // if we had no rotations (diagonal flipping) shift our y-coord to account for any non-tileSized tiles to account for
                        // Tiled being bottom-left origin
                        if (rotation == 0)
                        {
                            ty += map.TiledMap.TileHeight - tile.RenderTileSetTile.SourceRect.Height;
                        }

                        var destRect = tile.RenderTileSetTile.SourceRect;
                        destRect.Location = new Point(0, 0);

                        var meshItem = batch.Draw(tile.TileSet.ImageTexture, destRect, tile.RenderTileSetTile.SourceRect, Color.White, layerDepth);
                        meshItem.RotateMesh(rotation);
                        meshItem.ApplyEffectToMesh(spriteEffects);
                        meshItem.MoveMesh(new Vector3(tx + layer.Offset.X, ty + layer.Offset.Y, 0));
                        meshItem.ApplyTransformMesh(transformMatrix);
                    }
                }
            }
        }
Exemplo n.º 25
0
 public override void onEnabled()
 {
     base.onEnabled();
     _map = scene.findComponentOfType <TiledMapComponent>();
 }