New to processing, tic tac to game, confused on how to draw the X and O ...
in
Programming Questions
•
7 months ago
This is what I have so far. My problem is I know that in order for me to draw the circle or the X, I need to compare the mouseX and mouseY to the right, left, top and bottom boundaries of the tiles. I am not sure how to figure that out. did I set up my game board incorrectly? I am not allowed to use anything complex like matrices and such that is why this is really basic. Can someone please take some time to help me out, I am really desperate:
void setup() {
int width = 400;
int height = 400;
size(width,height);
}
void draw() {
background(0);
for(int i =0;i<width;i+=10){
for (int j=0;j<height;j+=10){
float my_distance = sqrt((i-mouseX)*(i-mouseX) + (j-mouseY)*(j-mouseY));
float dot_color = (my_distance*250)/(width/2);
stroke(dot_color);
fill(dot_color);
point(i,j);
}
}
int P1 = 50;
int P2 = 100;
int P3 = 150;
int P4 = 200;
stroke(0);
rect(P2,P2,P1,P1);
if(mousePressed == true){
if ((mouseX>P2)&&(mouseX<P4)&&(mouseY>0)&&(mouseY<P2)){
stroke(250);
fill(150);
ellipse(150,150,10,10);
}
}
rect(P4,P4,P1,P1);
rect(P4,P2,P1,P1);
rect(P2,P4,P1,P1);
rect(P3,P3,P1,P1);
fill(0);
rect(P3,P2,P1,P1);
rect(P2,P3,P1,P1);
rect(P3,P4,P1,P1);
rect(P4,P3,P1,P1);
}
Thank you so much in advance...
void setup() {
int width = 400;
int height = 400;
size(width,height);
}
void draw() {
background(0);
for(int i =0;i<width;i+=10){
for (int j=0;j<height;j+=10){
float my_distance = sqrt((i-mouseX)*(i-mouseX) + (j-mouseY)*(j-mouseY));
float dot_color = (my_distance*250)/(width/2);
stroke(dot_color);
fill(dot_color);
point(i,j);
}
}
int P1 = 50;
int P2 = 100;
int P3 = 150;
int P4 = 200;
stroke(0);
rect(P2,P2,P1,P1);
if(mousePressed == true){
if ((mouseX>P2)&&(mouseX<P4)&&(mouseY>0)&&(mouseY<P2)){
stroke(250);
fill(150);
ellipse(150,150,10,10);
}
}
rect(P4,P4,P1,P1);
rect(P4,P2,P1,P1);
rect(P2,P4,P1,P1);
rect(P3,P3,P1,P1);
fill(0);
rect(P3,P2,P1,P1);
rect(P2,P3,P1,P1);
rect(P3,P4,P1,P1);
rect(P4,P3,P1,P1);
}
Thank you so much in advance...
1