//Summer Bedard Processing Final //Code References: Rob Faludi, Daniel Shiffman //This code will mimick the prompt portrayed on the show "Lost" //import pitaru.sonia_v2_9.*; //import sonia (used Psound instead, sonia errors on export) PFont f; //font variable PImage b; //image variables PImage d; PImage happymick; PImage sadmick; String typing = ""; // Var to store text currently being typed String saved = ""; // Var to store saved text when return is hit String correct; //the code! //int x = 65; //variable I was going to use for my rectangle cursor //Sample mySample; // .wav sound file - for sonia PSound sound; //variables for timer int flip = 108; int counter = 1; int reset = 0; void setup() { size(550,440); f = loadFont("CourierNewPS-BoldMT-16.vlw"); sound = loadSound("lostalarm.wav"); b = loadImage ("screenfinal.jpg"); d = loadImage ("death.jpg"); happymick = loadImage("happymickey.jpg"); sadmick = loadImage ("sadmickey.jpg"); //Sonia.start(this); //Sample = new Sample("lostalarm.wav"); //sonia code for sound } void draw() { int indent = 45; background(b); correct ="4 8 15 16 23 42"; //fill(0,255,0); //was going to use this for cursor //rect (x,88,10,15); //counter code counter = counter % 5; counter++; //begin counter code if (counter == 1) { flip--; reset++; } if (reset > 108) { flip++; } if (flip == 108 && reset > 108) { flip = 108; reset = 0; } textFont (f,16); text (flip,465,365); //display my counter // end counter code // Set the font and fill for text to BRIGHT green fill(0,255,0); textFont(f); // Display everything text(":>",indent,100); text(typing+"[]",indent+20,100); fill(0,255,0); //evaluate input if (saved.equals(correct) == true) { image(happymick,150,100); // if the right code was typed, show happy mickey and text textSize(16); text ("Correct!",235,320); text ("You will live for at least 108 more seconds.", 55,340); if (flip<108 == true) { flip++; } } //if the wrong code was typed, show sad mickey, text, and play obnoxious noise if (saved.length() > 0 && saved.equals(correct) == false) { sound.play(); /*if (mySample.isPlaying() == false) { //sonia code for sound mySample.play(); }*/ image(sadmick,150,100); textSize(16); fill(255,0,0); text ("WRONG!", 235,320); text ("You have " + flip + " seconds to complete the code!", 70,340); } //otherwise, just tell em' to type the code! else { text("type the code!",300,100); } //if nothing is typed, keep counting down while (saved.length()==0 && flip==0 == true) { fill(255,0,0); textSize(25); image(d,0,0); flip--; } } //begin text to take and store typed input void keyPressed() { // If the return key is pressed, save the String and clear it and stop playing // the sound if it's playing if (key == '\n') { saved = typing; typing = ""; sound.stop(); //x=65; // variable for unused cursor //mySample.stop(); sonia code for sound } else if (key == BACKSPACE && typing.length() > 0) { // deleting text typing = typing.substring(0,typing.length()-1); // only delete text if it exists // x=x-10; // variable for unused cursor } else { // add each keypress to the previous ones typing = typing+key; // x = x+1; } } // Otherwise, concatenate the String with what the user pressed on the keyboard else { typing = typing + key; } }