示例#1
0
        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;
        }
示例#2
0
        public void Update(TeeEngine engine, GameTime gameTime)
        {
            if (!_mapLoaded) return;

            if (_isGameOver)
            {
                if (!_gameOverLoaded)
                {
                    List<Component> hudComponents = Component.LoadComponentsFromXml("HUD/Elements/GameOver.ui", engine.Game.Content);
                    foreach (Component c in hudComponents)
                        Hud.AddComponent(c.Name, c);

                    _gameOverLoaded = true;

                    Button restart = (Button)Hud.GetComponent("RestartButton");
                    restart.onMouseClick += new Component.MouseEventHandler(delegate(Component sender, MouseState mouse)
                    {
                        engine.ClearEntities();
                        engine.LoadMap("Content/Maps/arena.tmx");
                    });

                    Button exit = (Button)Hud.GetComponent("QuitButton");
                    exit.onMouseClick += new Component.MouseEventHandler(delegate(Component sender, MouseState mouse)
                    {
                        engine.Game.Exit();
                    });
                }
            }
            else
            {
                Hero player = (Hero)engine.GetEntity("Player");
                bool reduceIntensity = true;

                foreach (Entity entity in engine.EntitiesOnScreen)
                {
                    if (entity is Mob)
                    {
                        Mob mob = (Mob)entity;

                        // If any mob on screen is attacking the player, don't reduce their intensity value
                        if (mob.Stance == Mob.AttackStance.Attacking)
                        {
                            reduceIntensity = false;
                            break;
                        }
                    }
                }

                if (reduceIntensity)
                {
                    _intensityReductionTimer += gameTime.ElapsedGameTime.Milliseconds;

                    // Intensity should reduce at a rate of 90pts per 30 sec or 3pts per second
                    if (_intensityReductionTimer >= _intensityReductionDuration)
                    {
                        player.Intensity--;
                        if (player.Intensity < 0) player.Intensity = 0;

                        _intensityReductionTimer = 0;
                    }
                }

                // Check to spawn new mobs
                _mobSpawnTimer += gameTime.ElapsedGameTime.Milliseconds;

                if (_mobSpawnTimer >= _mobSpawnDelay && player.Intensity < 30)
                {
                    List<Entity> entities = new List<Entity>(engine.GetEntities());
                    List<Entity> mobs = entities.FindAll(delegate(Entity e) { return e is Mob; });

                    // Only have up to x mobs at once
                    if (mobs.Count < 15)
                    {

                        // Spawn a new mob on a random mob spawner
                        int spawner = randomGenerator.Next(0, _spawners.Count);

                        _spawners[spawner].SpawnMob(engine);
                    }

                    // Reset the timer regardless, just check again later
                    _mobSpawnTimer = 0;
                }
            }
        }