I have been working on a game for uni over the last week and have pieced together a mouse dodging game where the objective is to survive for as long as possible. The game is working fine but i want to clear up the code with classes and array lists. Ive looked at some tutorials on classes and arrays and understand their function but am having trouble incorporating it into the code. need classes for dropping objects and an array list for the amount on screen at once. Any help would be most appreciated thanks :)
code is as follows,
PImage enemy1; // Images for game
PImage enemy2;
PImage salmon;
PImage cover;
boolean startscreen = true; // functions for game starting and ending
boolean startgame = false;
boolean endgame = false;
int c; // variables for survival time
int jj = 0;
int rr;
int sec;
fill(0);
if (startgame == false){ // when game started make timer 0
rr =0+millis();
}
if (positionx1 >= 1390) { // if the position of x is beyond 1390, it gives it a new random y position and x is set to -50
positiony1 = random(0, 1390);
positionx1 = -50;
}
if (positionx2 >= 1390) {
positiony2 = random(0, 1390);
positionx2 = -50;
}
if (positionx3 >= 1390) {
positiony3 = random(0, 1390);
positionx3 = -50;
}
if (positiony4 >= 1390) {
positiony4 = random(0, 1390);
positionx4 = -50;
}
if (positiony5 >= 1390) {
positiony5 = random(0, 1390);
positionx5 = -50;
}
if (positiony6 >= 900) { // if the position if y is beyond 900, it gives it a new random x position and x is set to -50
positiony6 = -50;
positionx6 = random(0, 1390);
}
if (positiony7 >= 900) {
positiony7 = -50;
positionx7 = random(0, 1390);
}
if (positiony8 >= 900) {
positiony8 = -50;
positionx8 = random(0, 1390);
}
if (positiony9 >= 900) {
positiony9 = -50;
positionx9 = random(0, 1390);
}
if (positiony10 >= 900) {
positiony10 = -50;
positionx10 = random(0, 1390);
}
image(salmon, mouseX, mouseY, 40, 40); // salmon miages for the mouse
if(dist(mouseX, mouseY, positionx1, positiony1) <= 100){ // collision detection for the enemys with mouse
startscreen = true;
startgame = false;
}