nfg_day7

code color fillColorOff = color(10,10,10); color fillColorOn = color(10,10,255); color fillColor = fillColorOff; float posX = 320; float posY = 180; float rectWidth = 20; float rectHeight = 20; boolean clicked = false; boolean sceneOne = true; boolean sceneTwo = false;
 * Ex.1 hitdetect and scenes**

void setup{ size(640,360); }

void draw{ if(sceneOne){ drawSceneOne; }  else if(sceneTwo){ drawSceneTwo; } }

void drawSceneOne{ background(200); if(clicked){ fillColor = fillColorOn; posX--; } else { fillColor = fillColorOff; } fill(fillColor); rectMode(CENTER); rect(posX,posY,rectWidth,rectHeight); if(posX<0){ sceneOne = false; sceneTwo = true; } }

void drawSceneTwo{ background(random(255)); }

void mousePressed{ if(hitDetect(mouseX,mouseY,0,0,posX,posY,rectWidth,rectHeight)){ clicked = true; } }

void mouseReleased{ }

boolean hitDetect(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2) { w1 /= 2; h1 /= 2; w2 /= 2; h2 /= 2; if(x1 + w1 >= x2 - w2 && x1 - w1 <= x2 + w2 && y1 + h1 >= y2 - h2 && y1 - h1 <= y2 + h2) { return true; }  else { return false; } }

code