Пример #1
0
        void StickAttack()
        {
            //put player in bottom left corner have him try to catch enemy on collision enemy takes damage

            player.Update();

            //Make the monster run away from the player and away from the direction the player is heading
            Vector2 playerCourse = player.Position + (Utils.LockMagnitude(player.direction, 1) * Vector2.Distance(monster.Position, player.Position));

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

            player.Draw();
            monster.Draw();

            //Check for collision and if so damage the enemy and end the players turn
            if (CollisionManager.Colliding(player, monster))
            {
                monster.creature.TakeDamage((player.creature as CRPGNamespace.Player).Damage);
                if (monster.creature != null)
                {
                    healthBar.Width = ((float)monster.creature.currentHP / (float)monster.creature.maximumHP) * healthBackground.Width;
                }
                Window.attackTimer.Reset(Window.attackTimer.delay);
            }
        }
Пример #2
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);
                    }
                }
            }
        }
Пример #3
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);
                    }
                }
            }
        }
Пример #4
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);
            }
        }
Пример #5
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;
                }
            }
        }
Пример #6
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;
        }
Пример #7
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();
        }