make balloons pop in game
in
Programming Questions
•
1 years ago
i have this game im making where theses balls fall to the ground and the player moves a "pointy device" horizontally to "pop" the balls in order to get points.
i was hoping someone could help me with the popping part here's what i have so far:
ArrayList balls;
int ballRadius = 25;
int level = 1;
int score = 0;
void setup(){
size (450, 700);
fill(0);
smooth();
stroke(0);
strokeWeight(4);
PFont font = loadFont("ComicSansMS-Bold-24.vlw");
textFont(font);
balls = new ArrayList();
for (int i = 0; i < level*2; i++){
balls.add(new Ball(random(15,width-15), random(-300,0), ballRadius));
}
}
void draw(){
background(255);
frameRate(45);
fill(0);
rect(mouseX, height-10, 50,10);
triangle((mouseX)+18,height, (mouseX)+25, height-40, (mouseX)+32, height);
text("Score: " + score, 10,30);
text("Level: " + level, width-150,30);
for (int i = balls.size()-1; i >= 0; i--) {
Ball ball = (Ball) balls.get(i);
ball.move();
ball.display();
}
}
/*
void mousePressed() {
balls.add(new Ball(mouseX, 0, ballRadius));// A new ball object is added to the end of the ArrayList
}
*/
// Bouncing ball class
class Ball {
float x;
float y;
float speed;
float gravity;
float w;
int bounceCount = 0;
Ball(float xPos, float yPos, float bWidth) {
x = xPos;
y = yPos;
w = bWidth;
speed = 0;
gravity = 0.98;
}
void move() {
speed = speed + gravity;// Adds gravity to the speed
y = y + speed;// Adds speed to y location
/*
If square reaches the bottom
Reverse speed
*/
if (y > height) {
speed = speed * -0.8;
y = height;
bounceCount++;
//println(bounceCount);
}
if (x == (mouseX)+25 && y == height-10){
noLoop();
}
}
void display()
{
if (bounceCount == 0){
fill (0,255,0);
}
else if (bounceCount == 1){
fill (255,255,0);
}
else if (bounceCount == 2){
fill (255,150,0);
}
else if (bounceCount == 3||bounceCount == 4||bounceCount == 5){
fill (255,0,0);
}
else if (bounceCount == -1){
fill(255);
stroke(255);
}
else{
fill(200,200,200);
}
ellipse(x,y,w,w);
}
}
i was hoping someone could help me with the popping part here's what i have so far:
ArrayList balls;
int ballRadius = 25;
int level = 1;
int score = 0;
void setup(){
size (450, 700);
fill(0);
smooth();
stroke(0);
strokeWeight(4);
PFont font = loadFont("ComicSansMS-Bold-24.vlw");
textFont(font);
balls = new ArrayList();
for (int i = 0; i < level*2; i++){
balls.add(new Ball(random(15,width-15), random(-300,0), ballRadius));
}
}
void draw(){
background(255);
frameRate(45);
fill(0);
rect(mouseX, height-10, 50,10);
triangle((mouseX)+18,height, (mouseX)+25, height-40, (mouseX)+32, height);
text("Score: " + score, 10,30);
text("Level: " + level, width-150,30);
for (int i = balls.size()-1; i >= 0; i--) {
Ball ball = (Ball) balls.get(i);
ball.move();
ball.display();
}
}
/*
void mousePressed() {
balls.add(new Ball(mouseX, 0, ballRadius));// A new ball object is added to the end of the ArrayList
}
*/
// Bouncing ball class
class Ball {
float x;
float y;
float speed;
float gravity;
float w;
int bounceCount = 0;
Ball(float xPos, float yPos, float bWidth) {
x = xPos;
y = yPos;
w = bWidth;
speed = 0;
gravity = 0.98;
}
void move() {
speed = speed + gravity;// Adds gravity to the speed
y = y + speed;// Adds speed to y location
/*
If square reaches the bottom
Reverse speed
*/
if (y > height) {
speed = speed * -0.8;
y = height;
bounceCount++;
//println(bounceCount);
}
if (x == (mouseX)+25 && y == height-10){
noLoop();
}
}
void display()
{
if (bounceCount == 0){
fill (0,255,0);
}
else if (bounceCount == 1){
fill (255,255,0);
}
else if (bounceCount == 2){
fill (255,150,0);
}
else if (bounceCount == 3||bounceCount == 4||bounceCount == 5){
fill (255,0,0);
}
else if (bounceCount == -1){
fill(255);
stroke(255);
}
else{
fill(200,200,200);
}
ellipse(x,y,w,w);
}
}
1