Esempio n. 1
0
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            Hero player = (Hero) engine.GetEntity("Player");
            KeyboardState keyboardState = Keyboard.GetState();

            if (KeyboardExtensions.GetKeyDownState(keyboardState, Keys.S, this, true)
                && Entity.IntersectsWith(this, null, player, "Shadow", gameTime))
            {
                if (CurrentDrawableState != "Open")
                {
                    Random random = new Random();

                    CurrentDrawableState = "Open";
                    Drawables.ResetState("Open", gameTime);

                    for (int i = 0; i < 10; i++)
                    {
                        Coin coin = new Coin(this.Pos.X, this.Pos.Y, 100, (CoinType)random.Next(3));
                        coin.Pos.X += (float) ((random.NextDouble() - 0.5) * 100);
                        coin.Pos.Y += (float) ((random.NextDouble() - 0.5) * 100);

                        engine.AddEntity(coin);
                    }
                }
            }
        }
Esempio n. 2
0
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            Hero player = (Hero) engine.GetEntity("Player");
            KeyboardState keyboardState = Keyboard.GetState();

            if (KeyboardExtensions.GetKeyDownState(keyboardState, Keys.S, this, true)
                && Entity.IntersectsWith(this, "interaction", player, "Shadow", gameTime))
            {
                if (CurrentDrawableState != "Open")
                {
                    Random random = new Random();

                    _openSfx[random.Next(1)].Play();

                    CurrentDrawableState = "Open";
                    Drawables.ResetState("Open", gameTime);

                    for (int i = 0; i < 10; i++)
                    {
                        Coin coin = new Coin(this.Pos.X, this.Pos.Y, 100, (CoinType)random.Next(3));
                        coin.Pos.X += (float) ((random.NextDouble() - 0.5) * 100);
                        coin.Pos.Y += (float) ((random.NextDouble() - 0.5) * 100);
                        coin.TerrainCollisionEnabled = false;       // Prevent from getting stuck in sorrounding walls.

                        engine.AddEntity(coin);
                    }
                }
            }

            base.Update(gameTime, engine);
        }
        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);
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            Hero player = (Hero)engine.GetEntity("Player");
            Vector2 target;
            if (CoinState == State.Spawning)
            {
                target = SpawnTarget;
                float distance = Vector2.Distance(Pos, SpawnTarget);

                if (distance < 2.5)
                {
                    CoinState = State.Active;
                    Drawables.SetGroupProperty("Body", "Offset", Vector2.Zero);
                }
            }
            else
            {
                target = player.Pos;
            }

            if (IsOnScreen)
            {
                float COIN_MOVE_SPEED = 5000;
                float TERMINAL_VELOCITY = 5;

                // Find the distance between the player and this coin.
                float distanceSquared = Vector2.DistanceSquared(Pos, target);

                float speed = COIN_MOVE_SPEED / distanceSquared;  // Mangitude of velocity.
                speed = Math.Min(speed, TERMINAL_VELOCITY);

                if (speed > 0.5)
                {
                    // Calculate the angle between the player and the coin.
                    double angle = Math.Atan2(
                        target.Y - this.Pos.Y,
                        target.X - this.Pos.X
                        );

                    this.Pos.X += (float)(Math.Cos(angle) * speed);        // x component.
                    this.Pos.Y += (float)(Math.Sin(angle) * speed);        // y component.

                    // Check to see if coin can be considered collected.
                    if (Entity.IntersectsWith(this, "Shadow", player, "Shadow", gameTime))
                    {
                        CoinSound.Play(0.05f, 0.0f, 0.0f);
                        player.Gold += this.CoinValue;
                        engine.RemoveEntity(this);
                    }
                }
            }
        }
Esempio n. 6
0
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            // Get the Hero player for interaction purposes.
            Hero player = (Hero)engine.GetEntity("Player");
            Vector2 prevPos = Pos;

            // Check if this Bat has died.
            if (HP <= 0)
            {
                this.Opacity -= 0.02f;
                this.Drawables.ResetState(CurrentDrawableState, gameTime);
                if (this.Opacity < 0)
                    engine.RemoveEntity(this);
            }
            else
            {
                // ATTACKING LOGIC.
                if (_attackStance == AttackStance.Attacking)
                {
                    this.Pos.X -= (float) (Math.Cos(_attackAngle) * _attackSpeed);
                    this.Pos.Y -= (float) (Math.Sin(_attackAngle) * _attackSpeed);
                    this._attackHeight.Y += 30.0f / ATTACK_COUNTER_LIMIT;
                    this.Drawables.SetGroupProperty("Body", "Offset", _attackHeight);

                    if (Entity.IntersectsWith(this, "Shadow", player, "Shadow", gameTime))
                        player.HP -= 3;

                    if (_attackCounter++ == ATTACK_COUNTER_LIMIT)
                        _attackStance = AttackStance.NotAttacking;
                }
                // ATTACK PREPERATION LOGIC.
                else if (_attackStance == AttackStance.Preparing)
                {
                    _attackHeight.Y -= 2;

                    if (_attackHeight.Y < -40)
                    {
                        _attackHeight.Y = -40;
                        _attackAngle = Math.Atan2(
                            this.Pos.Y - player.Pos.Y,
                            this.Pos.X - player.Pos.X
                            );
                        _attackStance = AttackStance.Attacking;
                        _attackCounter = 0;
                    }

                    Drawables.SetGroupProperty("Body", "Offset", _attackHeight);
                }
                // NON-ATTACKING LOGIC. PATROL AND APPROACH.
                else if (_attackStance == AttackStance.NotAttacking)
                {
                    double distance = Vector2.Distance(player.Pos, this.Pos);

                    if (distance < AGRO_DISTANCE)
                    {
                        // Move towards the player for an attack move.
                        double angle = Math.Atan2(
                            player.Pos.Y - this.Pos.Y,
                            player.Pos.X - this.Pos.X
                            );

                        // Approach Function.
                        double moveValue;
                        if (distance < ATTACK_DISTANCE)
                        {
                            _attackStance = AttackStance.Preparing;
                            moveValue = 0;
                        }
                        else
                            moveValue = _moveSpeed;

                        Pos.X += (float)(Math.Cos(angle) * moveValue);
                        Pos.Y += (float)(Math.Sin(angle) * moveValue);
                    }
                    else
                    {
                        // Perform a standard patrol action.
                        Pos.X += (float)(Math.Cos(gameTime.TotalGameTime.TotalSeconds - _randomModifier * 90) * 2);
                    }
                }

                // Determine the animation based on the change in position.
                if (Math.Abs(prevPos.X - Pos.X) > Math.Abs(prevPos.Y - Pos.Y))
                {
                    if (prevPos.X < Pos.X)
                        this.CurrentDrawableState = "Right";
                    if (prevPos.X > Pos.X)
                        this.CurrentDrawableState = "Left";
                }
                else
                {
                    if (prevPos.Y < Pos.Y)
                        this.CurrentDrawableState = "Down";
                    if (prevPos.Y > Pos.Y)
                        this.CurrentDrawableState = "Up";
                }
            }
        }
Esempio n. 7
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;
        }
Esempio n. 8
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;
                }
            }
        }
Esempio n. 9
0
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            if (IsOnScreen)
            {
                float COIN_MOVE_SPEED = 5000;
                float TERMINAL_VELOCITY = 5;

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

                // Find the distance between the player and this coin.
                float distanceSquared = Vector2.DistanceSquared(Pos, player.Pos);

                float speed = COIN_MOVE_SPEED / distanceSquared;  // Mangitude of velocity.
                speed = Math.Min(speed, TERMINAL_VELOCITY);

                if (speed > 0.5)
                {
                    // Calculate the angle between the player and the coin.
                    double angle = Math.Atan2(
                        player.Pos.Y - this.Pos.Y,
                        player.Pos.X - this.Pos.X
                        );

                    this.Pos.X += (float)(Math.Cos(angle) * speed);        // x component.
                    this.Pos.Y += (float)(Math.Sin(angle) * speed);        // y component.

                    // Check to see if coin can be considered collected.
                    if (Entity.IntersectsWith(this, "Shadow", player, "Shadow", gameTime))
                    {
                        Random random = new Random();

                        _coinSfx[random.Next(_coinSfx.Length)].Play(0.5f, 0.0f, 0.0f);
                        player.Coins += this.CoinValue;
                        engine.RemoveEntity(this);
                    }
                }
            }

            base.Update(gameTime, engine);
        }