Dragon’s Puzzler
Dragon’s Puzzler was one of the first programs that I made in my Computer Science program at The Evergreen State College.
A simple puzzle design that was inspired by the constraints imposed in our first programming exercise.
An attempt to inspire my peers to make interactive media with me.
Backstory:
A challenging puzzle that stumps bright minds. A lesson for a developer (me), that some bugs can be features. Otherwise, my first complete game. The only way to truly lose is to give up.
**Inspired by constraints imposed on our first programming exercise:
1. Make an animation using moving rectangles, triangles and ellipses, using setup() and draw().
2. Animation where not only the locations change, but other properties do in a regular progression, e.g. color, background strokeWeight(). What if only some of the geometric objects change?
3. Make an animation where properties change based on whether mousePressed is true or not.
Complete Processing Code:
/* Dragons HW1 9/28/17 This program is made to satisfy the following criteria: 1.Make an animation using moving rectangles, triangles and ellipses, using setup() and draw(). 2.animation where not only the locations change, but other properties do in a regular progression, e.g. color, background strokeWeight(). What if only some of the geometric objects change? 3.Make an animation where properties change based on whether mousePressed is true or not. */ PImage img; PImage imgScore; PImage imgWinner; PFont font; int playScreenX = 0; int playScreenY = 21; int maxResX = 800; int maxResY = 600; int headX = 360; boolean[] colorGate = new boolean[26]; //true = Green int[] squareX = new int[26]; int[] squareY = new int[26]; int redSquareStep = 0; int wincounter; int score = 0; int fillval1 = 190; int winningSceneX = 0;//do not change :) int winningSceneY = 0;//do not change :D boolean winScene = false; int deltaLoop = 0; String headText = "Dragon's Creative Cave... Turn all 25 of these blocks green to win."; void setup() { img = loadImage("dragonBG.jpeg"); imgScore = loadImage("Score.png"); imgWinner = loadImage("winnerWinner.png"); //font = createFont("DragonBreath.ttf", 32); size(800, 600); background(255); fill(30, 20, 150, 55); rect(0, 0, 800, 20); fill(0, 90, 190, 199); } void draw() { if(winScene== true){winScene();}else{ //win scene takes control of the environment, :) myBackground(); topbar(); scorewindow(); winCondition(); } buildGrid(); } void mouseClicked() { for (int i = 0; i < 25; i = i+1) { //Robust code, basically checking mouse coords in comparison of the square locations... essentially buttons :D if (mouseX > squareX[i] && mouseX < (squareX[i]+100) && mouseY > squareY[i] && mouseY < (squareY[i]+100) ) { //True Clause, if TRUE do this stuff!!! old //.. //new statement is a NOT colorGate[i] = !(colorGate[i]); if ((i -5)> 0){colorGate[i-5] = !(colorGate[i-5]);}; if ((i+5)< 25){colorGate[i+5] = !(colorGate[i+5]);}; if ((i-1)>= 0){colorGate[i-1] = !(colorGate[i-1]);}; if ((i+1)< 25){colorGate[i+1] = !(colorGate[i+1]);};//This is a bug but I am going to leave it for the puzzles sake //switch(i){ // case 0: // colorGate[] // greenSquare(squareX[i], squareY[i]); // break; //} } } } void topbar() { fill(0, 0, 0); rect(0, 0, 800, 20); fill(0, 255, 00, 80); textSize(18); text(headText, headX, 15); //Debugging text :D headX = headX - 2;//Speed of looping text, to increase speed -1, slow down +1; if (headX < -400) { headX = 800; } if (headX > 800) { headX = 0; } } void buildGrid() { for (int i = 0; i < 25; i = i+1) { //redSquare((i*100)+200, if (i <= 4){redSquare((i*100)+200+winningSceneX, 50+winningSceneY);};//row1 if (i >= 5 && i<=9){redSquare((i*100)-300+winningSceneX, 150+winningSceneY);};//row2 note:I know there is a better formula with the difference of 500... just not sure how to derive it atm. if (i >= 10 && i <=14){redSquare((i*100)-800+winningSceneX, 250+winningSceneY);};//row3 if (i >= 15 && i <=19){redSquare((i*100)-1300+winningSceneX, 350+winningSceneY);};//row4 if (i >= 20 && i <=24){redSquare((i*100)-1800+winningSceneX, 450+winningSceneY);};//row5 /* OLD CODE FOR CREATING THE SQUARES, ABOVE IS THE NEW CODE, IT IS NOT PERFECT BUT IT IS AN IMPROVEMENT. //row 1 redSquare(200, 50); redSquare(300, 50); redSquare(400, 50); redSquare(500, 50); redSquare(600, 50); //row 2 redSquare(200, 150); redSquare(300, 150); redSquare(400, 150); redSquare(500, 150); redSquare(600, 150); //row 3 redSquare(200, 250); redSquare(300, 250); redSquare(400, 250); redSquare(500, 250); redSquare(600, 250); //row 4 redSquare(200, 350); redSquare(300, 350); redSquare(400, 350); redSquare(500, 350); redSquare(600, 350); //row 5 redSquare(200, 450); redSquare(300, 450); redSquare(400, 450); redSquare(500, 450); redSquare(600, 450); */ if (i <= 4 && colorGate[i] == true){greenSquare((i*100)+200+winningSceneX, 50+winningSceneY);};//row1 if (i >= 5 && i<=9 && colorGate[i] == true){greenSquare((i*100)-300+winningSceneX, 150+winningSceneY);};//row2 note:I know there is a better formula with the difference of 500... just not sure how to derive it atm. if (i >= 10 && i <=14 && colorGate[i] == true){greenSquare((i*100)-800+winningSceneX, 250+winningSceneY);};//row3 if (i >= 15 && i <=19 && colorGate[i] == true){greenSquare((i*100)-1300+winningSceneX, 350+winningSceneY);};//row4 if (i >= 20 && i <=24 && colorGate[i] == true){greenSquare((i*100)-1800+winningSceneX, 450+winningSceneY);};//row5 } } void redSquare(int S, int T) { if (redSquareStep < 26) { //building a saved set of values that make up a table. Only records the first 0-24, (25) added 1 extra to pad. squareX[redSquareStep] = S; //sets the x value of the square into an array squareY[redSquareStep] = T; //sets the y value of the square into an array, used later to check the mouse position vs the boxes as well as finding the position to draw the green boxes redSquareStep=redSquareStep+1;//probably a vulnerability as if "<" gets changed to anything it may cause a buffer overflow thingy... } fill(255, 0, 0); stroke(0, 255, 0); rect(S, T, 100, 100); stroke(0); fill(0); } void greenSquare(int S, int T) { fill(0, 255, 0); stroke(0, 190, 22); rect(S, T, 100, 100); stroke(0); fill(0); } void scorewindow(){ image(imgScore, playScreenX+2, playScreenY+10, playScreenX+180, playScreenY+70); textSize(100); if(score < 0){ //negative score changes border and color of text to inspire! stroke(255, 0, 0);//color of border fill(70);//color of rect background rect(playScreenX+5, playScreenY+95, playScreenX+180, playScreenY+120); fill(180, 11, 11); text(score, playScreenX+8, playScreenY+200 ); } if(score >= 0 && score<=9){ stroke(255, 255, 255);//color of border fill(70);//color of rect background rect(playScreenX+5, playScreenY+95, playScreenX+180, playScreenY+120); fill(0, 190, 22); text(score, playScreenX+65, playScreenY+200 ); } if(score >= 10 && score<=100){ stroke(255, 255, 0);//color of border fill(70);//color of rect background rect(playScreenX+5, playScreenY+95, playScreenX+180, playScreenY+120); if (score >= 20){fillval1=fillval1 + 50;}; fill(0, fillval1, 22); text(score, playScreenX+30, playScreenY+200 ); } noStroke(); fill(0); } void myBackground() { //image(img, playScreenX, playScreenY, maxResX-playScreenX, maxResY-playScreenY); image(img, playScreenX, playScreenY); } void winCondition() {//Note that this function counts up and the value was equivalent to 0 at some point, (wincounter >= 0) failed lol... for (int i = 0; i < 25; i = i+1) { if (colorGate[i] == true) { wincounter++; } else { wincounter--; } // } if (wincounter >= 25) {//25 default //Winner winner, chicken dinner. headText = "WINNER, WINNER, CHICKEN DINNER!"; winScene = true; } score = wincounter; wincounter = 0; } void winScene(){ //Speed deltaLoop++; winningSceneX++; winningSceneY++; image(imgWinner, playScreenX+220, playScreenY+120); if (deltaLoop >= 1000){exit();} }