mardi 2 mai 2017

Monogame Breakout: Trying to add abilities to random blocks

Problem 2 - adding abilities to random block:

I'm gonna add some abilities to random blocks, u know that drops down when you hit a random block. Like you get 2 balls or bigger paddle or slower ball speed. I know I need to create a new list and then add different blocks with different abilities. But I don't know how to write the code block that chooses a random block and adding a ability to that block. That drops down and you can take with paddle.

I was thinking of a switch, if one random block with ability is hit and using that switch and randomize it.

    void PowerUp()
    {
        powerups.Add(abilityballs_rect);
        powerups.Add(abilitylong_rect);
        powerups.Add(abilityslow_rect);
    }

-

    List<Rectangle> block = new List<Rectangle>();
    List<Rectangle> block2 = new List<Rectangle>();
    List<Rectangle> block3 = new List<Rectangle>();
    List<Rectangle> block4 = new List<Rectangle>();
    List<Rectangle> block5 = new List<Rectangle>();
    List<Rectangle> block6 = new List<Rectangle>();

    List<Rectangle> powerups = new List<Rectangle>();

-

            if (level == 1)
            {
                if (block.Count == 14 && block2.Count == 14)
                {
                    spriteBatch.DrawString(spritefont2, "LEVEL " + level, new Vector2(252, 400), Color.White);
                }

                foreach (Rectangle g in block)
                {
                    spriteBatch.Draw(block_texture, g, Color.LimeGreen);
                }
                foreach (Rectangle r in block2)
                {
                    spriteBatch.Draw(block_texture, r, Color.IndianRed);
                }
            }

            else if (level == 2)
            {
                if (block3.Count == 18 && block4.Count == 27)
                {
                    spriteBatch.DrawString(spritefont2, "LEVEL " + level, new Vector2(246, 400), Color.White);
                }

                foreach (Rectangle b in block3)
                {
                    spriteBatch.Draw(block_texture, b, Color.CornflowerBlue);
                }
                foreach (Rectangle y in block4)
                {
                    spriteBatch.Draw(block_texture, y, Color.Yellow);
                }
            }

            else if (level == 3)
            {
                if (block5.Count == 36 && block6.Count == 18)
                {
                    spriteBatch.DrawString(spritefont2, "LEVEL " + level, new Vector2(246, 400), Color.White);
                }

                foreach (Rectangle o in block5)
                {
                    spriteBatch.Draw(block_texture, o, Color.Orange);
                }
                foreach (Rectangle p in block6)
                {
                    spriteBatch.Draw(block_texture, p, Color.HotPink);
                }
            }

-

    void AddBlocks()
    {
        //LEVEL 1
        for (int i = 1; i < 3; i++)
        {
            for (int f = 1; f < 8; f++)
            {
                block.Add(new Rectangle((f * 63) + 94, (i * 40) + 60, block_texture.Width, block_texture.Height));
            }
        }
        for (int i = 1; i < 3; i++)
        {
            for (int g = 1; g < 8; g++)
            {
                block2.Add(new Rectangle((g * 63) + 94, (i * 40) + 40, block_texture.Width, block_texture.Height));
            }
        }

        //LEVEL 2
        for (int i = 1; i < 3; i++)
        {
            for (int j = 1; j < 10; j++)
            {
                block3.Add(new Rectangle((j * 63) + 34, (i * 200) - 60, block_texture.Width, block_texture.Height));
            }
        }
        for (int i = 1; i < 10; i++)
        {
            for (int k = 1; k < 4; k++)
            {
                block4.Add(new Rectangle((k * 103) + 143, (i * 20) + 140, block_texture.Width, block_texture.Height));
            }
        }

        //LEVEL 3
        for (int i = 1; i < 7; i++)
        {
            for (int j = 1; j < 7; j++)
            {
                block5.Add(new Rectangle((j * 63) + 127, (i * 20) + 190, block_texture.Width, block_texture.Height));
            }
        }
        for (int i = 1; i < 10; i++)
        {
            for (int k = 1; k < 3; k++)
            {
                block6.Add(new Rectangle((k * 443) - 317, (i * 20) + 160, block_texture.Width, block_texture.Height));
            }
        }
    }

-

    void DeleteBlocks()
    {
        if (level == 1)
        {
            for (int j = 0; j < block.Count; j++)
            {
                if (ball_rect.Intersects(block[j]))
                {
                    ball_speed.Y *= -1;
                    points += 1;
                    block.RemoveAt(j);
                    if (points > highscore)
                    {
                        highscore = points;
                    }
                }
            }

            for (int k = 0; k < block2.Count; k++)
            {
                if (ball_rect.Intersects(block2[k]))
                {
                    ball_speed.Y *= -1;
                    points += 1;
                    block2.RemoveAt(k);
                    if (points > highscore)
                    {
                        highscore = points;
                    }
                }
            }
            if (block.Count == 0 && block2.Count == 0)
            {
                level++;
                StartValueBallPaddle();
                Start = false;
            }
        }

        else if (level == 2)
        {
            for (int l = 0; l < block3.Count; l++)
            {
                if (ball_rect.Intersects(block3[l]))
                {
                    ball_speed.Y *= -1;
                    points += 1;
                    block3.RemoveAt(l);
                    if (points > highscore)
                    {
                        highscore = points;
                    }
                }
            }
            for (int m = 0; m < block4.Count; m++)
            {
                if (ball_rect.Intersects(block4[m]))
                {
                    ball_speed.Y *= -1;
                    points += 1;
                    block4.RemoveAt(m);
                    if (points > highscore)
                    {
                        highscore = points;
                    }
                }
            }
            if (block3.Count == 0 && block4.Count == 0)
            {
                level++;
                StartValueBallPaddle();
                Start = false;
            }
        }

        else if (level == 3)
        {
            for (int n = 0; n < block5.Count; n++)
            {
                if (ball_rect.Intersects(block5[n]))
                {
                    ball_speed.Y *= -1;
                    points += 1;
                    block5.RemoveAt(n);
                    if (points > highscore)
                    {
                        highscore = points;
                    }
                }
            }
            for (int o = 0; o < block6.Count; o++)
            {
                if (ball_rect.Intersects(block6[o]))
                {
                    ball_speed.Y *= -1;
                    points += 1;
                    block6.RemoveAt(o);
                    if (points > highscore)
                    {
                        highscore = points;
                    }
                }
            }
        }
    }




Aucun commentaire:

Enregistrer un commentaire