import processing.opengl.*; PFont font; ArrayList gameMotes, endingMotes; int level, bgR, bgG, bgB, bgTOP, tempTOP, tempR, tempG, tempB, pRG, pB, pA, eRGBA; boolean startOfLevel, newLevelCreated, win, lose, beginning, ending, resetMouse; float pX, pY, pDelay, pSize; void setup() { size(600, 400, OPENGL); smooth(); level = 0; startOfLevel = true; win = false; lose = false; beginning = true; ending = false; stroke(100,100,100,255); resetMouse = false; pDelay = 50.0; pX = mouseX; pY = mouseY; pSize = 0.0; pRG = 0; pB = 200; pA = 100; cursor(CROSS); bgR = 0; bgG = 20; bgB = 40; bgTOP = 200; font = loadFont("Trubble-48.vlw"); eRGBA = 150; endingMotes = new ArrayList(); for (int i=0; i<30; i++) { // parameters: posX, posY, size, Bcolor, Acolor endingMotes.add(new Ending(random(0,width), random(0,height), random(10,200), random(50,255), random(0,100))); } } void draw() { background(bgR, bgG, bgB, 255); // noStroke(); // beginShape(QUADS); // fill(bgTOP); // vertex(0,0); // Background vertex(width,0); // fill(bgR, bgG, bgB); // vertex(width,height-50); // vertex(0,height-50); // endShape(); // stroke(1); // ellipseMode(CENTER); // if (beginning) { showBeginning(); } else { if (startOfLevel && !newLevelCreated) { createLevel(); } else if (startOfLevel && newLevelCreated) { fadeInLevel(); } else { if (!ending) { if (win || lose) { endGame(); } else { playGame(); checkWinCond(); } drawPlayer(); } } } if (ending) { showEnding(); } } void drawPlayer() { float dX = mouseX - pX; float dY = mouseY - pY; if (abs(dX) > 1) { pX = pX + dX/pDelay; } if (abs(dY) > 1) { pY = pY + dY/pDelay; } noStroke(); fill(pRG, pRG, pB, pA); ellipse (pX, pY, pSize, pSize); } // -------------------------------------------------------------------------------------------- // ------------------------------------ LEVEL CREATOR ----------------------------------------- void createLevel() { if (resetMouse) { pX = mouseX; pY = mouseY; resetMouse = false; } gameMotes = new ArrayList(); /* Mote parameters for personalities are as follow: StartPosX, StartPosY, startSize, speedOfGrowth, shrinkingSpeed, risingSpeed, fallingSpeed, WarningBarLvl, speedofGrowthWhenAngry */ if (level == 0) { tempTOP= 190; tempR = 0; tempG = 20; tempB = 40; gameMotes.add(new Motes(300.0, 200.0, 0.5, 0.3, 0.4, 0.7, 0.20, 0.9, 0.4)); // tutorial. One mote only. } else if (level == 1) { tempTOP = 210; tempR = 0; tempG = 40; tempB = 60; gameMotes.add(new Motes(100.0, 100.0, 0.5, 0.5, 0.5, 0.6, 0.06, 0.8, 0.5)); // default gameMotes.add(new Motes(300.0, 300.0, 0.3, 0.3, 0.7, 0.8, 0.04, 0.8, 0.5)); // Complacent. Wants to cooperate with the player. gameMotes.add(new Motes(500.0, 200.0, 0.8, 0.6, 0.4, 0.6, 0.10, 0.9, 0.7)); // Volatile. quick to grow, but quick to shrink } else if (level == 2){ tempTOP = 230; tempR = 20; tempG = 70; tempB = 90; gameMotes.add(new Motes(100.0, 300.0, 0.2, 0.4, 0.3, 0.5, 0.04, 0.6, 0.8)); // Hesitant. It's warning bar is low. gameMotes.add(new Motes(400.0, 200.0, 0.5, 0.3, 0.7, 0.7, 0.20, 0.9, 0.2)); // Needy. Falls fast when neglected. gameMotes.add(new Motes(250.0, 100.0, 0.7, 0.5, 0.5, 0.6, 0.04, 0.8, 0.5)); // default gameMotes.add(new Motes(500.0, 250.0, 0.4, 0.5, 0.5, 0.6, 0.04, 0.8, 0.5)); // default } else if (level == 3) { tempTOP = 255; tempR = 40; tempG = 100; tempB = 130; gameMotes.add(new Motes(100.0, 100.0, 0.5, 0.5, 0.5, 0.6, 0.05, 0.8, 0.5)); // default gameMotes.add(new Motes(175.0, 230.0, 0.6, 0.2, 0.5, 0.3, 0.03, 0.7, 0.5)); // Untrusting. Slow reaction to player. gameMotes.add(new Motes(230.0, 180.0, 0.2, 0.3, 0.7, 0.8, 0.01, 0.8, 0.5)); // Almost Fully Complacent. gameMotes.add(new Motes(420.0, 270.0, 0.3, 0.7, 0.5, 0.4, 0.00, 0.8, 0.7)); // Stubborn. Quick to grow, but won't fall. gameMotes.add(new Motes(480.0, 200.0, 0.6, 0.3, 0.7, 0.7, 0.20, 0.9, 0.2)); // Needy. Falls fast when neglected. gameMotes.add(new Motes(530.0, 80.0, 0.2, 0.5, 0.5, 0.6, 0.05, 0.8, 0.5)); // default. } else { tempTOP = 255; tempR = 255; tempG = 255; tempB = 255; ending = true; } newLevelCreated = true; } // ------------------------------------ LEVEL CREATPR ----------------------------------------- // -------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------- // ------------------------------------ TRANSITIONS ------------------------------------------- void fadeInLevel() { boolean motesVisible = false; boolean playerVisible = false; boolean backgroundVisible = false; if (bgTOP < tempTOP) { bgTOP += 1; } // Fades in the background if (bgR < tempR) { bgR += 1; } // if (bgG < tempG) { bgG += 1; } // if (bgB < tempB) { bgB += 1; } // if (bgTOP >= tempTOP && bgR >= tempR && // bgG >= tempG && bgB >= tempB) { // bgTOP = tempTOP; // bgR = tempR; // bgG = tempG; // bgB = tempB; // backgroundVisible = true; // } else { // backgroundVisible = false; // } // if (!ending) { for (int i=0; i= // (((Motes)gameMotes.get(i)).getStartSize())) { // motesVisible = true; // } else { // motesVisible = false; // } // ((Motes)gameMotes.get(i)).drawMote(); // } // } if (!ending) { pSize += 1; // Fades in the player pA += 2; // if (pSize >= 50) { pSize = 50; } // if (pA >= 100) { pA = 100; } // if (pA >= 100 && pSize >= 50) { // playerVisible = true; // } else { // playerVisible = false; // } // } else { // Unless this is the ending if (pA > 0) { // in which case, the player fades out pA -= 1.0; // pSize += 0.5; // } // } // drawPlayer(); // if (motesVisible && playerVisible && backgroundVisible) { // verifies everything is visible startOfLevel = false; // before beginning gameplay } // println("Motes = " + motesVisible + ", Player = " + playerVisible + ", BG = " + backgroundVisible); if (ending && pA <= 0 && backgroundVisible) { // Verifies the ending transition went through before startOfLevel = false; // before leaving this function } } // ------------------------------------ TRANSITIONS ------------------------------------------- // -------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------- // ------------------------------------ UPDATING GAME ----------------------------------------- void playGame() { int i; for (i=0; i= height-50) { // or loseNum += 1; // floating at the bottom (lose condition) } // } // // if (winNum == gameMotes.size()) { // win = true; // } else if (loseNum == gameMotes.size()) { // lose = true; // } // } void endGame() { if (win) { // Fades the motes away. for (int i=0; i 10) { pSize -= 0.5; } // shrinks, if (pA > 0) { pA -= 1.0; } // fades, pY += 2; // and falls. if (pSize <= 10 && pA <= 0) { complete = true; resetMouse = true; } } if (complete) { win = false; lose = false; startOfLevel = true; newLevelCreated = false; } } void showBeginning() { // beginning screen fill(0,40,100,eRGBA); textFont(font, 32); text("The beginning...", 100, 100); } void showEnding() { for (int i=0; i