Code://Bear class
class Bear{
float r;
float x,y;
//Constructor
Bear(float tempR){
r=tempR;
x=0;
y=0;
}
void setLocation(float tempX, float tempY){
x=tempX;
y=tempY;
}
void displayBear(){
//Draw bounding-box for bear image.
ellipse(mouseX,mouseY+3,40,40);
//Draw bear icon to follow mouse.
image(normalBo,mouseX,mouseY, normalBo.width*.4, normalBo.height*.4);
}
void displayHurt(){
//Draw bounding-box for bear image.
ellipse(mouseX,mouseY+3,40,40);
//Draw happy bear icon to follow mouse.
image(hurtBo,mouseX,mouseY, hurtBo.width*.4, hurtBo.height*.4);
}
//Function to return true or false based on if bear intersects
//a honey pot
boolean intersect(Honey h){
//Calculate distance
float distance=dist(x,y,h.x,h.y);
//Compare distance to sum of radii
if(distance<r+h.r){
return true;
}
else {
return false;
}
}
boolean intersect(Bee b){
//Calculate distance
float distance=dist(x,y,b.x,b.y);
//Compare distance to sum of radii
if(distance<r+b.r){
return true;
}
else {
return false;
}
}
}
Code://Bee class.
class Bee{
float x;
float y;
float speed;
float r;
//Constructor
Bee(){
//Start the bees between 20 and 380.
x=random(20,380);
//Start the bees somewhere above screen.
y=-110;
//Start the bees at random speed
speed=random(1,4);
//Give bees' bounding-boxes a radius of 30.
r=25;
}
void display2(){
//Draw bouding-box behind bees.
ellipse(x,y,25,25);
//Draw bees.
image(bee,x,y,43,55);
}
//Move beesX across screen.
void moveX2(){
x=x+speed;
//If bees leaves screen, reset bee at x=0.
if(x>width){
x=0;
//When bee reappears, give a random y-coordinate and speed.
y=random(20,380);
if((keyPressed==true) && (key=='e') && (value==true)|| (keyPressed==true) && (key=='E') && (value==true)){
speed=random(1,4);
}
else if((keyPressed==true) && (key=='h') && (value==true) || (keyPressed==true) && (key=='H') && (value==true)){
speed=random(2,6);
}
}
}
//Move beesY down screen.
void moveY2(){
y=y+speed;
//If bee leaves screen, reset bee at y=0.
if(y>height){
y=0;
//When bee reappears, give a x-coordinate and speed.
x=random(20,480);
if((keyPressed==true) && (key=='e') && (value==true)|| (keyPressed==true) && (key=='E') && (value==true)){
speed=random(1,4);
}
else if((keyPressed==true) && (key=='h') && (value==true) || (keyPressed==true) && (key=='H') && (value==true)){
speed=random(2,6);
}
}
}
}
Code://Honey class.
class Honey{
float x;
float y;
float speed;
float r;
//Constructor
Honey(){
//Start the honey pots between 20 and 380.
x=random(20,380);
//Start the honey pots somewhere above screen.
y=-110;
//Start the honey pots at random speed.
speed=random(1,4);
//Give all honey pots' bounding boxes a radius of 30.
r=30;
}
//Move honeyX across screen.
void moveX1(){
x=x+speed;
//If honey pots leaves screen, reset honey pot at x=0.
if(x>width){
x=0;
//When a honey pot reappears
//give a random y-coordinate and speed.
y=random(20,380);
if((keyPressed==true) && (key=='e') && (value==true) || (keyPressed==true) && (key=='E') && (value==true)){
speed=random(1,4);
}else if((keyPressed==true) && (key=='h') && (value==true) || (keyPressed==true) && (key=='H') && (value==true)){
speed=random(2,6);
}
}
}
void display1(){
//Draw bounding-box behind honey pots.
ellipse(x,y,60,60);
//Draw honey pots.
image(honey,x,y, 60,60);
}
//Move honeyY down screen.
void moveY1(){
y=y+speed;
//If honey pot leaves screen, reset honey pot at y=0.
if(y>height){
y=0;
//When a honey pot reappears
//give a x-coordinate and speed.
x=random(20,480);
if((keyPressed==true) && (key=='e') && (value==true) || (keyPressed==true) && (key=='E') && (value==true)){
speed=random(1,4);
}else if((keyPressed==true) && (key=='h') && (value==true) || (keyPressed==true) && (key=='H') && (value==true)){
speed=random(2,6);
}
}
}
//If a horizontal honey pot is caught
void caughtX(){
//Give honey pot a random speed and y-coordinate.
speed=random(1,4);
x=0;
y=random(30,370);
//Increase score by 1 per honey pot.
currentScore++;
}
//If vertical honey pot is caught
void caughtY(){
//Give honey pot a random speed and x-coordinate
speed=random(1,4);
x=random(30,370);
y=0;
//Increase score by 1 per honey pot.
currentScore++;
}
}
I'm pretty sure the code's working, but, as I said before, I'd like the game to display and
stay displayed after I release the key. (I'm open to the possibility of replacing keyPresses with mouseClicks.)
Thanks for your time!