// Ice Cream Parlor // Cadin Batrack 9.10.05 // catch the current flavor to keep your hunger down // bowl instance // the bowl is a class to allow for multiple players // (not being used here) bowl p1; //Arrays of Scoops scoop[] scoopArray = new scoop[8]; //Some general parameters int bowlW = 50; int bowlH = 40; int scoopW = 56; int scoopH = 40; int bowlPosY; int players = 1; int masterFlavor; int newFlavor; int totalFlavors = 3; //Hunger meter & switch timers color meterFill; int meterLength; int swDialogTimer; int randomTimer; int subTimer; PImage bg; PImage scoop_a; PImage sw, sw_a; PImage ind; PImage bowl, bowl_a; PImage gameOver, gameOver_a; void setup() { //noCursor(); cursor(CROSS); noStroke(); size(600,350); framerate(20); ellipseMode(CENTER); rectMode(CENTER); bowlPosY = 330; //create the bowl instance p1 = new bowl(1, bowlPosY, bowlW, bowlH); // choose the master flavor switcheroo(); //populate Scoop Array for (int i = 0; i < scoopArray.length; i++) { scoopArray[i] = new scoop(scoopW, scoopH); } //load up images bg = loadImage("background.jpg"); sw_a= loadImage("switch_alpha.gif"); scoop_a= loadImage("scoop_alpha.gif"); bowl = loadImage("bowl.jpg"); bowl_a = loadImage("bowl_a.jpg"); gameOver = loadImage("gameOver.gif"); gameOver_a = loadImage("gameOver_a.gif"); } void draw() { //bg and flavor indicator images image(bg, 0,0); image(ind,435,3); //hunger Meter if(meterLength >0){ fill(meterFill); rectMode(CORNER); noStroke(); rect(14,19,meterLength,7); } else { meterLength=0; } //draw the bowl p1.displayBowl(); //if the game hasn't been lost if(meterLength<410){ //Update & Display Scoops in the scoop Array for(int i=0; i< scoopArray.length; i++){ scoopArray[i].update(); scoopArray[i].display(); } //switch dialog if(swDialogTimer < 30){ sw.mask(sw_a); image(sw,161,112); swDialogTimer++; } //timer for switch intervals if(randomTimer < 1){ switcheroo(); } else { randomTimer--; } //sub timer to make the meter crawl slower //I know this is sloppy. It works for now if(subTimer < 1) { meterLength++; subTimer = 3; } else { subTimer--; } } else { //game over Dialog gameOver.mask(gameOver_a); image(gameOver,161,112); } }//end void draw void switcheroo() { //choose a NEW flavor //the while loop keeps it from picking the same flavor while(newFlavor == masterFlavor) { newFlavor = floor(random(0,totalFlavors)); } masterFlavor = newFlavor; //set the images according to the chosen flavor if(masterFlavor ==0){ ind= loadImage("indicator_choc.jpg"); sw= loadImage("switch_choc.gif"); meterFill = color(135,109,90); } else if(masterFlavor ==1){ ind= loadImage("indicator_van.jpg"); sw= loadImage("switch_van.gif"); meterFill = color(225,202,165); } else if(masterFlavor ==2){ ind= loadImage("indicator_straw.jpg"); sw= loadImage("switch_straw.gif"); meterFill = color(237,130,153); } //reset timers swDialogTimer=0; randomTimer = floor(random(100,450)); } //Scoop class class scoop { PImage scoop; float posX; float posY; int w; int h; boolean hasBeenHit; float speed; int flavor; //CONSTRUCTOR scoop(int _w, int _h) { w = _w; h = _h; reset(); } void reset(){ //choose new X & Y posY = 0-h; posX = floor(random(w/2, 600-(w/2))); //if it's the current flavor and it didn't get //caught add to the hunger meter if(flavor == masterFlavor && !hasBeenHit){ meterLength+=5; } //choose a random flavor flavor = floor(random(0, totalFlavors)); hasBeenHit=false; //load the image based on the chosen flavor if(flavor==0){ scoop = loadImage("scoop_choc.gif"); } else if(flavor==1){ scoop = loadImage("scoop_van.gif"); } else { scoop = loadImage("scoop_straw.gif"); } //random speed speed = random(4, 8); } void update(){ //update position posY += speed; //reset if it hits the bottom if(posY > 350+h) { reset(); } //test for collision (with bowl) if(hitTest()){ collision(); } } //is it hitting the bowl boolean hitTest() { if( posX-(w/2) < p1.posX+(p1.w/2) && posX+(w/2) > p1.posX-(p1.w/2) && posY-(h/2) < p1.posY+(p1.h/2) && posY+(h/2) > p1.posY-(p1.h/2)){ return true; } else { return false; } } //display the scoop void display() { if(!hasBeenHit){ scoop.mask(scoop_a); image(scoop,posX-w/2,posY-h/2); } } void collision(){ if(! hasBeenHit){ if(flavor == masterFlavor){ meterLength-=10; hasBeenHit = true; } else { meterLength+=5; hasBeenHit = true; } } } }//end Scoop class //Bowl class class bowl { int player; int life; color bodyColor; int posY; int posX; int w; int h; //CONSTRUCTOR bowl(int _player, int _y, int _w, int _h) { player = _player; life = 100; w = _w; h = _h; posY = _y; } void displayBowl() { posX = mouseX; bowl.mask(bowl_a); image(bowl, posX-(bowlW-5),posY-(bowlH)); } }//end Bowl class