So I am making a game where you would click on randomly appearing circles, and for the sake of reusability and self-improvement I have chosen to use for loops and arrays for the first time.
After some unexpected results I have gotten this piece of code, and I have no idea what is causing it to completely not work.
The game would look like
aimbooster.com
float fRandomX,fRandomY;
int randomX, randomY;
void game() {
currentColor=colors[1];
for (int i=0; i==4; i++) {
fRandomX=random(20, 580);
fRandomY=random(20, 580);
randomX=round(fRandomX);
randomY=round(fRandomY);
targetX[i]=randomX;
targetY[i]=randomY;
}
for (int i = 0; i ==4; i++) {
ellipse(targetX[i], targetY[i], size/2.0, size/2.0);
}
}
If that Is not enough code,
int size=40, difficulty;
float targetDelay;
boolean hasStarted, hasLost, menuState, gameState;
int currentColor; // color system
int[] colors={#264653,#2A9D8F,#E9C46A,#F4A261};
int[] targetX, targetY;
int lastScore;
void setup(){
ellipseMode(CENTER);
rectMode(CORNERS);
size(600,600);
frameRate(60);
}
void draw(){
background(currentColor);
check();
debug();
}
void check(){
if(!hasStarted ||hasLost){
menuState=true; //run the menu
hasStarted=true; //dont run it again
hasLost=false; //reset game if lost
}
if(menuState){
menu(lastScore);
}else if(gameState){
game();
}
}
void menu(int score1){
currentColor=colors[0];
ellipse(100,100,30,30);//gameButton
text("last Score:"+score1,50,50);
}
void mousePressed(){
if(dist(mouseX,mouseY,100,100)<30){
gameState=true;
menuState=false;
}
}
void debug(){
text(mouseX+";"+mouseY,20,20);
}