hi~
Now I am making a shooting game with processing for homework, and I really need some help as I am
new to this program. Any help and advice would be appreciated very, very much.
The game I want to make is something like below↓
First, some(about 10) circles, which look the same and represents balloons, are drawn on the background randomly.
Second, at the bottom of the background, there is an rectangle, and it works as needle that pops the circles.
The rectangle should be able to move horizontally as it follows the mouse. When mousePressed, the needle shoots up. While the needle can move, the circles should stay still.
Third, when the rectangle(needle) passes through the area of a circle, the circle gets erased. Here, I am considering
using dist() to count the distance between the circle and the rectangle and boolean().
(Fourth, the player has 3 chances of throwing the needle to pop all the circles.)
so far, i have programmed this..
First,
int numCircles = 10;
int [][] circles; // use a two-dimensional array
void setup() {
size(400, 400);
smooth();
noStroke();
circles = new int [numCircles][3]; // define the array, every circle needs three parameters (xPos, yPos, circleDiameter)
// fill array only once
for (int i=0; i<numCircles; i++) {
int circleDiameter=20;
int xPos = int(random(0 + circleDiameter/2, width - circleDiameter/2)); // keep distance from border
int yPos = int(random(0 + circleDiameter/2, height - circleDiameter/2)); // keep distance from border
circles[i][0]= xPos;
circles[i][1]= yPos;
circles[i][2]= circleDiameter; }}
void draw() {
for (int i=0; i<numCircles; i++) {
fill(121,3,254);
ellipse(circles[i][0], circles[i][1], circles[i][2],circles[i][2]); }}
Second, Third,
int y=380;
int x= mouseX;
float dist= sqrt((x-circles[i][0])*(x-circles[i][0])+ (y-circles[i][1])*
(y-circles[i][1]))
void setup(){
size(400, 400);
score=0;
}
void draw(){
background();
rect(x, y, 10, 10);
if(mousePressed==true){
for(int k=0; k<=380; k +=10){
y -= k; // the needle shoots up
}
}
if (dist>circles[i][2]){
int [][]circles=0;
}
the First one works, but the second&third do not seem to work.......