abstract class Level{ Faucet f; PApplet mainApplet; //Create a PPhys2D world PPWorld world = new PPWorld(); PImage faucetFront = loadImage("art/bamboo_front.png"); PImage imgBackdrop;//loadImage(); void setup(PApplet mainApplet){ setup(mainApplet,-1); } Faucet makeFaucet(int faucetRate ){ Faucet f =null; if(faucetRate != -1){ f = new Faucet(164,30,faucetRate); } else { f = new Faucet(164,30); } f.setPosition(-30,-30); f.vertex(191,62); f.vertex(142,31); f.vertex(-199,-59); f.vertex(-196,-43); f.vertex(189,61); f.setStaticBody(true); f.attachImage(loadImage("art/bamboo_back.png")); return f; } void setup(PApplet mainApplet, int faucetRate){ this.mainApplet = mainApplet; imgBackdrop = loadImage("art/Backgroundv2.jpg"); f = makeFaucet(faucetRate); world.add(f); if (windSound != null) windSound.setGain(-10); } HashSet mouseables = new HashSet(); void registerMouseable(Mousable m){ mouseables.add(m); } void mousePressed(){ Iterator i = mouseables.iterator(); while(i.hasNext()){ Mousable m = (Mousable) i.next(); m.handleMousePressed(); } } void mouseMoved(){ Iterator i = mouseables.iterator(); while(i.hasNext()){ Mousable m = (Mousable) i.next(); m.isMouseOver(); } } void mouseDragged(){ Iterator i = mouseables.iterator(); while(i.hasNext()){ Mousable m = (Mousable) i.next(); m.handleMouseDragged(); } } void mouseReleased(){ Iterator i = mouseables.iterator(); while(i.hasNext()){ Mousable m = (Mousable) i.next(); m.handleMouseReleased(); } } HashSet everyTickers = new HashSet(); void registerEveryTicker(EveryTicker et){ everyTickers.add(et); } void doEveryTickers(){ Iterator i = everyTickers.iterator(); while(i.hasNext()){ EveryTicker et = (EveryTicker) i.next(); et.handleTick(); } } HashSet drops; void reset(){ drops = new HashSet(); } void draw(){ // println(imgBackdrop); image(imgBackdrop, 0, 0); world.draw(mainApplet); if(f!=null) { if(f.updateAndCheck()){ addDrop(f.x,f.y); } } checkBouncers(); removeFallenDrops(); checkDropletColliders(); doEveryTickers(); doDropTails(); image(faucetFront,-226,-113); } boolean isDone(){ return false; } HashSet bouncers = new HashSet(); void registerBouncer(PPBody thing,String msg,int noteIndex){ bouncers.add(new Bouncer(thing,msg,noteIndex)); } void checkBouncers(){ Iterator iD = drops.iterator(); while(iD.hasNext()){ Droplet d = (Droplet)iD.next(); Iterator iB = bouncers.iterator(); while(iB.hasNext()){ Bouncer b = (Bouncer)iB.next(); b.checkHit(d); } } } HashSet dropletColliders = new HashSet(); void registerDropletCollider(DropletCollider thing){ dropletColliders.add(thing); } void checkDropletColliders(){ Iterator iDC = dropletColliders.iterator(); while(iDC.hasNext()){ DropletCollider hitter = (DropletCollider)iDC.next(); Iterator iD = drops.iterator(); while(iD.hasNext()){ Droplet d = (Droplet)iD.next(); if(hitter.checkDropletCollision(d) && hitter.shouldRemoveOnDropletCollision()){ iD.remove(); world.remove(d); } } } } void addDrop(float x, float y){ Droplet d=new Droplet(x,y); drops.add(d); world.add(d); } void removeFallenDrops(){ Iterator i = drops.iterator(); while(i.hasNext()){ Droplet d = (Droplet)i.next(); if(d.getY() > height * 2){ world.remove(d); i.remove(); } } } void doDropTails(){ Iterator i = drops.iterator(); while(i.hasNext()){ Droplet d = (Droplet)i.next(); d.doTail(); } } boolean useAltSounds() { int musicPos = music.position(); return ((musicPos > 20338 && musicPos < 26796) || (musicPos > 33786 && musicPos < 40194) || (musicPos > 47184 && musicPos < 53592) || (musicPos > 60582 && musicPos < 66990)); } } class Bouncer{ String msg; AudioPlayer sound; AudioPlayer altSound; float soundGain = 0; PPBody thing; Bouncer(PPBody thing, String msg, int noteIndex){ if (noteIndex == 0){ sound = minim.loadFile("sounds/ping_f3.mp3"); altSound = minim.loadFile("sounds/ping_eb3.mp3"); } else if (noteIndex == 1){ sound = minim.loadFile("sounds/ping_a3.mp3"); altSound = minim.loadFile("sounds/ping_b3.mp3"); } else if (noteIndex == 2){ sound = minim.loadFile("sounds/ping_b3.mp3"); altSound = minim.loadFile("sounds/ping_db4.mp3"); } else if (noteIndex == 3){ sound = minim.loadFile("sounds/ping_e4.mp3"); altSound = minim.loadFile("sounds/ping_f4.mp3"); } else if (noteIndex == 4){ sound = minim.loadFile("sounds/jump_f_1.mp3"); altSound = minim.loadFile("sounds/jump_eb_1.mp3"); soundGain = -5; } else{ sound = minim.loadFile("sounds/jump_f_2.mp3"); altSound = minim.loadFile("sounds/jump_eb_2.mp3"); soundGain = -5; } this.thing = thing; this.msg = msg; } boolean checkHit(Droplet d){ if(d.isTouchingBody(thing) ){ if(d.soundDelay <= 0){ d.soundDelay = 30; // prevent repeated sounds AudioPlayer whichSound = sound; // play the alternate sound during some parts of the song if (currentLevel.useAltSounds()){ whichSound = altSound; } whichSound.rewind(); whichSound.setGain(soundGain); whichSound.play(); //print(msg+"("+musicPos+") "); return true; } d.soundDelay = 30; // prevent repeated sounds } return false; } }