コード例 #1
0
        public override void Update(ArenaUI hud, GameTime dt, InputState input)
        {
            if (!Visible)
                return;

            base.Update(hud, dt, input);

            // If the entities go out of range of one another close the conversation
            if (Vector2.Distance(Speaker.Pos, Audience.Pos) > 40)
                Visible = false;
        }
コード例 #2
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;
        }