I’m trying to develop my first XNA game by my own hands, just looking the source of tutorials and thinking my own implementations and solutions. Currently, I’m making a bubble shooter game, and I’m drawing the bubbles in their respective position.
The thing is, I have implemented two types of bubbles. The program chooses which type to draw though a random generator (0 or 1 means blue or red), and depending on the result, the selected type is drawn into the screen. This approach is not working, and I have exhausting my search resources. The code is the following
for (int colBubCounter = 0; colBubCounter < maxVerticalBubNumber / 2; colBubCounter++)
{
for (int rowBubCounter = 0; rowBubCounter < maxHorizontBubNumber; rowBubCounter++)
{
Rectangle bubbleDrawRectangle = new Rectangle(initDrawCoordX, initDrawCoordY, bubbleWidth, bubbleHeight);
//Randomizamos el tipo de burbujar a dibujar ( 0 = blue, 1 = red)
bubbleType = randomGenerator.Next(0, 1);
if (bubbleType == 0) spriteBatch.Draw(blueBubbleSprite, bubbleDrawRectangle, Color.White);
else if (bubbleType == 1) spriteBatch.Draw(redBubbleSprite, bubbleDrawRectangle, Color.White);
//Cada vez que dibujamos uno, corremos la coordenada a dibujar en el otro ciclo en 10 pixeles
initDrawCoordX += bubbleWidth;
}
initDrawCoordX = 0;
initDrawCoordY += bubbleHeight;
}
With
System.Random randomGenerator = new System.Random();
I’m not using classes or anything more than raw code, because I’m taking the incremental step development, once this is ready, I’ll do the same thing with classes and other fancy thing.
Thanks for your help, and please let me know if I did something wrong in this question, it’s my first here in StackOverflow. 🙂
The
randomGenerator.Next(0, 1);will always return 0, since maxValue (upper) bound is exclusive. You need to userandomGenerator.Next(0, 2)to make zeroes and ones.