Need help adding a "hit" counter
in
Programming Questions
•
5 months ago
I got the images to work here. Can I get some help on cleaning the hits up. It looks slopy, the laser doesn't show some of the time, the explosions only happen if you click in just the right area. I am not verry good at this, which i'm sure is apparent.
Still have no clue how to make a hit counter work. Any other thoughts.
PFont fontA;
float bombDiameter = 20;
boolean shoot = false;
PImage galaxy;
PImage bomb;
PImage explode;
int hit = 0;
int miss = 0;
int randx()
{
return int(random(800));
}
float bombDiameter = 20;
boolean shoot = false;
PImage galaxy;
PImage bomb;
PImage explode;
int hit = 0;
int miss = 0;
int randx()
{
return int(random(800));
}
int[] bombXCoords = {
randx(), randx(), randx(), randx(), randx()
}; // X cood. values for bomb array are random
int[] bombYCoords = {
0, 0, 0, 0, 0
}; // All bombs have a 0 y value to start.
randx(), randx(), randx(), randx(), randx()
}; // X cood. values for bomb array are random
int[] bombYCoords = {
0, 0, 0, 0, 0
}; // All bombs have a 0 y value to start.
void setup()
{
size(800, 700);
galaxy = loadImage("galaxy.jpg");
}
{
size(800, 700);
galaxy = loadImage("galaxy.jpg");
}
void draw()
{
background(galaxy);
fill(color(0, 255, 0));
stroke(color(0, 255, 0));
ellipseMode(CENTER);
ellipse(400, 700, 30, 30);
fill(color(255, 0, 0));
stroke(color(255, 0, 0));
{
background(galaxy);
fill(color(0, 255, 0));
stroke(color(0, 255, 0));
ellipseMode(CENTER);
ellipse(400, 700, 30, 30);
fill(color(255, 0, 0));
stroke(color(255, 0, 0));
if (shoot==true)
{
Laser(mouseX);
shoot = false;
}
{
Laser(mouseX);
shoot = false;
}
Bombs();
gameOver();
gameOver();
}
void mousePressed() // value for mousepressed
{
shoot = true;
}
{
shoot = true;
}
void Bombs()
{
stroke(255);
fill(255, 0, 0);
bomb = loadImage("bomb.png");
for (int i=0; i<5; i++)
{
image(bomb, bombXCoords[i], bombYCoords[i]++);
}
}
{
stroke(255);
fill(255, 0, 0);
bomb = loadImage("bomb.png");
for (int i=0; i<5; i++)
{
image(bomb, bombXCoords[i], bombYCoords[i]++);
}
}
void Laser(int shotX) // creates laser
{
{
boolean strike = false;
explode = loadImage("explode.png");
for (int i = 0; i < 5; i++)
{
if ((shotX >= ((bombXCoords[i])-bombDiameter)) && // paramiters to define a hit
(shotX <= (bombXCoords[i]+bombDiameter)))
{
strike = true;
line(400, 670, mouseX, bombYCoords[i]);
image(explode, bombXCoords[i], bombYCoords[i],
bombDiameter+75, bombDiameter+75);
bombXCoords[i] = randx(); // Moves hit bomb to random x-coordinate
bombYCoords[i] = 0; // Restet hit bomb to 0
}
}
explode = loadImage("explode.png");
for (int i = 0; i < 5; i++)
{
if ((shotX >= ((bombXCoords[i])-bombDiameter)) && // paramiters to define a hit
(shotX <= (bombXCoords[i]+bombDiameter)))
{
strike = true;
line(400, 670, mouseX, bombYCoords[i]);
image(explode, bombXCoords[i], bombYCoords[i],
bombDiameter+75, bombDiameter+75);
bombXCoords[i] = randx(); // Moves hit bomb to random x-coordinate
bombYCoords[i] = 0; // Restet hit bomb to 0
}
}
if (strike == false)
{
line(400, 670, mouseX, 0);
}
}
{
line(400, 670, mouseX, 0);
}
}
void gameOver()
{
for (int i=0; i< 5; i++)
{
if (bombYCoords[i]==800)
{
fill(color(255, 0, 0));
noLoop();
textSize(100);
text("GAME OVER", 100, 350);
}
}
}
{
for (int i=0; i< 5; i++)
{
if (bombYCoords[i]==800)
{
fill(color(255, 0, 0));
noLoop();
textSize(100);
text("GAME OVER", 100, 350);
}
}
}
1