/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://cisc1600.sketchpad.cc/sp/pad/view/ro.EVSZCitk3Np/rev.1053
*
* authors:
* David Kaner
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
//This sets up the starting frame count and the controllers starting position
int frame = 0;
float xpos = width + 270;
float ypos = height-55;
//This sets up the viewing size and frame rate
void setup() {
size(500, 500);
frameRate(30);
colorMode(RGB);
ellipseMode(CENTER);
}
// This sets up the starting layout
void draw() {
drawBoard(0,0);
drawPacman(xpos, ypos);
drawInstructions(0,0);
frame = frame+1 ;
drive();
}
// this is the message that is shown when you touch the blue walls
Void drawReset() {
text("GET OFF THE BLUE", width/2 -55, height/2 +5);
}
// this is the message that is shown when you get to the finish
Void drawCongratulations() {
text("To play again", width/2 -45, height/2-5);
text("press the render button", width/2 -60, height/2+10)
}
//This is the layout of the walls
void drawBoard(int x, int y) {
fill(15,15,255);
rect(0,0,500,500);
fill(255,255,255);
rect(15,15,485,485);
fill(255,15,15);
ellipse(120,42.5,55,55);
fill(15,15,255);
quad(485,485,15,485,15,500,485,500);
quad(500,500,500,15,485,15,485,500);
rect(15,270,100,-40);
rect(485,270,-100,-40);
rect(70,70,100,100);
rect(415,70,-100,100);
rect(70,415,100,-100);
rect(415,415,-100,-100);
rect(240,15,20,420);
rect(315,415,-55,-25);
rect(170,315,70,25);
rect(165,230,170,40);
fill(255,255,255);
}
//this is the player controlled icon and sets it's boundries
void drawPacman(int x, int y) {
if (frame %25) {
fill(0,255,0);
triangle(x + 15, y + 5, x- 15, y+5, x, y+ 20);
} else {
fill(255,255,255);
triangle(x+ 15, y, x- 15, y, x, y+ 15);
}
if (frame %25) {
fill(0,255,0);
triangle(x+ 15, y- 5, x- 15, y-5, x, y- 20);
} else{
fill(255,255,255);
triangle(x+ 15, y, x- 15, y, x, y- 15);
}
fill(255,255,255);
if (xpos-15 <15 || ypos-20 < 15 || xpos+15 > 485 || ypos+20>485){
drawReset(xpos,ypos);
} else if ( xpos+15>15 && ypos+20 >230 && xpos-15<115 && ypos-20<270){
drawReset(xpos,ypos);
} else if ( xpos+15>385 && ypos+20 >230 && xpos-15<485 && ypos-20<270){
drawReset(xpos,ypos);
} else if ( xpos+15>165 && ypos+20 >230 && xpos-15<335 && ypos-20<270){
drawReset(xpos,ypos);
} else if ( xpos+15>70 && ypos+20 >70 && xpos-15<170 && ypos-20<170){
drawReset(xpos,ypos);
} else if ( xpos+15> 315 && ypos+20 >70 && xpos-15<415 && ypos-20<170){
drawReset(xpos,ypos);
} else if ( xpos+15>70 && ypos+20 >315 && xpos-15<170 && ypos-20<415){
drawReset(xpos,ypos);
} else if ( xpos+15>315 && ypos+20 >315 && xpos-15<415 && ypos-20<415){
drawReset(xpos,ypos);
} else if ( xpos+15>240 && ypos+20 >15 && xpos-15<260 && ypos-20<435){
drawReset(xpos,ypos);
} else if ( xpos+15>170 && ypos+20 >315 && xpos-15<240 && ypos-20<340){
drawReset(xpos,ypos);
} else if ( xpos+15>260 && ypos+20 >390 && xpos-15<315 && ypos-20<415){
drawReset(xpos,ypos);
} else if ( xpos+15>120 && ypos+20 >42.5 && xpos-15<120 && ypos-20<42.5){
drawCongratulations(xpos,ypos)
}
}
// this sets up the instructions and the counter
void drawInstructions(int x, int y) {
text("Make Your Way",77.5 ,105 );
text("To The Red",90 ,125 );
text("Don't Touch",90 ,145 );
text("The Blue ",90 ,165 );
if ( xpos+15>120 && ypos+20 >42.5 && xpos-15<120 && ypos-20<42.5){
text("Congratulations",325 ,120 );
}else{
text(frame,355 ,120 );
};
text("UP KEY",100,345 );
text("GOES",105 ,355 );
text("UP",110 ,365 );
text("DOWN KEY",90 ,375 );
text("GOES",105 ,385);
text("DOWN",100 ,395);
text("LEFT KEY",340,345 );
text("GOES",350 ,355 );
text("LEFT",355 ,365 );
text("RIGHT KEY",335 ,375 );
text("GOES",350 ,385);
text("RIGHT",350 ,395);
text("FINSH",100,42.5);
}
// this establishes the control keys so the player can contol the icon
void drive() {
if( keyPressed == true && key == CODED ) {
if (keyCode == UP) {
ypos = ypos - 2;
} else if (keyCode == DOWN) {
ypos = ypos + 2;
} else if (keyCode == RIGHT) {
xpos = xpos + 2;
} else if (keyCode == LEFT) {
xpos = xpos - 2;
}
else if (keyCode == LEFT && keyCode == UP) {
xpos = xpos - 2;
ypos = ypos - 2;
}
}
}