Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 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;
                }
            }
        }