Moving buttons for a game
in
Programming Questions
•
10 months ago
Hi, I am a new programming student and for my school final, I am working on a mini game, where you have to shoot werewolves in a set amount of time. How can I make it so that the werewolf image is a button that you can click on it and after you click on it twice, it disappears? Really need the help, I have the girl shooting and the werewolf walking. Download in comment below >_<
- //DECLARING OBJECTS
Werewolf werewolf;
//BACKGROUND
float r = 0.8;
PImage bg;
//SHOOT LEFT
PImage shootleft;
//SHOOT RIGHT
PImage shootright;
//STAND
float v = 0.5;
PImage standleft;
PImage standright;
//SETUP
void setup() {
size (650, 700);
bg = loadImage ("bg_0.png"); //load background
standleft = loadImage ("stand_left.png"); //load standing left image
standright = loadImage ("stand_right.png"); //load standing right image
shootleft= loadImage ("shoot_left.png"); //load shooting left image
shootright= loadImage ("shoot_right.png"); //load shooting right image
werewolf = new Werewolf(); //load werewolf class
}
//DRAW
void draw() {
frameRate(10);
scale(v); //scale bg image
image(bg, 0, 0); //display bg image
scale (r); //scale Ellen image
if (mousePressed && mouseX> width/2) { //
image(shootright, 500, 850);
}
else if (mousePressed) {
image(shootleft, 500, 850);
}
else if (mouseX > width/2) {
image(standright, 500, 850);
}
else {
image(standleft, 500, 850);
}
werewolf.display(); //call display method
werewolf.movement();
} - class Werewolf {
float life; //life counter
int walk; //walk 8 images
int imageIndex; // start at image 0
int die; // death 7 images
int imageIndextwo; //start at image 0
float movement; //movement counter
float sizewolf; //scale wolf down
int xtwo; // x variable for position
PImage [] wolf; //wolf image walking to the left
PImage [] death; //death image walking to the left
boolean hit;
float tempX;
float tempY;
float tempW;
float tempH;
Werewolf() {
life = 2;
walk = 8;
die = 7;
imageIndex = 0;
imageIndextwo = 0;
movement = 3;
sizewolf = 0.9;
tempX = 0;
tempY = 0;
tempW = 0;
tempH = 0;
xtwo = 0;
wolf = new PImage [walk]; //left walk
death = new PImage [die]; // left death
hit = false;
for (int w = 0; w < wolf.length; w ++) {
wolf[w] = loadImage("wolf_walk_" + w + ".png");
}
for (int q = 0; q < death.length; q ++) {
death[q] = loadImage("wolf_death_" + q + ".png");
}
}
void display() {
image(wolf[imageIndex], xtwo+1386, 650);
imageIndex = (imageIndex + 1) % wolf.length;
}
void movement() {
xtwo-=4;
}
void lifecounter(int mx, int my) {
if (mx > tempX && mx < tempX + tempW && my > tempY && my < tempY + tempH) {
hit = !hit;
}
if (hit) {
life -= 1;
}
}
void deathdisplay() {
image(death[imageIndex], xtwo+1386, 650);
imageIndextwo = (imageIndextwo + 1) % death.length;
}
}
1