We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to code a little game using a 10x10 grid. That's really all I have so far but what I would like to do is to have a random square in the grid change to a random color and if it's clicked within a second the player scores a point. I also have no idea how to put a little scoreboard above the grid because it will mess it up I think. Could anyone point me in the right direction? Here's what I have so far:
size(500, 500);
background(0);
stroke(255);
for(int i=0; i<width; i+=50)
{
line(i,0,i,height);
}
for(int w=0; w<height; w+=50)
{
line(0,w,width,w);
}
Any help is really appreciated. Thanks in advance.
Answers
so, first of all, you should format properly by highlighting your code in the text box and hitting the "C" at the top of the text editor ;)
you should create rectangles
edit: is the processing site down for you? processing.org
I just tried that now but I got an error saying "cannot convert from float to int" :( Yeah the sites down for me. Is it always like this?
this will change the rectangle you click on to a color, if you still need help just reply
edit: spawns random color now
there is no "losing" but if you click it will disappear otherwise, there is a new color and you can't win
I'm really lost now lol Not sure what everything is doing or where it's supposed to be
please don't post duplicate questions, it confuses people.
i have deleted the other.
the rectangle code you rejected was a better start imo.
break the problem into small steps.
use that code and work out how highlight a single rectangle (pick a random x and y, change the fill colour and redraw just that rectangle)
then work out how to map the current mouse position to a given rectangle within the grid. it's just a matter of division.
then check whether the clicked rect is the highlighted rect.
worry about the timing later.
and this is why we (some of us) don't just post full solutions without explanation but rather try and ask questions to get you thinking about things.
but 'Rejected Answer' 8(