/** * A Tale of Two Santas: * * ... for christmas, all he wanted was to win a game */ CapsFont words; Speech sp; Key k; Keyboard board; CustomKey ck; Animation boyRun; int time; Dude duder; Snow snowfx; KleptoSanta ks; HypnoSanta hs; MrsClaus ms; boolean[] keysDown; boolean movementKeys[]; boolean upDownKeys[]; boolean hypnoMode = false; int[] hypnoPresses = new int[29]; int[] hypnoMap = new int[29]; String hypnoBuf = ""; HashMap hypnoToResponse; HashMap imagesDisplayed; HashMap discussed; ArrayList gifts; Response resp = null; PImage raptor_rights; boolean rights_triggered = false; PImage thoughtbub; void startHypnoMode(String hypText) { println("hypnostarted"); hypnoMode = true; for (int i = 0; i < hypnoPresses.length; i++) { hypnoPresses[i] = 0; hypnoMap[i] = 0; } hypnoBuf = ""; hypnoText = hypText.toUpperCase(); hypnoTextPos = 0; } void endHypnoMode() { hypnoMode = false; textBuf = ""; // textbuf has random stuff in it because that code isn't changed by hypnomode, so just clear it } boolean anyStolen = false; int MOVEKEY_LEFT = 0; int MOVEKEY_RIGHT = 1; int UDKEY_UP = 0; int UDKEY_DOWN = 1; int CODE_RET = 26; int CODE_BACKSPACE = 27; int CODE_SPACE = 28; String textBuf = ""; String emptyText = ""; String hypnoText = ""; int hypnoTextPos = 0; ArrayList introText; PImage frame; boolean flipped = false; boolean twinMode = false; PImage hintbird; ArrayList images = new ArrayList(); PImage managedRequestImage(String file) { PImage req = requestImage(file); images.add(req); return req; } int requestsSatisfied() { int sat = 0; for (int i = 0; i < images.size(); i++) { PImage img = (PImage)images.get(i); if (img.width != 0) sat++; } return sat; } int FRAMEWIDTH = 168; int FRAMEHEIGHT = 76; void setup() { size(525, 420); frameRate(50); hintbird = managedRequestImage("parakeet.gif"); raptor_rights = managedRequestImage("raptor_rights.gif"); keysDown = new boolean[29]; movementKeys = new boolean[2]; upDownKeys = new boolean[2]; for (int i = 0; i < 29; i++) { keysDown[i] = false; } for (int i = 0; i < 2; i++) { movementKeys[i] = false; upDownKeys[i] = false; } /* String loadPath = selectInput(); a = new Animation(loadPath, loadPath.substring(0,loadPath.length()-3) + "csv"); drag = new Draggable(a, new PVector(50,50)); // The file "jelly.jpg" must be in the data folder // of the current sketch to load successfully //a = loadImage(loadPath); // Load the image into the program fontA = createFont("FFScala", 15); textFont(fontA, 15); blah = new Button(new PVector(100,100), "the quick brown fox");*/ words = new CapsFont("alphabet.gif"); sp = new Speech(); k = new Key(words); ck = new CustomKey(words); board = new Keyboard(k, ck); boyRun = new Animation("boy_run.gif", "boy_run.csv"); time = 0; duder = new Dude(200,10+50*3); frame = managedRequestImage("frame.gif"); snowfx = new Snow(FRAMEWIDTH, FRAMEHEIGHT); ks = new KleptoSanta(10+10*3, 10+48*3, time, false); hs = new HypnoSanta(10+(FRAMEWIDTH-10-16)*3, 10+48*3, time, true); ms = new MrsClaus(200+14*3,10+48*3,time,true); thoughtbub = managedRequestImage("thoughtbubble.gif"); hypnoToResponse = new HashMap(); hypnoToResponse.put("RAPTOR WEDDINGS", new Response("i am so with you on that", "take it to the courts man")); hypnoToResponse.put("TO WIG", new Response("you go on and wig out man", "dont let me stop you")); hypnoToResponse.put("RAPTOR INS", new Response("youre already cool with the raptors", "they love you for your flesh")); hypnoToResponse.put("RAPTOR IN", new Response("youre already cool with the raptors", "they love you for your flesh")); hypnoToResponse.put("RAPTOR WIGS", new Response("raptors did not wear wigs", "sorry but that is a fact")); hypnoToResponse.put("RAPTOR WIG", new Response("raptors did not wear wigs", "sorry but that is a fact")); hypnoToResponse.put("RAPTOR WINGS", new Response("raptors wings are too powerful", "they would break game balance")); hypnoToResponse.put("AI", new Response("I AM AFRAID I CANNOT LET YOU HAVE THAT", "DAVE")); hypnoToResponse.put("ADD", new Response("I cannot give the give of knowledge", "do you think this is edutainment")); hypnoToResponse.put("APT", new Response("I have just the place", "a lakefront property you will love")); hypnoToResponse.put("AW", new Response("cute?")); hypnoToResponse.put("AWE", new Response("Feel it in your bones boy")); PImage apepic = managedRequestImage("present_ape.gif"); hypnoToResponse.put("APE", new Response("okay have a damn dirty ape", null, apepic)); hypnoToResponse.put("APES", new Response("okay have a damn dirty ape", null, apepic)); hypnoToResponse.put("INS", new Response("You are now all up ins", "congratulations")); hypnoToResponse.put("IS", new Response("information services are on coffee break", "come back next year")); hypnoToResponse.put("ODD", new Response("Quite")); hypnoToResponse.put("ODDS", new Response("with complementary ends", null, managedRequestImage("present_odds.gif"))); hypnoToResponse.put("OWE", new Response("Debt for xmas?", "Surely you jest")); hypnoToResponse.put("OWES", new Response("Debt for xmas?", "Surely you jest")); hypnoToResponse.put("OWING", new Response("Debt for xmas?", "Surely you jest")); hypnoToResponse.put("PE", new Response("Consider yourself physically educated", null, managedRequestImage("present_muscles.gif"))); PImage pegpic = managedRequestImage("present_peg.gif"); hypnoToResponse.put("PEG", new Response("okay here is a peg", "it is general purpose",pegpic)); hypnoToResponse.put("PEGS", new Response("okay here is a peg", "it is general purpose",pegpic)); PImage raptorpic = managedRequestImage("present_raptor.gif"); hypnoToResponse.put("RAPTOR", new Response("here is your raptor then", null, raptorpic)); hypnoToResponse.put("RAPTORS", new Response("here is your raptor then", null, raptorpic)); PImage penpic = managedRequestImage("present_pen.gif"); hypnoToResponse.put("PEN", new Response("happy writings",null,penpic)); hypnoToResponse.put("PENS", new Response("happy writings",null,penpic)); hypnoToResponse.put("PI", new Response("okay nerd",null,managedRequestImage("present_pi.gif"))); PImage pigpic = managedRequestImage("present_pig.gif"); hypnoToResponse.put("PIG", new Response("OINK OINK",null,pigpic)); hypnoToResponse.put("PIGS", new Response("OINK OINK",null,pigpic)); hypnoToResponse.put("PING", new Response("PONG")); hypnoToResponse.put("PNG", new Response("the PNG format is free dude")); PImage pinpic = managedRequestImage("present_pin.gif"); hypnoToResponse.put("PIN", new Response("you be careful with that now",null,pinpic)); hypnoToResponse.put("PINS", new Response("you be careful with that now",null,pinpic)); hypnoToResponse.put("PINGS", new Response("pongs")); hypnoToResponse.put("PODDING", new Response("for what kind of plant?")); hypnoToResponse.put("POI", new Response("I do not even know what this is", "apparently it is edible", managedRequestImage("present_poi.gif"))); hypnoToResponse.put("PONG", new Response("you kids", "with your video games")); hypnoToResponse.put("PONGS", new Response("you kids", "with your video games")); PImage powpic = managedRequestImage("present_pow.gif"); hypnoToResponse.put("POW", new Response("ZAP",null,powpic)); hypnoToResponse.put("POWS", new Response("ZAP",null,powpic)); hypnoToResponse.put("RARES", new Response("all my rares are dragons", null, managedRequestImage("present_rares.gif"))); PImage tegpic = managedRequestImage("present_sheep.gif"); hypnoToResponse.put("TEG", new Response("your sheep is inside this box", null, tegpic)); hypnoToResponse.put("TEGS", new Response("your sheep is inside this box", null, tegpic)); PImage tenpic = managedRequestImage("present_ten.gif"); hypnoToResponse.put("TEN", new Response("here you go",null,tenpic)); hypnoToResponse.put("TENS", new Response("how many do you want",null,tenpic)); PImage tinpic = managedRequestImage("present_tin.gif"); hypnoToResponse.put("TIN", new Response("a tin could always come in handy",null,tinpic)); hypnoToResponse.put("TINS", new Response("a tin could always come in handy",null,tinpic)); hypnoToResponse.put("TING", new Response("SFX not implemented", "i am tired")); hypnoToResponse.put("TINGS", new Response("SFX not implemented", "i am tired")); PImage toepic = managedRequestImage("present_toe.gif"); hypnoToResponse.put("TOE", new Response("I can get you a toe",null,toepic)); hypnoToResponse.put("TOES", new Response("I can get you toes","how many you need?",toepic)); PImage togpic = managedRequestImage("present_tog.gif"); hypnoToResponse.put("TOG", new Response("this should keep you warm", null, togpic)); hypnoToResponse.put("TOGS", new Response("this should keep you warm", null, togpic)); PImage tonpic = managedRequestImage("present_ton.gif"); hypnoToResponse.put("TON", new Response("OKAY but if you are hunting birds","just use a gun",tonpic)); hypnoToResponse.put("TONS", new Response("OKAY but if you are hunting birds","just use a gun",tonpic)); PImage tongpic = managedRequestImage("present_tong.gif"); hypnoToResponse.put("TONGS", new Response("here you go", null, tongpic)); hypnoToResponse.put("TONG", new Response("here you go", null, tongpic)); PImage townpic = managedRequestImage("present_town.gif"); hypnoToResponse.put("TOWN", new Response("A whole town","wow",townpic)); hypnoToResponse.put("TOWNS", new Response("You are becoming quite the little dictator",null,townpic)); PImage twigpic = managedRequestImage("present_twig.gif"); hypnoToResponse.put("TWIG", new Response("HERE YOU GO", null, twigpic)); hypnoToResponse.put("TWIGS", new Response("HERE YOU GO", null, twigpic)); hypnoToResponse.put("TWIN", new Response("HERE IS YOUR TWIN", "YOU TWO ARE SO MUCH ALIKE")); hypnoToResponse.put("TWINS", new Response("HERE IS YOUR TWIN", "YOU TWO ARE SO MUCH ALIKE")); hypnoToResponse.put("A WEDDINGS", new Response("and who is to be wed?")); hypnoToResponse.put("A WEDDING", new Response("and who is to be wed?")); hypnoToResponse.put("WEDDING", new Response("and who is to be wed?")); hypnoToResponse.put("WEDDINGS", new Response("and who is to be wed?")); PImage wenpic = managedRequestImage("present_wen.gif"); hypnoToResponse.put("A WEN", new Response("i guess this is a wen", null, wenpic)); hypnoToResponse.put("WEN", new Response("i guess this is a wen", null, wenpic)); hypnoToResponse.put("WENS", new Response("i guess this is a wen", null, wenpic)); PImage wigpic = managedRequestImage("present_wig.gif"); hypnoToResponse.put("A WIG", new Response("good choice","i myself am a man of many guises", wigpic)); hypnoToResponse.put("WIG", new Response("good choice","i myself am a man of many guises", wigpic)); hypnoToResponse.put("WIGS", new Response("good choice","i myself am a man of many guises", wigpic)); PImage wingpic = managedRequestImage("present_wing.gif"); hypnoToResponse.put("WING", new Response("I believe you can fly", null, wingpic)); hypnoToResponse.put("WINGS", new Response("I believe you can fly", null, wingpic)); PImage wispic = managedRequestImage("present_wis.gif"); hypnoToResponse.put("WIS", new Response("i guess i can give you wisconsin","who would care?",wispic)); PImage winpic = managedRequestImage("present_win.gif"); hypnoToResponse.put("WIN", new Response("congrats you win", "who knew life was so easy?",winpic)); hypnoToResponse.put("TO WIN", new Response("congrats you win", "who knew life was so easy?",winpic)); hypnoToResponse.put("WINS", new Response("congrats you win", "who knew life was so easy?",winpic)); hypnoToResponse.put("TO WINS", new Response("congrats you win", "who knew life was so easy?",winpic)); hypnoToResponse.put("A WIN", new Response("congrats you win", "who knew life was so easy?",winpic)); hypnoToResponse.put("A WINS", new Response("congrats you win", "who knew life was so easy?",winpic)); introText = new ArrayList(); introText.add("hello there"); introText.add("i am running to the north pole"); introText.add("when i wrote a letter to santa"); introText.add("my dad broke it down for me"); introText.add("santa will not read it because"); introText.add("santa is illiterate"); introText.add("santa is a demigod"); introText.add("he does not have time for letters"); introText.add("if I want anything for xmas"); introText.add("I should talk to the man himself"); introText.add("or men"); introText.add("there are two of them see"); introText.add("a kleptomaniac and a hypnotist"); introText.add("and mrs claus is around too"); introText.add("if you want to see her"); introText.add("just talk to the darkness"); introText.add("anyway"); introText.add("that is just what my dad said"); introText.add("hopefully it is correct"); introText.add("I have been walking"); introText.add("for such a long time"); gifts = new ArrayList(); /* // code to test pics gifts.add(apepic); gifts.add(loadImage("present_muscles.gif")); gifts.add(loadImage("present_peg.gif")); gifts.add(loadImage("present_odds.gif")); gifts.add(loadImage("present_pen.gif")); gifts.add(loadImage("present_pi.gif")); gifts.add(loadImage("present_pin.gif")); gifts.add(loadImage("present_poi.gif")); gifts.add(loadImage("present_pow.gif")); gifts.add(loadImage("present_raptor.gif")); gifts.add(loadImage("present_rares.gif")); gifts.add(loadImage("present_sheep.gif")); gifts.add(loadImage("present_ten.gif")); gifts.add(loadImage("present_tin.gif")); gifts.add(loadImage("present_toe.gif")); gifts.add(loadImage("present_tog.gif")); gifts.add(loadImage("present_ton.gif")); gifts.add(loadImage("present_tong.gif")); gifts.add(loadImage("present_town.gif")); gifts.add(loadImage("present_twig.gif")); gifts.add(loadImage("present_wen.gif")); gifts.add(loadImage("present_wing.gif")); gifts.add(loadImage("present_wis.gif")); gifts.add(loadImage("present_wig.gif")); */ imagesDisplayed = new HashMap(); discussed = new HashMap(); hints = new String[HINT_MISC5+1]; seenCount = new int[HINT_MISC5+1]; minTime = new int[HINT_MISC5+1]; maxSeen = new int[HINT_MISC5+1]; hints[HINT_MOVE] = "use arrow keys baaaak arrows"; seenCount[HINT_MOVE] = 0; maxSeen[HINT_MOVE] = 2; minTime[HINT_MOVE] = 1200; hints[HINT_LETTERS] = "try the letter keys baak"; seenCount[HINT_LETTERS] = 0; maxSeen[HINT_LETTERS] = 2; minTime[HINT_LETTERS] = 0; hints[HINT_PRESENTS] = "baaak polly wanna present"; seenCount[HINT_PRESENTS] = 0; maxSeen[HINT_PRESENTS] = 2; minTime[HINT_PRESENTS] = 1600; hints[HINT_TRY_OTHER_SANTA] = "polly love both santa"; seenCount[HINT_TRY_OTHER_SANTA] = 0; maxSeen[HINT_TRY_OTHER_SANTA] = 3; minTime[HINT_TRY_OTHER_SANTA] = 1200; hints[HINT_MRS_CLAUS] = "polly see mrs claus in the darkness"; seenCount[HINT_MRS_CLAUS] = 0; maxSeen[HINT_MRS_CLAUS] = 2; minTime[HINT_MRS_CLAUS] = 5000; hints[HINT_MRS_CLAUS2] = "POLLY SAY hello to darkness"; seenCount[HINT_MRS_CLAUS2] = 0; maxSeen[HINT_MRS_CLAUS2] = 2; minTime[HINT_MRS_CLAUS2] = 1000; hints[HINT_ASK_FOR_SOMETHING] = "raptor weddings raptor weddings"; seenCount[HINT_ASK_FOR_SOMETHING] = 0; maxSeen[HINT_ASK_FOR_SOMETHING] = 2; minTime[HINT_ASK_FOR_SOMETHING] = 3000; hints[HINT_WHAT_YOU_WANT] = "polly just ask santa to win"; seenCount[HINT_WHAT_YOU_WANT] = 0; maxSeen[HINT_WHAT_YOU_WANT] = 1; minTime[HINT_WHAT_YOU_WANT] = 15000; hints[HINT_MISC] = "baaak polly just clearing throat"; seenCount[HINT_MISC] = 0; maxSeen[HINT_MISC] = 2; minTime[HINT_MISC] = 1200; hints[HINT_MISC2] = "polly went to hahvahd you know"; seenCount[HINT_MISC2] = 0; maxSeen[HINT_MISC2] = 2; minTime[HINT_MISC2] = 9000; hints[HINT_MISC3] = "polly does not care for crackers"; seenCount[HINT_MISC3] = 0; maxSeen[HINT_MISC3] = 2; minTime[HINT_MISC3] = 600; hints[HINT_MISC4] = "polly remove olly get p"; seenCount[HINT_MISC4] = 0; maxSeen[HINT_MISC4] = 2; minTime[HINT_MISC4] = 3600; hints[HINT_MISC5] = "polly miss good weather"; seenCount[HINT_MISC5] = 0; maxSeen[HINT_MISC5] = 2; minTime[HINT_MISC5] = 800; fws = new FireworksShow(FRAMEWIDTH, FRAMEHEIGHT); } FireworksShow fws; String[] hints; int[] seenCount; int[] minTime; int[] maxSeen; int HINT_MOVE = 0; int HINT_LETTERS = 1; int HINT_PRESENTS = 2; int HINT_TRY_OTHER_SANTA = 3; int HINT_MRS_CLAUS = 4; int HINT_MRS_CLAUS2 = 5; int HINT_ASK_FOR_SOMETHING = 6; int HINT_WHAT_YOU_WANT = 7; int HINT_MISC = 8; int HINT_MISC2 = 9; int HINT_MISC3 = 10; int HINT_MISC4 = 11; int HINT_MISC5 = 12; // broad game state info // a lot of the more specific state info can be stored separately // for example in the class for the relevant character int GAME_INTRO = -1; int GAME_ROAM = 0; int GAME_KSANTA = 1; int GAME_HSANTA = 2; int GAME_MCLAUS = 3; int GAME_WON = 4; int gameState = GAME_INTRO; boolean talkedToHSanta = false; boolean talkedToKSanta = false; boolean hasWings = false; boolean hasWon = false; int introPressState = 0; int hintTimer = 0; int timeHintGiven = -1; int lastHint = -1; String currentHint = ""; boolean pongActive = false; int lpaddle = 50; int rpaddle = 50; int ballx = 200, bally = 100; int balldx = 1; int balldy = 1; void draw() { int reqsat = requestsSatisfied(); if (reqsat < images.size()) { background(0,128,0); fill(200,10,10); stroke(100,30,30); rect(50,200,425 * reqsat / images.size(),20); return; } if (gameState == GAME_INTRO) { background(128,0,0); fill(50,100,50); stroke(50,100,50); rect(11,11,frame.width*3-2, frame.height*3-2); snowfx.Draw(10, 10, 3); image(frame, 10, 10, frame.width*3, frame.height*3); board.Draw(30,10+80*3,3); words.Draw(23,33,"A TALE OF TWO SANTAS",4); // words.Draw(110,100,"TWO SANTAS",5); //words.Draw(200,170,"by zaphos", 2); //words.Draw(50,185,"control with letters and arrow keys", 2); words.Draw(130,80,"press any key to start", 2); int lineNo = time / 150; if (lineNo >= introText.size()) lineNo = introText.size() - 1; duder.xpos = 50; sp.DrawFromBot(duder.xpos,duder.ypos+6,(String)introText.get(lineNo),3,33,true); duder.state = STATE_MOVE; duder.DrawNoInput(time, 3); duder.xpos = 200; if (!keyPressed && introPressState == 0) { introPressState = 1; } if (keyPressed && introPressState == 1) { introPressState = 2; } if (!keyPressed && introPressState == 2) { gameState = GAME_MCLAUS; textBuf = ""; introPressState = 0; } time++; return; } if (gameState == GAME_WON) { // note -- I removed this, so, you shouldn't be able to actually get to this game state ... hasWon = true; maxSeen[HINT_WHAT_YOU_WANT] = 0; background(128,0,0); fill(200); stroke(200); rect(11,11,frame.width*3-2, frame.height*3-2); image(frame, 10, 10, frame.width*3, frame.height*3); board.Draw(30,10+80*3,3); words.Draw(40,60,"CONGRATULATIONS",5); words.Draw(160,120,"YOU WON",5); // words.Draw(200,170,"", 2); //words.Draw(50,185,"control with letters and arrow keys", 2); words.Draw(70,200,"press any key to continue anyway", 2); if (!keyPressed && introPressState == 0) { introPressState = 1; } if (keyPressed && introPressState == 1) { introPressState = 2; } if (!keyPressed && introPressState == 2) { gameState = GAME_MCLAUS; textBuf = ""; introPressState = 0; } return; } // the basic layout background(128,0,0); fill(0); stroke(0); rect(11,11,frame.width*3-2, frame.height*3-2); if (hasWon) fws.Draw(10,10,3); snowfx.Draw(10, 10, 3); if (pongActive) { stroke(255); fill(255); if (upDownKeys[UDKEY_UP]) lpaddle -= 3; if (upDownKeys[UDKEY_DOWN]) lpaddle += 3; if (bally < rpaddle + 15 - 10) rpaddle -= 3; else if (bally > rpaddle + 15 + 10) rpaddle += 3; if (rpaddle < 10) rpaddle = 10; if (rpaddle > 200) rpaddle = 200; if (lpaddle < 10) lpaddle = 10; if (lpaddle > 200) lpaddle = 200; if (ballx < 25+4 && ballx > 25) { if (bally + 4 >= lpaddle && bally - 4 <= lpaddle + 30) { balldx = -balldx; balldy = (bally - (lpaddle + 15)) / 5; } } if (ballx > 10+frame.width*3-20-4 && ballx < 10+frame.width*3-20) { if (bally + 4 >= rpaddle && bally - 4 <= rpaddle + 30) { balldx = -balldx; balldy = (bally - (rpaddle + 15)) / 5; } } rect(25,lpaddle,3,30); rect(10+frame.width*3-20,rpaddle,3,30); ellipse(ballx,bally,4,4); ballx += balldx*2; bally += balldy*2; if (ballx < 18) { ballx = 150; bally = 100; balldx = -balldx; balldy = int(random(-2,2)); // println(balldy); } if (ballx > frame.width*3) { ballx = 150; bally = 100; balldx = -balldx; balldy = int(random(-2,2)); // println(balldy); } if (bally > 230) { bally = 230; balldy = -balldy; } if (bally < 17) { bally = 17; balldy = -balldy; } } image(frame, 10, 10, frame.width*3, frame.height*3); board.Draw(30,10+80*3,3); for (int i = 0; i < gifts.size(); i++) { PImage pic = (PImage)gifts.get(i); int row = i / 12; int col = i % 12; image(pic, col * 2 * 18 + 35, row * 2 * 18 + 23, pic.width*2, pic.height*2); } if (rights_triggered) image(raptor_rights,hs.xpos-20*3, hs.ypos-9*3, raptor_rights.width*3, raptor_rights.height*3); /* int hintTimer = 0; int timeHintGiven = -1; String currentHint = ""; */ hintTimer++; if (textBuf.length() > 0 || failedPress) { maxSeen[HINT_LETTERS] = 0; } if (talkedToHSanta && talkedToKSanta) { maxSeen[HINT_TRY_OTHER_SANTA] = 0; } // decide if we want to spawn if (currentHint.length() == 0) { // default don't talk until at least 6 seconds pass -- give some adjustment time! if (hintTimer - timeHintGiven > 550 && random(1) > .995 && hintTimer > 600) { int selection = -1; int considered = 0; for (int i = 0; i < hints.length; i++) { if (seenCount[i] < maxSeen[i] && hintTimer > minTime[i] && lastHint != i) { if ((i == HINT_MRS_CLAUS || i == HINT_MRS_CLAUS2) && anyStolen == false) { continue; } if (i == HINT_PRESENTS) considered *= 2; if (i == HINT_MISC) // weight down misc hints considered *= 2; considered++; if (random(1) < 1/float(considered)) { println("selected " + i); selection = i; } } } if (selection != -1) { println("selected hint " + hints[selection]); timeHintGiven = hintTimer; currentHint = hints[selection]; seenCount[selection]++; lastHint = selection; } } } else { if (hintTimer - timeHintGiven > 300) { currentHint = ""; } } sp.DrawFromBot( 10 + frame.width*3 - 12*3 - 12, 70, currentHint,3,40); image(hintbird, 10 + frame.width*3 - 12*3, 65, hintbird.width*3, hintbird.height*3); sp.DrawFromBot(duder.xpos,duder.ypos+6,emptyText,3,15); if (duder.xpos <= 10 + (10+20)*3) { duder.xpos = 10 + (10+20)*3; duder.WallHit(-1); } else if (duder.xpos >= 10 + (frame.width-10-20-8)*3) { duder.xpos = 10 + (frame.width-10-20-8)*3; duder.WallHit(1); } if (hasWings) { if (upDownKeys[UDKEY_UP]) { duder.ypos -= 2; } if (upDownKeys[UDKEY_DOWN]) { duder.ypos += 2; } if (duder.ypos < 30) duder.ypos = 30; if (duder.ypos > 10+50*3) duder.ypos = 10+50*3; } if (gameState == GAME_ROAM) { // basically we do nothing but check if we need to transition to other states if (duder.xpos <= 10 + (10+20)*3) { gameState = GAME_KSANTA; ks.gamePhase = KS_GREET_PHASE; ks.phaseTime = 0; ks.textBuf = "Hello there boy"; talkedToKSanta = true; } else if (duder.xpos >= 10 + (frame.width-10-20-8)*3) { gameState = GAME_HSANTA; hs.gamePhase = HS_GREET_PHASE; hs.phaseTime = 0; hs.textBuf = "welcome child"; talkedToHSanta = true; } else if (keysDown[CODE_RET] || textBuf.length() > 0 || failedPress) { gameState = GAME_MCLAUS; ms.gamePhase = MS_BERATE_PHASE; ms.phaseTime = 0; ms.textBuf = "naughty boy"; maxSeen[HINT_MRS_CLAUS] = 0; if (anyStolen) { maxSeen[HINT_MRS_CLAUS2] = 0; ms.textBuf = "oh dear you are hurt"; } textBuf = ""; if (duder.xpos < 220) { duder.flip = true; ms.xpos = duder.xpos + 14*3; } else { duder.flip = false; ms.xpos = duder.xpos - 14*3; } ms.ypos = 10; } } if (gameState == GAME_MCLAUS) { boolean canInterrupt = false; if (duder.xpos >= ms.xpos) ms.flip = false; else ms.flip = true; boolean onGround = true; if (ms.ypos < 10+48*3) { ms.ypos += 5*3; onGround = false; if (ms.ypos >= 10+48*3) { onGround = true; ms.ypos = 10+48*3; } } if (ms.gamePhase == MS_BERATE_PHASE) { ms.Talk(); if (onGround) { canInterrupt = true; } if (ms.phaseTime == 70) { if (anyStolen) { ms.gamePhase = MS_GREET_PHASE; } else { ms.textBuf = "children shouldspeak only when spoken to"; } } if (ms.phaseTime == 160) { ms.gamePhase = MS_GREET_PHASE; if (anyStolen) ms.phaseTime = 0; else ms.phaseTime = 300; } } if (abs(duder.xpos - ms.xpos) >= 30*3 || duder.wallhit != 0) { if (ms.gamePhase != MS_LEAVING_PHASE && ms.gamePhase != MS_FADE_PHASE) { println(ms.gamePhase); ms.gamePhase = MS_LEAVING_PHASE; ms.phaseTime = 0; } } if (ms.gamePhase == MS_LEAVING_PHASE) { if (abs(duder.xpos - ms.xpos) < 10*3 && duder.wallhit == 0) { ms.gamePhase = MS_GREET_PHASE; } if (abs(duder.xpos - ms.xpos) > 25*3 || duder.wallhit != 0) { println("FADING"); ms.gamePhase = MS_FADE_PHASE; ms.phaseTime = 0; ms.Fade(time); } } if (ms.gamePhase == MS_FADE_PHASE) { if (ms.state == MS_ABSENT) { ms.phaseTime = 0; gameState = GAME_ROAM; ms.textBuf = ""; println("absent"); } } if (ms.gamePhase == MS_INTRO_PHASE) { canInterrupt = true; ms.textBuf = "welcome to the north pole"; ms.Talk(); if (ms.phaseTime == 0) { textBuf = ""; } if (ms.phaseTime == 100) { ms.gamePhase = MS_GREET_PHASE; ms.phaseTime = 0; } } if (ms.gamePhase == MS_GREET_PHASE) { canInterrupt = true; if (anyStolen) { canInterrupt = false; if (ms.phaseTime == 0) { ms.textBuf = "oh dear you are hurt"; textBuf = ""; ms.Talk(); } if (ms.phaseTime == 70) { ms.textBuf = "that should fix you up"; anyStolen = false; for (int i = 0; i < 29; i++) { board.here[i] = true; } ms.phaseTime = 220; } } else { if (ms.phaseTime == 0) { ms.textBuf = "holler if you need help"; textBuf = ""; ms.Talk(); } if (ms.phaseTime == 300) { ms.textBuf = "I will be here watching"; } if (ms.phaseTime == 500) { ms.Fade(time); ms.gamePhase = MS_FADE_PHASE; } } } if (ms.gamePhase == MS_RESPOND_PHASE) { canInterrupt = false; //println("respond phase not implemented"); if (textBuf.length() > 1) { int index = textBuf.charAt(0) - 'A'; if (textBuf.charAt(0) == ' ') index = 26; ms.textBuf = ms.interjections[index]; duder.state = STATE_IDLE; canInterrupt = true; ms.gamePhase = MS_RESPOND_PHASE_2; ms.phaseTime = 0; ms.Talk(); println("going to phase 2"); textBuf = ""; } else if (textBuf.length() < 1) { ms.phaseTime = -1; ms.Talk(); duder.state = STATE_IDLE; ms.gamePhase = MS_GREET_PHASE; } } if (ms.gamePhase == MS_RESPOND_PHASE_2) { //println("in phase 2"); if (ms.phaseTime > 20) canInterrupt = true; else textBuf = ""; if (ms.phaseTime == 0) { textBuf = ""; ms.Talk(); } if (ms.phaseTime == 100) { ms.phaseTime = -1; ms.gamePhase = MS_GREET_PHASE; } } if (canInterrupt) { if (textBuf.length() > 0) { println("interrupted"); ms.gamePhase = MS_RESPOND_PHASE; ms.phaseTime = 0; ms.textBuf = ""; ms.Idle(); duder.state = STATE_TALK; } } ms.phaseTime++; int xoff = 6; if (ms.flip) { xoff = -6; } sp.DrawFromBot(ms.xpos+xoff,ms.ypos-6,ms.textBuf,3,15); // gameState = GAME_ROAM; } if (gameState == GAME_KSANTA) { if (duder.xpos >= 10 + (10+30)*3) { if (ks.gamePhase != KS_LEAVING_PHASE) { ks.gamePhase = KS_LEAVING_PHASE; ks.phaseTime = 0; emptyText = ""; } } if (ks.gamePhase == KS_LEAVING_PHASE) { if (duder.xpos < 10 + (10+25)*3) { ks.gamePhase = KS_GREET_PHASE; textBuf = ""; ks.phaseTime = 50; } if (duder.xpos > 10 + (10+29)*3) { ks.gamePhase = KS_IDLE_PHASE; ks.phaseTime = 0; gameState = GAME_ROAM; ks.Idle(); } //ks.textBuf = "wait come back"; } if (ks.gamePhase == KS_GREET_PHASE) { ks.Talk(); if (ks.phaseTime == 0) { textBuf = ""; ks.textBuf = "hello there boy"; failedPress = false; } if (ks.phaseTime == 50) { ks.textBuf = "what do you want for xmas"; failedPress = false; } if (ks.phaseTime == 150) { ks.textBuf = "come on ask for something"; } if (textBuf.length() > 0 || failedPress) { ks.gamePhase = KS_STEAL_PHASE; ks.Steal(time); ks.phaseTime = 0; ks.textBuf = "i am sorry what was that"; } // sp.DrawFromBot(ks.xpos+24,ks.ypos-6,ks.textBuf,3,25, true); } if (ks.gamePhase == KS_STEAL_PHASE) { if (failedPress) { ks.textBuf = "gee that letter seems to be gone"; ks.Talk(); ks.phaseTime = 0; } if (textBuf.length() > 0) { //duder.state = STATE_TALK; boolean stolen = false; for (int i = 0; i < textBuf.length(); i++) { int ch = textBuf.charAt(i) - 'A'; if (ch < 0 || ch >= 26) ch = textBuf.charAt(i) - 'a'; println(ch + " from " + textBuf.charAt(i)); if (ch >= 0 && ch < 26) { if (board.here[ch]) stolen = true; board.here[ch] = false; emptyText += " "; } if (textBuf.charAt(i) == ' ') { if (board.here[CODE_SPACE]) stolen = true; emptyText += " "; board.here[CODE_SPACE] = false; } } if (stolen) { ks.Steal(time); ks.textBuf = ks.taunts[int(random(ks.taunts.length - .1))]; ks.phaseTime = 0; //ks.Talk(); anyStolen = true; } else { ks.textBuf = "gee that letter seems to be gone"; ks.phaseTime = 0; ks.Talk(); } textBuf = ""; } if (ks.phaseTime > 60) { ks.Idle(); ks.textBuf = ""; } if (keysDown[CODE_RET] && emptyText.length() > 0) { emptyText = ""; ks.textBuf = "haha i cant hear you"; ks.Talk(); ks.phaseTime = 0; duder.state = STATE_IDLE; } } sp.DrawFromBot(ks.xpos+24,ks.ypos-6,ks.textBuf,3,35, true); ks.phaseTime++; } if (gameState == GAME_HSANTA) { if (duder.xpos <= 10 + (frame.width-10-40-8)*3) { if (hs.gamePhase != HS_LEAVING_PHASE) { endHypnoMode(); hs.gamePhase = HS_LEAVING_PHASE; hs.phaseTime = 0; println("leaving phase entered"); } } if (hs.gamePhase == HS_LEAVING_PHASE) { if (duder.xpos > 10 + (frame.width-10-40-8)*3) { hs.gamePhase = HS_GREET_PHASE; textBuf = ""; hs.phaseTime = 50; startHypnoMode("raptor weddings"); } if (duder.xpos <= 10 + (frame.width-10-40-8)*3) { hs.gamePhase = HS_IDLE_PHASE; hs.phaseTime = 0; gameState = GAME_ROAM; hs.Idle(); } //hs.textBuf = "wait come back"; } if (hs.gamePhase == HS_GREET_PHASE) { hs.Talk(); if (hs.phaseTime == 0) { startHypnoMode("raptor weddings"); textBuf = ""; hs.textBuf = "welcome child"; } if (hs.phaseTime == 50) { hs.textBuf = "what is it you desire"; } if (hs.phaseTime == 150) { hs.textBuf = "open your heart to me"; } if (hypnoTextPos > 0) { hs.gamePhase = HS_HYPNO_PHASE; hs.Hypno(); hs.phaseTime = 0; hs.textBuf = ""; } } if (hs.gamePhase == HS_HYPNO_PHASE) { if (hypnoTextPos > 0) { duder.state = STATE_TALK; } if (hypnoPresses[CODE_RET] > 0) { hs.phaseTime = 0; hs.gamePhase = HS_RESPOND_PHASE; textBuf = ""; duder.state = STATE_IDLE; resp = null; if (hypnoBuf.length() > 0) { if (hypnoBuf.charAt(0) == ' ') { hypnoBuf = hypnoBuf.substring(1); } if (hypnoBuf.length() > 0) { if (hypnoBuf.charAt(hypnoBuf.length() - 1) == ' ') { hypnoBuf = hypnoBuf.substring(0,hypnoBuf.length()-1); } } } /* // code to debug all responses Object[] blahs = hypnoToResponse.keySet().toArray(); hypnoBuf = (String)blahs[currblah]; currblah = (currblah + 1) % blahs.length;; */ if (!discussed.containsKey(hypnoBuf) && !hypnoToResponse.containsKey(hypnoBuf)) { for (int i = 0; i < hypnoBuf.length(); i++) { if (hypnoBuf.charAt(i) == ' ') { println("hypnoBuf " + hypnoBuf + " -> " + (hypnoBuf.substring(0,i) + hypnoBuf.substring(i+1))); String subs = hypnoBuf.substring(0,i) + hypnoBuf.substring(i+1); if (hypnoToResponse.containsKey(subs)) { hypnoBuf = subs; } break; } } } hs.textBuf = hypnoBuf + "? Huh?"; println(hypnoBuf); if (discussed.containsKey(hypnoBuf)) { hs.textBuf = "we already discussed that"; } else if (hypnoToResponse.containsKey(hypnoBuf)) { resp = (Response)hypnoToResponse.get(hypnoBuf); if (resp.pic != null) { if (!imagesDisplayed.containsKey(resp.pic)) { imagesDisplayed.put(resp.pic, true); gifts.add(resp.pic); } } if (hypnoBuf.equals("RAPTOR WEDDINGS") || hypnoBuf.equals("RAPTOR WEDDING")) rights_triggered = true; if (hypnoBuf.equals("WINGS") || hypnoBuf.equals("WING")) hasWings = true; if (hypnoBuf.equals("TWINS") || hypnoBuf.equals("TWIN")) twinMode = true; if (hypnoBuf.equals("PONG") || hypnoBuf.equals("PONGS")) pongActive = true; if (hypnoBuf.equals("WIN") || hypnoBuf.equals("TO WIN") || hypnoBuf.equals("WINS") || hypnoBuf.equals("TO WINS") || hypnoBuf.equals("A WIN") || hypnoBuf.equals("A WINS") ) { hasWon = true; } } else { if (hypnoBuf.length() > 4) { String subs = hypnoBuf.substring(0,4); println("else else " + subs); if (subs.equals("APT ")) { resp = new Response("who am i to say what is apt", "narrow that down for me"); } } } discussed.put(hypnoBuf, true); endHypnoMode(); startHypnoMode("raptor weddings"); } } if (hs.gamePhase == HS_RESPOND_PHASE) { hs.Talk(); if (hs.phaseTime == 0) { if (resp != null) { hs.textBuf = resp.words[0]; } } if (hs.phaseTime == 80) { if (resp != null && resp.words.length > 1) { hs.textBuf = resp.words[1]; } else { hs.phaseTime = 50; hs.gamePhase = HS_GREET_PHASE; } } if (hs.phaseTime == 160) { hs.phaseTime = 50; hs.gamePhase = HS_GREET_PHASE; } if (textBuf.length() > 0) { if (hs.phaseTime > 40) { hs.gamePhase = HS_HYPNO_PHASE; hs.Hypno(); hs.textBuf = ""; hs.phaseTime = 0; } else { textBuf = ""; } } } sp.DrawFromBot(hs.xpos,hs.ypos-6,hs.textBuf,3,35, false); hs.phaseTime++; } if (hypnoMode && hs.state == HS_HYPNO) { if (hypnoTextPos < hypnoText.length()) { image(thoughtbub, hs.xpos + 45, hs.ypos-40,thoughtbub.width*2,thoughtbub.height*2); words.Draw(hs.xpos+63,hs.ypos-34,hypnoText.charAt(hypnoTextPos),2); } } if (hypnoMode) sp.DrawFromBot(duder.xpos,duder.ypos+6,hypnoBuf,3,15); else sp.DrawFromBot(duder.xpos,duder.ypos+6,textBuf,3,15); ms.Draw(time,3); duder.Draw(time, 3); if (twinMode) { duder.xpos -= 8*3; duder.DrawNoInput(time, 3); duder.xpos += 8*3; } ks.Draw(time, 3); hs.Draw(time, 3); time++; failedPress = false; } //int currblah = 0; boolean failedPress = false; void keyPressed() { boolean repeat = false; // non-hypnomode key handling (always runs, not changed by hypnomode) if (key == RETURN || key == ENTER) { if (!keysDown[CODE_RET]) keysDown[CODE_RET] = true; else repeat = true; } if (key == BACKSPACE) { if (!keysDown[CODE_BACKSPACE]) { keysDown[CODE_BACKSPACE] = true; if (textBuf.length() > 0) { textBuf = textBuf.substring(0, textBuf.length()-1); } } else repeat = true; } if (key == ' ') { if (!keysDown[CODE_SPACE]) { keysDown[CODE_SPACE] = true; if (board.here[CODE_SPACE]) textBuf += ' '; else failedPress = true; } else repeat = true; } if (key >= 'a' && key <= 'z') { if (!keysDown[key - 'a']) { keysDown[key - 'a'] = true; if (board.here[key - 'a']) textBuf += char('A' + (key - 'a')); else failedPress = true; } else repeat = true; } if (key >= 'A' && key <= 'Z') { if (!keysDown[key - 'A']) { keysDown[key - 'A'] = true; if (board.here[key - 'A']) textBuf += char(key); else failedPress = true; } else repeat = true; } if (key == CODED) // coded keys are just character movement { if (keyCode == LEFT) { // println("no more move hint"); maxSeen[HINT_MOVE] = 0; movementKeys[MOVEKEY_LEFT] = true; } if (keyCode == RIGHT) { // println("no more move hint"); maxSeen[HINT_MOVE] = 0; movementKeys[MOVEKEY_RIGHT] = true; } if (keyCode == UP) { upDownKeys[UDKEY_UP] = true; } if (keyCode == DOWN) { upDownKeys[UDKEY_DOWN] = true; } return; } // hypnomode variables for reference /* boolean hypnoMode = false; int[] hypnoPresses = new int[29]; char[] hypnoMap = new char[29]; String hypnoBuf = ""; */ // hypnomode key handling if (hypnoMode && !repeat) { if (key == BACKSPACE) { if (hypnoTextPos > 0) { hypnoTextPos--; if (hypnoBuf.length() > 0) { while (hypnoTextPos > 0 && hypnoText.charAt(hypnoTextPos) != hypnoBuf.charAt(hypnoBuf.length() - 1)) hypnoTextPos--; hypnoBuf = hypnoBuf.substring(0, hypnoBuf.length() - 1); } println(hypnoTextPos + " -> " + hypnoBuf); } } else { int hypnoKey; char hypnoKeyChar = '!'; if (hypnoTextPos >= hypnoText.length()) { hypnoKey = CODE_RET; } else { hypnoKey = hypnoText.charAt(hypnoTextPos++); hypnoKeyChar = char(hypnoKey); if (hypnoKey == ' ') hypnoKey = CODE_SPACE; else hypnoKey -= 'A'; } if (hypnoKey < 0 || hypnoKey >= hypnoPresses.length) println("oh no bad hypnokey"); else { hypnoPresses[hypnoKey]++; if (board.here[hypnoKey] && hypnoKeyChar != '!') { hypnoBuf += hypnoKeyChar; } } int keyid = key - 'A'; if (key - 'a' >= 0 && key - 'a' < 26) { keyid = key - 'a'; } if (key == ' ') { keyid = CODE_SPACE; } if (key == RETURN || key == ENTER) { keyid = CODE_RET; } if (keyid >= 0 && keyid < hypnoMap.length) hypnoMap[keyid] = hypnoKey; } } } void keyReleased() { if (key == CODED) // coded keys are just character movement { if (keyCode == LEFT) { movementKeys[MOVEKEY_LEFT] = false; } if (keyCode == RIGHT) { movementKeys[MOVEKEY_RIGHT] = false; } if (keyCode == UP) { upDownKeys[UDKEY_UP] = false; } if (keyCode == DOWN) { upDownKeys[UDKEY_DOWN] = false; } return; } if (hypnoMode) { // TODO: implement hypno mode key release if (key != BACKSPACE) { int keyid = key - 'A'; if (key - 'a' >= 0 && key - 'a' < 26) { keyid = key - 'a'; } if (key == ' ') { keyid = CODE_SPACE; } if (key == RETURN || key == ENTER) { keyid = CODE_RET; } if (keyid >= 0 && keyid < hypnoMap.length) hypnoPresses[hypnoMap[keyid]]--; } } // non-hypnomode key handling (always runs, not changed by hypnomode) if (key == RETURN || key == ENTER) keysDown[CODE_RET] = false; if (key == BACKSPACE) keysDown[CODE_BACKSPACE] = false; if (key == ' ') keysDown[CODE_SPACE] = false; if (key >= 'a' && key <= 'z') keysDown[key - 'a'] = false; if (key >= 'A' && key <= 'Z') keysDown[key - 'A'] = false; }