Hi! Sorry, newcommer to processing, hoping I don’t mess up the guidelines.
The story so far:
I have a class called “blocks”. The colour, size and position of that box is defined through the main project in its signatur, because I want to be able to change the colour depending on what level.
Each individual block should turn black as I hover over it and stay black (as in invisible because the bg is also black).
But, I also want the game to be endless.
So when I win the game, it should reset with a keypress.
So. If I define the colour as red in main, and then in the blocks class, define that if mouseX and mouseY is over the block, it turns black, I usually just redefined the HEX value the variable “colour”.
But, since the game should be endless, that setting has to revert back to its original colour value once the game restarts.
I can’t just define the colour value again, cause it has to be able to be defined over the main project.
To my question:
So, how do I reference the colour value I defined in the main project again?
Thank you and I hope I explained everything understandably!
But because we can see only the class code and not the main program I had to kind of imagine the other variables at play.
For example, when you say:
Does endless here mean that there is an accumulation of a score that remains intact that you build upon when you reset?
Or does everything reset to the original default settings?
Also, regarding the boolean end in:
I’m assuming this is declared and initialized in the main program.
But cannot see how/or where in your main code you mark the event that the game is over. This may be key to understanding the issue.
Also, I played with your code a bit to understand the behavior you want.
A super simple working version to confirm this is the basic behavior you want to reset the color to the initial red. (?) With a few comments.
//////////////////////////////////////////////////////////////////////////////
int x = 150;
int y = 150;
int w = 100;
int h = 100;
boolean activated = false; //set to false/off before the mouse position is hovering over the rect
boolean invisible = false; //?? no info on how this fits into your main program
boolean end = false; //?? no info on how this fits into your main program
color col = color(255, 0, 0);
color black = color(0);
void setup() {
size(400, 400);
background(0);
fill(col); // initialize with red
rect (x, y, w, h);
}
void draw() {
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
activated = true;
} else {
activated = false;
}
if (activated) {
fill(black); // change to black after mouse position over rect, stays black until reset(any key is pressed)
rect (x, y, w, h);
}
if (keyPressed == true) {
fill(col);
rect (x, y, w, h);
} else {
fill(0); // need the else statement or reset to red does not work
}
}