void draw () { cursor(CROSS); strokeWeight(1); background(161,140,198); // Display the square stroke(0); fill(100); fill (209,120,25); rect(0,350,800,700); fill(175); //spider head fill (0,mouseY,mouseX); ellipse (530,470,70,50); fill (255); ellipse (510,470,10,20); fill(0); ellipse (510,470,5,6); //spider body fill(mouseX,mouseY,0); ellipse (600,500,120,100); //spider legs strokeWeight (6); line (550,530,450,500); line (570,544,470,550); line (590,550, 540,590); line(450,500,380,560); line(470,550,400,620); line (540,590,500,650); //right hand side legs line(600,450, 650,400); line (630,454, 680,420); line (653,470, 700,440); line(650,400,730,380); line(680,420,770,440); line(700,440,800,490); strokeWeight (1); //fly strokeWeight (0); fill (255); ellipse(x,y-10,40,20); fill(170); ellipse(x,y,40,20); fill(0); ellipse(x+10,y,20,10); //cross hairs
line (mouseX-30,mouseY,mouseX-10,mouseY); line (mouseX+30,mouseY,mouseX+10,mouseY); line (mouseX,mouseY+30,mouseX,mouseY+10); line (mouseX,mouseY-30,mouseX,mouseY-10);
//path of fly
if (state == 0) { x = x + speed;
if (x > width-100) { x = width-100; state = 1; } } else if (state == 1) { y = y + speed; if (y > height-100) { y = height-100; state = 2; } } else if (state == 2) { x = x - speed; if (x < 150) { x = 150; state = 3; } } else if (state == 3) { y = y - speed; if (y<200) { y = 200; state= 4; } } else if (state == 4) { x = x + speed; if (x>600) { x = 600; state=5; } } else if (state == 5) { y = y + speed; if (y > 400) { y = 400; state=6; } } else if (state == 6) { x = x - speed; if (x < 500) { x = 500; state=7; } } else if (state ==7) { y = y - speed; if (y < 100) { y = 100; state=0; } }
if (state == 0) { x = x + speed;
if (x > width-100) { x = width-100; state = 1; } }strokeWeight(2); if (mousePressed == true) { line(495,470,mouseX,mouseY); } }
it may be a bit noobish,i know, but im following some processing tutorials at the moment and want to learn how to use it properly-
its a basic game - if u click-the spider shoots a web
my problem is....if i click on the fly...and only the fly< as if the spider was catching it>
how would i get a text to count it as a score....1...2..3..4 etc only when the fly is clicked.
not looking for any answers or anything, just want to learn how to do this
...so any one who can point me in the right direction it would be appreciated
Write a dynamic processing application for a screen size of 400 X 400 that moves a square at a 45degree angle continually from (200,0) to (0,200) to (200,400) to (400,200) and then backto (200,0). The square should change to a random color every time it hits an edge.
---- add-on : Any key press should change the direction of rotation of the square, anti clockwise to clockwise and vice-versa .
^^^^^question
//my code so
int x = 200;
int y = 0;
int speed = 5;
int state = 0;
float r = random (10);
float g = random (10);
float b = random (70);
void setup() {
size(400,400);
}
void draw() {
frameRate (30);
background(255);
stroke(0);
rect (x,y,30,30);
//Move to left center
if(state == 0) {
x -= speed ;
y += speed;
if(x <= 0 || y >= 200) {
x = 0;
y = 200;
fill(r,g,b);
state ++;
}
}
//Move to bottom center
else if(state == 1) {
x += speed ;
y += speed;
if(x >= 200 || y >= 370) {
x = 200;
y = 370;
fill(r,g,b);
state ++;
}
}
//Move to right side center
else if(state == 2) {
x += speed ;
y -= speed;
if(x >=380 || y <= 200) {
x = 380;
y = 200;
fill(r,g,b);
state ++;
}
}
//move back to top center
else if(state == 3) {
x -= speed ;
y -= speed;
if(x <= 200 || y <= 0) {
x = 200;
y = 0;
fill(r,g,b);
state = 0;
}
}
}
//i do not know how to make it change direction if a key is pressed , any help?