Question
Must use software Processing 4 written in Java In this task, we going to develop a very simple fly swatter game. The mechanics are
Must use software Processing 4 written in Java
In this task, we going to develop a very simple fly swatter game. The mechanics are fairly basic - we have a fly swatter that is controlled by the mouse and some flies resting on the screen. It's up to the user to swat the flies by clicking their mouse. If they hit a fly, a satisfying mess will be left behind to clean up and the score will be incremented!
Below is a screenshot displaying the finished product. Good luck and happy coding!
Task
Your task is to develop a simple interactive graphical user interface using the Processing environment. The specific implementation details and images, as well as skeleton code, are provided, but if you wish to add any further details or use additional/alternative images, you are free to do so.
- The first task will be to get the images to appear on the screen and to set the interface size.
- Once this is complete, try to get the fly swatter object to follow the mouse around the screen.
- As this is a fictional exercise, the starting position of the flies can be randomly generated. With a new fly appended to memory each time one is swatted.
- The flies do not need to move around the screen and can stay in one position with the swatted version of the fly replacing the fly image.
- The swatter image should swap to the swatting image provided when the mouse button is clicked.
- A simple collision detection algorithm (bounding box), should be implemented to detect swats.
- A text object should be used to keep the score of the number of flies swatted.
- further effects can be added, this part is entirely up to you.
Main Code
PImage fly,flybye,swatter,swatted;
float[] fX,fY; // fly locations array
float[] swat; // fly swatted binary boolean array, 1 = swatted, 0 = not swatted
int score=0; // increments when swatted.
void setup(){
size(800,400);
fX=new float[0];
fY=new float[0];
swat=new float[0];
// load images
//fly = ;
//flybye = ;
//swatter = ;
//swatted = ;
fX =append(); //first fly - random location
fY =append();
swat =append(swat,0); // used as a boolean and matches to each individual fly, 0 = fly not swatted, 1 = swatted.
}
void populate(){ // draw the flies in memory to the screen.
for(int i=0;i if(swat[i]==1){ // if swatted
// resize the fly image and place based on fx/fy array values
image();
} else { // not swatted
image();
}
}
}
void collisionDetect(){ //collision detection - detect collision between swatter and fly
for(int i=0; i if(){ // condition should look at location of mouse and individual coordinates in fX and fY
swat[i] = 1; // swatted
fX =append(); //new fly placed in random location when old fly dies.
fY =append();
swat =append(swat,0); // new fly not swatted
score++; //increment score
}
}
}
void draw(){
background(255);
populate(); // draw flys to screen.
fill(0);
// set a text size and location for the score.
if(mousePressed){ // image swap
collisionDetect();
image(); //draw swatter image to around mouse locaiton - might want to play with this to get it to look right.
}else{
image(); // if not pressed then alternative image.
}
}
Referenced images
Step by Step Solution
There are 3 Steps involved in it
Step: 1
To implement the fly swatter game using Processing 4 in Java youll need to complete the code provided with the necessary image loading and functionali...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started