Пример #1
0
        void WolfAttack()
        {
            //Wolves spawn randomly throughout the scene over time and if a wolf collides with player, player takes damage

            //Update the player
            player.Update();
            player.Draw();

            //Update Wolves
            for (int x = 0; x < MathF.Min(wolves.Count * Window.attackTimer.PercentComplete * 2, wolves.Count); x++)
            {
                wolves[x].SetDirection(player.Position - wolves[x].Position);
                wolves[x].Update();
                wolves[x].Draw();

                //make sure the wolves never overlap
                for (int y = 0; y < wolves.Count; y++)
                {
                    if (CollisionManager.Colliding(wolves[x], wolves[y]))
                    {
                        CollisionManager.Push(wolves[x], wolves[y]);
                    }
                }

                //Check to see if a wolf hit the player
                if (CollisionManager.Colliding(player, wolves[x]))
                {
                    int damage = Utils.NumberBetween(minDamage, maxDamage);

                    player.creature.TakeDamage(damage);

                    if (player.creature != null)
                    {
                        damage -= (player.creature as CRPGNamespace.Player).CurrentAc;
                        damage  = (int)MathF.Max(damage, 1);
                        player.PopUp(damage.ToString(), (int)Utils.Lerp(10, 70, damage / player.creature.maximumHP));
                        healthBar.Width = ((float)player.creature.currentHP / (float)player.creature.maximumHP) * healthBackground.Width;
                    }

                    wolves.RemoveAt(x);

                    if (wolves.Count == 0)
                    {
                        Window.attackTimer.Reset(Window.attackTimer.delay);
                    }
                }
            }
        }
Пример #2
0
        void InitBandits()
        {
            arrows.Clear();
            monster.Position = new Vector2(Utils.NumberBetween((int)(Window.playZoneBarrier.X + 10), (int)(Window.playZoneBarrier.Z - 10)),
                                           Utils.NumberBetween((int)(Window.playZoneBarrier.Y + 10), (int)(Window.playZoneBarrier.W - 10)));
            monster.speed       = 0;
            monster.sensitivity = 0;

            monster2 = new AI(monster.texture, monster.Position, WHITE, 16, Vector2.One * 4, monster.radius);
            CollisionManager.Push(monster, monster2);
            monster2.speed       = 500;
            monster2.sensitivity = 1.5f;


            player.Position    = new Vector2(Window.screenWidth / 2, Window.screenHeight / 2);
            player.sensitivity = 4;
            player.speed       = 400;

            rangedTimer.Reset();
            playerInvulnerability.Reset();
        }
Пример #3
0
        void BanditsAttack()
        {
            //Have two bandits attack the player one using melee and one range

            //Updates
            player.Update();
            player.Draw();

            Vector2 dir = player.Position - monster.Position;

            if (MathF.Abs(dir.X) > MathF.Abs(dir.Y))
            {
                state = (dir.X > 0) ? 2 : 1;
            }
            else if (MathF.Abs(dir.X) < MathF.Abs(dir.Y))
            {
                state = (dir.Y > 0) ? 0 : 3;
            }
            monster.SetState(state);
            monster.Draw();

            monster2.SetDirection(player.Position - monster2.Position);
            monster2.Update();
            monster2.Draw();
            //make monster2 collide with monster
            if (CollisionManager.Colliding(monster, monster2))
            {
                CollisionManager.Push(monster, monster2);
            }

            //have monster one shoot a new arrow
            if (rangedTimer.Check())
            {
                arrows.Add(new LineSprite(monster.Position, player.Position - monster.Position, 60, 10, 600, BROWN));
            }
            //Update arrows
            for (int x = 0; x < arrows.Count; x++)
            {
                arrows[x].Update();
                arrows[x].Draw();

                //Check to see if arrow has collided with player
                if (CollisionManager.Colliding(player, arrows[x]))
                {
                    int damage = Utils.NumberBetween(minDamage, maxDamage);

                    player.creature.TakeDamage(damage);

                    if (player.creature != null)
                    {
                        damage -= (player.creature as CRPGNamespace.Player).CurrentAc;
                        damage  = (int)MathF.Max(damage, 1);
                        player.PopUp(damage.ToString(), (int)Utils.Lerp(10, 70, damage / player.creature.maximumHP));
                        healthBar.Width = ((float)player.creature.currentHP / (float)player.creature.maximumHP) * healthBackground.Width;
                    }

                    arrows.RemoveAt(x);
                }
            }

            //ensure the player doesn't get sawbladed by the enemies
            if (playerInvulnerability.Check(false))
            {
                //check to see if monster has collided with the player
                if (CollisionManager.Colliding(player, monster))
                {
                    player.creature.TakeDamage(Utils.NumberBetween(minDamage, maxDamage));
                    if (player.creature != null)
                    {
                        healthBar.Width = ((float)player.creature.currentHP / (float)player.creature.maximumHP) * healthBackground.Width;
                    }

                    CollisionManager.Push(monster, player);
                    playerInvulnerability.Reset();
                }
                //check to see if monster2 has collided with the player
                if (CollisionManager.Colliding(player, monster2))
                {
                    player.creature.TakeDamage(Utils.NumberBetween(minDamage, maxDamage));
                    if (player.creature != null)
                    {
                        healthBar.Width = ((float)player.creature.currentHP / (float)player.creature.maximumHP) * healthBackground.Width;
                    }

                    CollisionManager.Push(monster2, player);
                    playerInvulnerability.Reset();

                    monster2.Position = monster.Position;
                }
            }
        }