Exemple #1
0
        public override void Cast(ContentManager content, Ball ball, GameTime gameTime)
        {
            double seconds = gameTime.TotalGameTime.TotalSeconds;

            if (-0.01 < seconds - (int)seconds && seconds - (int)seconds < 0.01)
            {
                if (mana < 100)
                {
                    mana++;
                }
            }
            if (-0.01 < seconds - ((int)seconds + 0.5) && seconds - ((int)seconds + 0.5) < 0.01)
            {
                if (mana < 100)
                {
                    mana++;
                }
            }

            //If ball is near goal, random chance to cast Portal Trap
            Rectangle casterBox = Game1.walls[2].BoundingBox();
            Rectangle box       = new Rectangle(casterBox.X, casterBox.Y, casterBox.Width, casterBox.Height);

            box.X      -= 60;
            box.Y      -= 20;
            box.Width  += 60;
            box.Height += 40;

            if (ball.BoundingBox().Intersects(box))
            {
                if (randomizer.Next(1, 6) <= 2)
                {
                    if (mana > PortalTrap.Cost)
                    {
                        PortalTrap temp = new PortalTrap(2, this, ball);
                        temp.LoadContent(content);

                        if (!temp.IsFail())
                        {
                            animState      = AnimationState.Attack;
                            attackOverride = true;
                            mana          -= PortalTrap.Cost;
                        }
                        else
                        {
                            //This should not happen because it should be trigged before it enters the goal or not at all.
                            //Or should it happen as the ball continually intersects it?
                        }
                    }
                }
            }
            //Randomly casts Force Field
            if (randomizer.Next(1, 15) == 4 && mana >= 78)
            {
                ForceField temp = new ForceField(2, wizardSprites[10].Width); //has to be the largest attack to prevent issues IMPORTANT
                temp.LoadContent(content, new Vector2(position.X, position.Y), ball);
                if (!temp.IsFail())
                {
                    animState      = AnimationState.Attack;
                    attackOverride = true;
                    mana          -= ForceField.Cost;
                }
            }

            //if ball is near, cast slime ball
            if (randomizer.Next(1, 350) == 2 && mana >= 50 && Vector2.Distance(ball.BoundingBox().Center.ToVector2(), BoundingBox().Center.ToVector2()) < 500)
            {
                SlimeBall temp = new SlimeBall(2, new Vector2(position.X + wizardSprites[currentTexture].Width / 2, position.Y + wizardSprites[currentTexture].Height / 2), ball);
                temp.LoadContent(content);
                mana          -= SlimeBall.Cost;
                animState      = AnimationState.Attack;
                attackOverride = true;
            }
            //if other play is near center line, cast slowtime
            if (randomizer.Next(1, 4) == 2 && mana >= 60 && Math.Abs(Game1.walls[0].BoundingBox().X - enemy.BoundingBox().X) < 500 && !ball.TowardsAIGoal())
            {
                SlowTime temp = new SlowTime(2);
                temp.LoadContent(content);
                mana          -= SlowTime.Cost;
                animState      = AnimationState.Attack;
                attackOverride = true;
            }
        }
Exemple #2
0
        public virtual void Cast(ContentManager content, Ball ball, GameTime gameTime)
        {
            castCounter += 0.1;
            KeyboardState keyboardState = Keyboard.GetState();
            GamePadState  padState      = GamePad.GetState(PlayerIndex.One); //prevents issues with a value that doesn't exist

            if (playerNum == 1)
            {
                padState = GamePad.GetState(PlayerIndex.One);
            }
            else if (playerNum == 2)
            {
                padState = GamePad.GetState(PlayerIndex.Two);
            }
            double seconds = gameTime.TotalGameTime.TotalSeconds;

            if (-0.01 < seconds - (int)seconds && seconds - (int)seconds < 0.01)
            {
                if (mana < 100)
                {
                    mana++;
                }
            }
            if (-0.01 < seconds - ((int)seconds + 0.5) && seconds - ((int)seconds + 0.5) < 0.01)
            {
                if (mana < 100)
                {
                    mana++;
                }
            }

            if (castCounter >= 1)
            {
                if (keyboardState.IsKeyDown(control[4]) || (padState.IsButtonDown(Buttons.A) && !Game1.lastGamePadOne.IsButtonDown(Buttons.A)))
                {
                    if (mana > ForceField.Cost)
                    {
                        ForceField temp = new ForceField(playerNum, wizardSprites[10].Width);                                                                                    //has to be the largest attack image to prevent issues IMPORTANT, and if player two then needs to change corner
                        temp.LoadContent(content, new Vector2(playerNum == 1 ? position.X : position.X - (wizardSprites[10].Width - wizardSprites[0].Width), position.Y), ball); //and if player two then needs to change corner because opens to the left


                        if (!temp.IsFail()) //Did not fail due to exceptions
                        {
                            animState      = AnimationState.Attack;
                            attackOverride = true;
                            mana          -= ForceField.Cost;
                        }
                    }
                    else
                    {
                        NoMana temp = new NoMana(playerNum);
                        temp.LoadContent(content);
                    }
                }
                else if (keyboardState.IsKeyDown(control[5]) || (padState.IsButtonDown(Buttons.X) && !Game1.lastGamePadOne.IsButtonDown(Buttons.X)))
                {
                    if (mana > SlowTime.Cost)
                    {
                        SlowTime temp = new SlowTime(playerNum);
                        temp.LoadContent(content);
                        mana          -= SlowTime.Cost;
                        animState      = AnimationState.Attack;
                        attackOverride = true;
                    }
                    else
                    {
                        NoMana temp = new NoMana(playerNum);
                        temp.LoadContent(content);
                    }
                }
                else if (keyboardState.IsKeyDown(control[6]) || (padState.IsButtonDown(Buttons.Y) && !Game1.lastGamePadOne.IsButtonDown(Buttons.Y)))
                {
                    if (mana > SlimeBall.Cost)
                    {
                        SlimeBall temp = new SlimeBall(playerNum, new Vector2(position.X + wizardSprites[currentTexture].Width / 2, position.Y + wizardSprites[currentTexture].Height / 2), ball);
                        temp.LoadContent(content);
                        mana          -= SlimeBall.Cost;
                        animState      = AnimationState.Attack;
                        attackOverride = true;
                    }
                    else
                    {
                        NoMana temp = new NoMana(playerNum);
                        temp.LoadContent(content);
                    }
                }
                else if (keyboardState.IsKeyDown(control[7]) || (padState.IsButtonDown(Buttons.B) && !Game1.lastGamePadOne.IsButtonDown(Buttons.B)))
                {
                    if (mana > PortalTrap.Cost)
                    {
                        PortalTrap temp = new PortalTrap(playerNum, this, ball);
                        temp.LoadContent(content);

                        if (!temp.IsFail())
                        {
                            mana          -= PortalTrap.Cost;
                            animState      = AnimationState.Attack;
                            attackOverride = true;
                        }
                    }
                    else
                    {
                        NoMana temp = new NoMana(playerNum);
                        temp.LoadContent(content);
                    }
                }
                else
                {
                    return; //needs to break to prevent cast counter reset
                }
                castCounter = 0;
            }
        }