Shooting Gallery type game, Hit detection.
in
Programming Questions
•
2 years ago
I need help, with a shooting gallery type game. Targets are going to pop up at random at a random location and you have to click them to score. What i currently need help with is the Random locations and the Hit detection. So far the enemy (smiley) just sits in the left corner of the program, and does nothing. I haven't got any hit detection at all, simply because i'm not to sure how to do it.
Here's my code so far:
float r;
float rx;
float ry;
float x;
float y;
float px;
float py;
PImage Ch;
PImage Bh;
float Bx;
float By;
float distance;
PImage Enemy;
int Score;
boolean bDisplay;
boolean bDisplay2;
boolean bDisplay3;
boolean bDisplay4;
boolean bDisplay5;
boolean bDisplay6;
boolean bDisplay7;
boolean bDisplay8;
boolean bDisplay9;
boolean bDisplay10;
color c =(255);
color col;
int enemyRadie = 50;
int i;
Smiley[] smiler = new Smiley[10];
PFont f;
float m;
class Smiley {
int x;
int y;
boolean visible;
PImage picture;
Smiley(PImage enemy, int px, int py) {
picture = enemy;
px = x;
py = y;
visible = true;
}
}
void setup()
{
size (800,600);
Ch = loadImage ("crosshairs.png");
Bh = loadImage ("BulletHole.png");
Enemy = loadImage ("Awesome Smiley.png");
Score = 0;
for(int i = 0; i < smiler.length; i++) {
smiler[i] = new Smiley(Enemy, (int)random(width-100), (int)random(height-100));
}
f = loadFont("Text.vlw");
}
void draw()
{
background(0,200,0);
textFont(f,25);
float r = random(0, 600);
float rx = random (0, 800);
float ry = random (0, 600);
float m = millis();
noCursor();
image (Ch, mouseX,mouseY);
for(int i = 0; i < smiler.length; i++) {
if(smiler[i].visible == true) {
image(smiler[i].picture, smiler[i].x, smiler[i].y);
}
}
text (Score, 25,25);
text (m, 700,25);
{
}
}
{
if (m >= 60000){
noLoop();
text ("Time's up. Your score is" +Score,200,200);
}
}
void mousePressed()
{
for (int i = 0; i <10; i++){
float distance = sqrt( px*px + py*py );}
if(distance <50){
bDisplay = false;
bDisplay2 = false;
bDisplay3 = false;
bDisplay4 = false;
bDisplay5 = false;
bDisplay6 = false;
bDisplay7 = false;
bDisplay8 = false;
bDisplay9 = false;
bDisplay10 = false;
println("Check");
Score = Score + 50;}
}
Here's my code so far:
float r;
float rx;
float ry;
float x;
float y;
float px;
float py;
PImage Ch;
PImage Bh;
float Bx;
float By;
float distance;
PImage Enemy;
int Score;
boolean bDisplay;
boolean bDisplay2;
boolean bDisplay3;
boolean bDisplay4;
boolean bDisplay5;
boolean bDisplay6;
boolean bDisplay7;
boolean bDisplay8;
boolean bDisplay9;
boolean bDisplay10;
color c =(255);
color col;
int enemyRadie = 50;
int i;
Smiley[] smiler = new Smiley[10];
PFont f;
float m;
class Smiley {
int x;
int y;
boolean visible;
PImage picture;
Smiley(PImage enemy, int px, int py) {
picture = enemy;
px = x;
py = y;
visible = true;
}
}
void setup()
{
size (800,600);
Ch = loadImage ("crosshairs.png");
Bh = loadImage ("BulletHole.png");
Enemy = loadImage ("Awesome Smiley.png");
Score = 0;
for(int i = 0; i < smiler.length; i++) {
smiler[i] = new Smiley(Enemy, (int)random(width-100), (int)random(height-100));
}
f = loadFont("Text.vlw");
}
void draw()
{
background(0,200,0);
textFont(f,25);
float r = random(0, 600);
float rx = random (0, 800);
float ry = random (0, 600);
float m = millis();
noCursor();
image (Ch, mouseX,mouseY);
for(int i = 0; i < smiler.length; i++) {
if(smiler[i].visible == true) {
image(smiler[i].picture, smiler[i].x, smiler[i].y);
}
}
text (Score, 25,25);
text (m, 700,25);
{
}
}
{
if (m >= 60000){
noLoop();
text ("Time's up. Your score is" +Score,200,200);
}
}
void mousePressed()
{
for (int i = 0; i <10; i++){
float distance = sqrt( px*px + py*py );}
if(distance <50){
bDisplay = false;
bDisplay2 = false;
bDisplay3 = false;
bDisplay4 = false;
bDisplay5 = false;
bDisplay6 = false;
bDisplay7 = false;
bDisplay8 = false;
bDisplay9 = false;
bDisplay10 = false;
println("Check");
Score = Score + 50;}
}
1