Inheritance: PropertyBag
        public override void MapLoaded(TeeEngine engine, TiledMap map, MapEventArgs mapEventArgs)
        {
            LightShader lightShader = (LightShader)engine.GetPostGameShader("LightShader");
            lightShader.Enabled = true;

            base.MapLoaded(engine, map, mapEventArgs);
        }
        public virtual void MapLoaded(TeeEngine engine, TiledMap map, MapEventArgs mapEventArgs)
        {
            if (mapEventArgs.HasProperty("Target"))
            {
                Hero player = new Hero();
                MapEntrance targetEntrance = (MapEntrance)engine.GetEntity(mapEventArgs.GetProperty("Target"));

                player.Pos = targetEntrance.Pos + new Vector2(targetEntrance.Width, targetEntrance.Height) / 2;

                engine.AddEntity("Player", player);
            }
        }
        void MapEntrance_MapZoneHit(MapZone sender, Entity entity, TeeEngine engine, GameTime gameTime)
        {
            if(KeyboardExtensions.GetKeyDownState(Keyboard.GetState(), ACTIVATE_KEY, engine, true) &&
               entity == engine.GetEntity("Player"))
            {
                MapEventArgs mapArgs = new MapEventArgs();
                mapArgs.SetProperty("Target", Target);

                engine.ClearEntities();
                engine.LoadMap(Destination, mapArgs);
            }
        }
        public override void MapLoaded(TeeEngine engine, TiledMap map, MapEventArgs mapEventArgs)
        {
            LightShader lightShader = (LightShader)engine.GetPostGameShader("LightShader");
            lightShader.Enabled = false;

            Random random = new Random();

            for (int i = 0; i < 50; i++)
            {
                int px = (int)Math.Ceiling(random.NextDouble() * engine.Map.pxWidth);
                int py = (int)Math.Ceiling(random.NextDouble() * engine.Map.pxHeight);

                Bat bat = new Bat(px, py);
                Coin coin = new Coin(px, py, 100, (CoinType)random.Next(3));

                // Switch between adding bats and coins to the map.
                if (i % 2 == 0)
                    engine.AddEntity(bat);
                else
                    engine.AddEntity(coin);
            }

            base.MapLoaded(engine, map, mapEventArgs);
        }
        protected override void LoadContent()
        {
            ItemRepository.LoadRepositoryXml("Items/ItemRepository.xml", Content);

            LightShader = new LightShader(this.GraphicsDevice, CIRCLE_POINT_ACCURACY);
            LightShader.AmbientLight = new Color(30, 15, 15);
            LightShader.Enabled = false;
            Engine.RegisterGameShader("LightShader", LightShader);

            MapEventArgs mapArgs = new MapEventArgs();
            mapArgs.SetProperty("Target", "CaveExit");
            Engine.LoadMap("Content/Maps/cave_example.tmx", mapArgs);

            CurrentSampler = SamplerStates[SamplerIndex];

            Engine.DrawingOptions.ShowEntityDebugInfo = false;
            Engine.DrawingOptions.ShowBoundingBoxes = false;
            Engine.DrawingOptions.ShowTileGrid = false;

            Engine.LoadContent();

            SpriteBatch = new SpriteBatch(GraphicsDevice);

            DefaultSpriteFont = Content.Load<SpriteFont>(@"Fonts\DefaultSpriteFont");
        }
        public void MapLoaded(TeeEngine engine, TiledMap map, MapEventArgs args)
        {
            engine.GetPostGameShader("LightShader").Enabled = false;

            _player = (Hero)engine.GetEntity("Player");

            // The player should start with zero intensity
            _player.Intensity = 0;
            _spawners = new List<MobSpawner>();

            List<Entity> entities = new List<Entity>(engine.GetEntities());
            foreach (Entity e in entities)
            {
                if (e is MobSpawner)
                    _spawners.Add((MobSpawner)e);
            }

            // Setup and load the UI
            Hud = new ArenaUI(engine.Game);

            List<Component> hudComponents = Component.LoadComponentsFromXml("HUD/Elements/Components.ui", engine.Game.Content);
            foreach (Component c in hudComponents)
                Hud.AddComponent(c.Name, c);

            // Bind data to components
            if (_player != null)
            {
                Label label = (Label)Hud.GetComponent("HeroLevel");
                if (label != null)
                    label.SetDataBinding("Level", _player);

                label = (Label)Hud.GetComponent("HeroStrength");
                if (label != null)
                    label.SetDataBinding("Strength", _player);

                label = (Label)Hud.GetComponent("HeroDexterity");
                if (label != null)
                    label.SetDataBinding("Dexterity", _player);

                label = (Label)Hud.GetComponent("HeroWisdom");
                if (label != null)
                    label.SetDataBinding("Wisdom", _player);

                Button cheat = (Button)Hud.GetComponent("CheatButton");
                if(cheat != null)
                    cheat.onMouseClick += new Component.MouseEventHandler(delegate(Component sender, MouseState mouse)
                    {
                        _player.LevelUp();
                        _player.HP = _player.MaxHP;
                    });

                _player.onItemEquipped += new NPC.OnItemEquippedEventHandler(NPC_onItemEquiped);
                _player.onItemUnEquipped += new NPC.OnItemUnEquippedEventHandler(NPC_onItemUnEquiped);
                _player.onDeath += new NPC.OnDeathEventHandler(NPC_onDeath);

                // Load the currently equipped items
                foreach (KeyValuePair<ItemType, Item> pair in _player.Equiped)
                {
                    NPC_onItemEquiped(_player, pair.Value);
                }
            }

            _mapLoaded = true;
        }
        public override void Update(GameTime gameTime)
        {
            LastUpdateTime = gameTime;

            // Allow Map to Perform Update Routine
            if (MapScript != null)
            {
                OverallPerformance.RestartTiming("MapScriptUpdateTime");
                MapScript.Update(this, gameTime);
                OverallPerformance.StopTiming("MapScriptUpdateTime");
            }

            OverallPerformance.ResetAll();
            OverallPerformance.RestartTiming("TotalEntityUpdateTime");

            foreach (string entityId in _entities.Keys)
            {
                Entity entity = _entities[entityId];
                entity.PreviousBoundingBox = entity.CurrentBoundingBox;

                EntityUpdatePerformance.RestartTiming(entityId);
                {
                    entity.Update(gameTime, this);
                }
                EntityUpdatePerformance.StopTiming(entityId);

                // Recalculate the Entities BoundingBox.
                entity.CurrentBoundingBox = entity.GetPxBoundingBox(gameTime);

                // Reset the IsOnScreen variable before the next drawing operation.
                entity.IsOnScreen = false;

                // If the entity has moved, then update his position in the QuadTree.
                OverallPerformance.StartTiming("ColliderUpdateTime");
                {
                    if (entity.CurrentBoundingBox != entity.PreviousBoundingBox)
                        Collider.Update(entity);
                }
                OverallPerformance.StopTiming("ColliderUpdateTime");
            }

            OverallPerformance.StopTiming("TotalEntityUpdateTime");

            DestroyEntities(gameTime);
            CreateEntities(gameTime);

            // If the Map Loaded flag has beem set, we need to invoke the MapScripts MapLoaded event hook.
            if (_mapLoaded)
            {
                EntityRenderPerformance.Clear();
                EntityUpdatePerformance.Clear();

                if (MapScript != null)
                    MapScript.MapLoaded(this, Map, _mapLoadedEventArgs);

                _mapLoadedEventArgs = null;
                _mapLoaded = false;

                DestroyEntities(gameTime);
                CreateEntities(gameTime);
            }
        }
 public void LoadMap(string mapFilePath, MapEventArgs mapLoadedEventArgs=null)
 {
     LoadMap(TiledMap.LoadTmxFile(mapFilePath), mapLoadedEventArgs);
 }
        public void LoadMap(TiledMap map, MapEventArgs mapLoadedEventArgs=null)
        {
            this.Map = map;
            this.Map.LoadContent(Game.Content);

            // Load Specified Map Scipt (If Any)
            if (this.Map.HasProperty("MapScript"))
            {
                string assemblyName = map.GetProperty("Assembly");
                string mapModel = map.GetProperty("MapScript");

                this.MapScript = (IMapScript)Activator.CreateInstance(assemblyName, mapModel).Unwrap();
            }
            else this.MapScript = null;

            // Convert TiledObjects into Entity objects.
            ConvertMapObjects(map);

            // Set the mapLoaded flag so that the MapLoaded event can be invoked at a later stage.
            _mapLoaded = true;
            _mapLoadedEventArgs = mapLoadedEventArgs;

            // unload previous map here.

            this.Collider.Construct(map.txWidth, map.txHeight, map.TileWidth, map.TileHeight);

            // Setup the pathfinding with the new map
            this.Pathfinding = new AStar(this.Map);
        }