Project help needed
in
Programming Questions
•
5 months ago
I'm trying to make a bubble popping game, and so far I have the bubbles rising up from the bottom of the screen and disappearing out the top. However, I can't get the code working to make them pop. My code calls a class however in this coding instance, I can't do that since this program will be used on a phone as a kid friendly app. Any help would be appreciated since I'm not sure how to get this to work properly.
All It needs to do is pop a bubble when the mouse button is clicked. If I was able to use classes, it would be rather easy, but I have to have it all in one page in order for it to be part of another application that a friend is doing. I'll even provide my code so people can look at it. Sadly, I'm not done commenting it out yet.
//Floats and sets up the Array of Bubbles
float [][] bubble = new float [50][5];
// Sets the on or off state of the Bubbles as a Boolean
boolean [] bubble_state = new boolean [100];
int numb_active_bubble;
int Point_Score;
int time = 0;
void setup() {
size(540, 960);
//Initiaes
numb_active_bubble = 0;
for (int i=0; i<100; i++)
{
bubble_state[i] = false;
}
}
void draw() {
time++;
background(0, 191, 255);
if(time%10==0)
{
createBubble();
}
updateBubble();
drawBubble();
}
void createBubble()
{
for(int i=0; i<100; i++)
{
if(bubble_state[i] == false)
{
bubble[i][0] = random(0,width);
bubble[i][1] = height;
bubble[i][2] = 0;
bubble[i][3] = random(3,5);
bubble[i][4] = random(120,160);
bubble_state[i] = true;
numb_active_bubble++;
break;
}
}
}
void updateBubble()
{
for(int i=0; i<100; i++)
{
if(bubble_state[i] == true)
{
bubble[i][1] = bubble[i][1]- bubble[i][3];
if( bubble[i][1] < -bubble[i][4])
{
bubble_state[i] = false;
numb_active_bubble--;
}
}
}
}
void drawBubble()
{
for(int i=0; i<100; i++)
{
if(bubble_state[i] == true)
{
ellipse( bubble[i][0], bubble[i][1], bubble[i][4], bubble[i][4]);
}
}
}
void mousePressed()
{
if( mouseButton == LEFT && bubble.isMouseIntersect(mouseX, mouseY) )
{
bubble_state[i] = false;
}
}
1