> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.iR$WugrB6RU/rev.6255
 * 
 * authors: 
 *   Benjamin Y

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// Pressing Control-R will render this sketch.
   
int i = 0; 
int playerX = 200;
int playerY = 200;
boolean onRoad = true;
boolean isCtrlPressed = false;
boolean isCtrlReleased = true;
boolean hasClickedHelp = false;
int moves = 0;
boolean lightsout = false;
   
void setup() {  // this is run once.   
       
    // set the background color
    background(0,204,0);
       
    // canvas size (Variable aren't evaluated. Integers only, please.)
    size(400, 400); 
         
    // smooth edges
    smooth();
       
    // limit the number of frames per second
    frameRate(10);
       
    // set the width of the line. 
    strokeWeight(12);
} 
   
boolean wreckCheck(int pX,int pY) {
    if (
       ((pX == 155 && pY <= 180) ||
         pX == 180 ||
         pX == 200 ||
         pX == 260 ||
        (pX == 290 && pY >= 20 && pY <= 180) ||
        (pX == 340 && pY >= 180 && pY <= 370)) ||
       ((pY == 20 && pX >= 160 && pX <= 290) ||
         pY == 125 ||
         pY == 180 ||
         pY == 200 ||
        (pY == 245 && pX >= 180 && pX <= 260) ||
        (pY == 370 && pX >= 200 && pX <= 370))) {
        return true;
    } else {
        return false;
    }
}
   
void move(int dX,int dY) {
    if (wreckCheck(playerX+dX,playerY+dY)) {
        playerX += dX;
        playerY += dY;
        moves += 1;
    }
}
   
int dist(int aX,int aY,int bX,int bY) {
    return sqrt(sq(aX-bX)+sq(aY-bY));
}
   
boolean mouse(int button) {
    if (button == 0 && mousePressed && mouseButton == LEFT) {
        return true;
    }
    if (button == 1 && mousePressed && mouseButton == RIGHT) {
        return true;
    }
    return false;
}
   
void draw() {  // this is run repeatedly.  
    background(0,204,0);
    noStroke();
    fill(0);
    if (isCtrlPressed) {
        text("CTRL",10,390);
    }
    text("HELP",350,10);
    if (mouseX >= 350 && mouseY <= 10 && mousePressed && !hasClickedHelp) {
        alert("Use arrow keys to move");
        alert("CTRL Shortcuts: \n Q: home, W: Point 1, E: Point 2, R: Point 3, A: Point 4, S: Point 5");
        hasClickedHelp = true;
    }
    fill(255,255,0);// sands
    ellipse(0,400,320,320);
    ellipse(200,400,110,110);
    ellipse(150,350,110,110);
    ellipse(300,400,230,230);
    ellipse(400,350,70,70);
    fill(0,204,0);
    ellipse(370,370,50,50);
    // water
    fill(0,0,255);
    ellipse(65,25,105,105);
       
    rect(0,0,65,65);
    stroke(0,0,255);
    line(0,340,125,340);
    line(125,340,265,300);
    line(265,300,350,245);
    line(350,245,390,160);
       
    line(0,155,130,165);
    line(130,165,250,160);
    line(250,160,400,160);
    stroke(102);
    noFill();
    // roads
    line(200,0,200,400);
    line(0,200,400,200);
    line(180,0,180,400);
    line(0,180,400,180);
    line(0,125,400,125);
    line(260,0,260,400);
    line(180,245,259,245);
    line(155,0,155,179);
    line(160,20,289,20);
    line(290,20,290,179);
    line(200,370,370,370);
    line(340,180,340,369);
    // destination points
    noStroke();
    fill(255,0,0);
    ellipse(245,110,15,15);
    ellipse(190,190,15,15);
    ellipse(380,360,15,15);
    ellipse(275,160,15,15);
    ellipse(190,370,15,15);
    fill(255,255,153);
    if (dist(mouseX,mouseY,245,110) <= 10) {
        rect(mouseX,mouseY,115,15);
        fill(0);
        text("The Daily Update",mouseX+5,mouseY+10);
        if (mouse(0)) {
            playerX = 260;
            playerY = 110;
        }
    }
    if (dist(mouseX,mouseY,190,190) <= 10) {
        rect(mouseX,mouseY,115,15);
        fill(0);
        text("Center Park",mouseX+5,mouseY+10);
        if (mouse(0)) {
            playerX = 180;
            playerY = 190;
        }
    }
    if (dist(mouseX,mouseY,380,360) <= 10) {
        rect(mouseX-115,mouseY,115,15);
        fill(0);
        text("City Airport",mouseX-110,mouseY+10);
        if (mouse(0)) {
            playerX = 370;
            playerY = 370;
        }
    }
    if (dist(mouseX,mouseY,275,160) <= 10) {
        rect(mouseX-115,mouseY,115,15);
        fill(0);
        text("East City Bridges",mouseX-110,mouseY+10);
        if (mouse(0)) {
            playerX = 290;
            playerY = 160;
        }
    }
    if (dist(mouseX,mouseY,190,370) <= 10) {
        rect(mouseX-115,mouseY,115,15);
        fill(0);
        text("Sandy Desert",mouseX-110,mouseY+10);
        if (mouse(0)) {
            playerX = 200;
            playerY = 370;
        }
    }
   
    // set the color
    stroke(random(50), random(255), random(255), 100);
    fill(255);
    ellipse(playerX,playerY,20,20);
    if (keyPressed) {
        if (key == CODED) {
            if (keyCode == UP) {
                move(0,-5);
            }
            if (keyCode == DOWN) {
                move(0,5);
            }
            if (keyCode == LEFT) {
                move(-5,0);
            }
            if (keyCode == RIGHT) {
                move(5,0);
            }
            if (keyCode == CONTROL && isCtrlReleased) {
                isCtrlPressed = !isCtrlPressed;
                isCtrlReleased = false;
            } else {
                isCtrlReleased = true;
            }
        } else {
            if (key == 'Q' || key == 'q') {
                if (isCtrlPressed) {
                    playerX = 200;
                    playerY = 200;
                    isCtrlPressed = false;
                    isCtrlReleased = true;
                }
            }
            if (key == 'W' || key == 'w') {
                if (isCtrlPressed) {
                    playerX = 245;
                    playerY = 125;
                    isCtrlPressed = false;
                    isCtrlReleased = true;
                }
            }
            if (key == 'E' || key == 'e') {
                if (isCtrlPressed) {
                    playerX = 180;
                    playerY = 190;
                    isCtrlPressed = false;
                    isCtrlReleased = true;
                }
            }
            if (key == 'R' || key == 'r') {
                if (isCtrlPressed) {
                    playerX = 370;
                    playerY = 370;
                    isCtrlPressed = false;
                    isCtrlReleased = true;
                }
            }
            if (key == 'A' || key == 'a') {
                if (isCtrlPressed) {
                    playerX = 290;
                    playerY = 160;
                    isCtrlPressed = false;
                    isCtrlReleased = true;
                }
            }
        }
    }
    noStroke();
    fill(255);
    if(!lightsout) {
        fill(0);
    }
    ellipse(20,20,10,10);
    if(dist(mouseX,mouseY,20,20) <= 5 && mousePressed) {
        lightsout = !lightsout;
    }
    if(lightsout) {
        noStroke();
        fill(0,0,0,204);
        rect(0,0,width,height);
        int ang;
        int rad;
        for (int i=0;i<500;i++) {
            fill(255,255,255,51);
            ang = random(0,TWO_PI);
            rad = random(100);
            ellipse(cos(ang)*rad+200,sin(ang)*rad+200,2,2);
        }
    }
    fill(0);
    int crosscheck = 0;
    int zi = 0;
    if (playerX == 155 && playerY <= 180) {
        text("Maffin Road",10,390);
        crosscheck += 1;
    } else if (playerX == 180) {
        text("Maddlefall Road",10,390);
        crosscheck += 1;
    } else if (playerX == 200) {
        text("Adfling Way",10,390);
        crosscheck += 1;
    } else if (playerX == 260) {
        text("Parry Street",10,390);
        crosscheck += 1;
    } else if (playerX == 290 && playerY >= 20 && playerY <= 180) {
        text("Arrengram Street",10,390);
        crosscheck += 1;
    } else if (playerX == 340 && playerY >= 180 && playerY <= 370) {
        text("Bunnongam Street",10,390);
        crosscheck += 1;
    }
    if (playerY == 20 && playerX >= 155 && playerX <= 290) {
        text("Arenca Street",10,370);
        zi = 90;
        crosscheck += 1;
    } else if (playerY == 125) {
        text("Gorban Road",10,370);
        zi = 90;
        crosscheck += 1;
    } else if (playerY == 180) {
        text("Major Street",10,370);
        zi = 80;
        crosscheck += 1;
    } else if (playerY == 200) {
        text("Minor Street",10,370);
        zi = 80;
        crosscheck += 1;
    } else if (playerY == 245 && playerX >= 180 && playerX <= 260) {
        text("Jumpna Street",10,370);
        zi = 90;
        crosscheck += 1;
    } else if (playerY == 370 && playerX >= 200 && playerX <= 370) {
        text("Airport Boulevard",10,370);
        zi = 110;
        crosscheck += 1;
    }
    if (crosscheck == 2) {
        text("&",zi,370);
    }
    i += 1;
}