예제 #1
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();
        }
예제 #2
0
        void MermaidAttack()
        {
            //spears appear pointing at the player and travel forward on collision player takes damage

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

            //Update spears
            for (int x = 0; x < MathF.Min((spears.Count + 1) * Window.attackTimer.PercentComplete, spears.Count); x++)
            {
                spears[x].Spawn(player.Position);
                spears[x].Update();
                spears[x].Draw();

                //Check for collision
                if (CollisionManager.Colliding(player, spears[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;
                    }

                    spears.RemoveAt(x);

                    if (spears.Count == 0)
                    {
                        Window.attackTimer.Reset(Window.attackTimer.delay);
                    }
                }
            }
        }
예제 #3
0
        void LooterAttack()
        {
            //one looter spawned in the bottom left corner of the scene, player cannot see the looter when it is behind them, on collision player takes damage
            #region Create and update player view triangle
            Vector2 triPoint2 = player.Position + Utils.RotationMatrix(Utils.LockMagnitude(player.direction, 1), Utils.DegToRad(-70), Window.screenWidth / MathF.Cos(Utils.DegToRad(-70)));
            Vector2 triPoint3 = player.Position + Utils.RotationMatrix(Utils.LockMagnitude(player.direction, 1), Utils.DegToRad(70), Window.screenWidth / MathF.Cos(Utils.DegToRad(70)));
            DrawTriangle(player.Position, triPoint2, triPoint3, GRAY);
            #endregion

            player.Update();
            player.Draw();

            monster.SetDirection(player.Position - monster.Position);
            monster.Update();

            //If monster is within view of player draw it
            if (MathF.Abs(Utils.AngleBetween(Utils.LockMagnitude(player.direction, 1), monster.Position - player.Position)) < 70)
            {
                monster.Draw();
                monster.speed = 300;
            }
            else
            {
                monster.speed = 100;
            }

            //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;
                }
                Window.attackTimer.Reset(Window.attackTimer.delay);
            }
        }
예제 #4
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;
                }
            }
        }
예제 #5
0
        void TrollAttack()
        {
            //troll will randomly attack the left right or center all of which take up have the screen player must avoid or take damage

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

            //If it hasn't been long enough inbetween attack return
            if (!waitTimer.Check(false))
            {
                return;
            }

            //for the first frame decide which space to attack from
            if (stallTimer.Time == 0)
            {
                spaceToUse = Utils.NumberBetween(0, attackSpaces.Count - 1);
                while (spaceToUse == prevSpace)
                {
                    spaceToUse = Utils.NumberBetween(0, attackSpaces.Count - 1);
                }
            }

            attackSpaces[spaceToUse].Draw();
            player.Draw();//Make sure to draw the player over the space

            //if it hasn't been long enough to give the player a chance to react set color to grey and return
            if (!stallTimer.Check(false))
            {
                attackSpaces[spaceToUse].color = GRAY;
                return;
            }

            //hold the damage zone so the player can see it
            if (!holdTimer.Check())
            {
                attackSpaces[spaceToUse].color = RED;

                if (!hit && CollisionManager.Colliding(player, attackSpaces[spaceToUse].Rectangle))
                {
                    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;
                    }

                    hit = true;
                }

                return;
            }

            //reset and run again
            prevSpace = spaceToUse;
            stallTimer.Reset();
            waitTimer.Reset();
            attackSpaces[spaceToUse].color = BLANK;
            hit = false;
        }
예제 #6
0
        void MermaidSpearAttack()
        {
            //spears appear pointing at the player and travel forward on collision player takes damage

            //if the player hasn't used up all their spears and press and release the left mouse button spawn a new spear traveling in the direction the player dragged
            if (spears.Count < 15)
            {
                if (IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                {
                    spawnPoint = GetMousePosition();
                }
                if (IsMouseButtonReleased(MouseButton.MOUSE_LEFT_BUTTON))
                {
                    spears.Add(new LineSprite(spawnPoint, GetMousePosition() - spawnPoint, 100, 10, 600, SKYBLUE));
                }
            }
            else if (endTimer.Check())
            {
                Window.attackTimer.Reset(Window.attackTimer.delay);
                return;
            }

            //If there are no active spears make the monster run from the cursor and return
            if (spears.Count == 0)
            {
                monster.SetDirection(monster.Position - GetMousePosition());
                monster.Update();
                monster.Draw();
                return;
            }

            float distance       = Vector2.Distance(monster.Position, spears[0].position);
            int   spearToRunFrom = 0;

            //Update spears
            for (int x = 0; x < spears.Count; x++)
            {
                spears[x].Update();
                spears[x].Draw();

                //Checks to see if monster was hit and if so, deal damage
                if (CollisionManager.Colliding(monster, spears[x]))
                {
                    int damage = (player.creature as CRPGNamespace.Player).Damage;

                    monster.creature.TakeDamage(damage);

                    if (monster.creature != null)
                    {
                        monster.PopUp(damage.ToString(), (int)Utils.Lerp(10, 70, damage / monster.creature.maximumHP));
                        healthBar.Width = ((float)monster.creature.currentHP / (float)monster.creature.maximumHP) * healthBackground.Width;
                    }

                    spears.RemoveAt(x);

                    if (spears.Count != 0)
                    {
                        continue;
                    }

                    //if there are no spears run from mouse and don't continue
                    monster.SetDirection(monster.Position - GetMousePosition());
                    monster.Update();
                    monster.Draw();
                    return;
                }

                //Determine which spear to make the monster run from
                if (distance > Vector2.Distance(monster.Position, spears[x].position))
                {
                    spearToRunFrom = x;
                    distance       = Vector2.Distance(monster.Position, spears[x].position);
                }
            }

            Vector2 course = spears[spearToRunFrom].position + (Utils.LockMagnitude(spears[spearToRunFrom].Direction, 1) * Vector2.Distance(monster.Position, spears[spearToRunFrom].position));

            monster.SetDirection(monster.Position - course);
            monster.Update();
            monster.Draw();
        }