HELP - Attempting to use mousepressed in a game
in
Programming Questions
•
6 months ago
Hey everyone, I could really use some help. Im trying to use mousepressed to be able to click on falling bombs but im not exactly sure how to do it. This is what I have so far. Any help would be amazing thanks!
Nazi r1;
PImage img;
PImage bg;
PImage CLDS;
import ddf.minim.*; //minim/ audio
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
int INTRO = 0; // Start screen
int RUN_GAME = 1; //Game
int gameState = INTRO; //start
int score=0; //Inital score
int lives=10; //lives you start with
int numBombs = 12;
Nazi[] bombs = new Nazi[numBombs]; // Declare and create the array
Minim minim;
AudioPlayer song;
//----------------------------------------------------------------------------
void setup() {
size(600,600);
smooth();
noStroke();
minim = new Minim(this);
song= minim.loadFile("Song1.mp3");
song.play();
song.loop();
img = loadImage("Untitled.png");
bg = loadImage("BG.jpg");
CLDS = loadImage("Clouds.png");
//Loop through array to create each object
for (int i = 0; i < bombs.length; i++) {
bombs[i] = new Nazi(); // Create each object
r1 = new Nazi();
}
}
//----------------------------------------------------------------------------//
void draw() {
if (gameState == INTRO) {
intro();
}
else if (gameState == RUN_GAME) {
run_game();
}
}
void intro() {
PImage z;
z = loadImage("http://i1086.photobucket.com/albums/j443/MrLukeyD/Nazi_Game_INTRO_zps5443b391.jpg");
z.resize(600, 600);
// first image you see, start screen
background(z);
}
//-----------------------------------------------------------------------
void run_game() {
background(bg);
//Loop through array to use objects.
for (int i = 0; i < bombs.length; i++) {
bombs[i].fall();
}
}
class Nazi {
float r = random(600);
float y = random(-height);
void fall() {
y = y+6;
image(CLDS,0,0);
image(img, r, y);
if(y>height){
r = random(600);
y = random(-200);
}
}
}
//------------------------------------------------------------------------
void keyPressed() {
if ( gameState == INTRO) {
if (key == ENTER || key == RETURN) {
gameState = RUN_GAME; // start the game
}
}
}
1