#include "testApp.h" //bug in codeblocks: it sometimes checks for existence of executable from previous project //-------------------------------------------------------------- guiWindow::~guiWindow(){ cout << "gui window destroyed" << endl; } void guiWindow::setup(){ } void guiWindow::setParent(testApp *p){ parent=p; } void guiWindow::draw(){ ofDisableAlphaBlending(); parent->gui.draw(); ofSetColor(255,255,255); ofDrawBitmapString(ofToString(parent->game.queued)+" in queue", 10,ofGetHeight()-15); char buf[8]; sprintf(buf,"%.1f",ofGetFrameRate()); ofDrawBitmapString(buf, ofGetWidth()-43,ofGetHeight()-15); ofDrawBitmapString(levelnames[parent->gamestate-1], 10,ofGetHeight()-35); if (parent->gamestate==GAME_PLAYING) ofDrawBitmapString(parent->songs[parent->currentsong]->getScoreString(),10,ofGetHeight()-55); } void guiWindow::dragEvent(ofDragInfo dragInfo, ofxFenster* win){ parent->dragEvent(dragInfo); } void guiWindow::windowMoved(int x,int y){ //printf("window moved!\n"); } //---------------------------------------------------------------------- void testApp::setup(){ game.setup("1122",2000); //Asterisk.cpp thread polls server every 2000ms songs.push_back(new song("WeWishYouAMerryChistmas_v.2.1/VODA_MUS_WEWISHU_Backing_v.2.1.mp3","WeWishYouAMerryChistmas_v.2.1/VODA_MUS_WEWISHU_Lead_v.2.1.mp3","VODA_MUS_WEWISHU_Midi_v.2.2.xml","Lyrics_WeWishYou.2.1.xml","Levels_WeWishYou.2.1.xml")); songs.push_back(new song("DeckTheHalls_v.4.0/VODA_MUS_DeckTheHalls-Backing_v.4.0.mp3","DeckTheHalls_v.4.0/VODA_MUS_DeckTheHalls-Lead_v.4.0.mp3","VODA_MIDI_DeckTheHalls-v.4.0.xml","Lyrics_DeckTheHalls.4.0.xml","Levels_DeckTheHalls.4.0.xml")); songs.push_back(new song("DingDong.v.2.2/VODA_MUS_DingDong_Backing_v.2.2.mp3","DingDong.v.2.2/VODA_MUS_DingDong_Melody_v.2.2.mp3","VODA_MIDI_DingDong_v.2.2.xml","Lyrics_DingDong.2.2.xml","Levels_DingDong.2.2.xml")); songs.push_back(new song("JingleBells_v.4.0/VODA_MUS_JingleBells_Backing_v.4.0.mp3","JingleBells_v.4.0/VODA_MUS_JingleBells_Melody_v.4.0.mp3","VODA_MUS_JingleBells_MIDI_v.4.0.xml","Lyrics_JingleBells.4.0.xml","Levels_JingleBells.4.0.xml")); ofSetBackgroundAuto(false); ofBackground(0,0,0); //printf("we wish you a merry xmas:\n"); //songs[0]->notes.printNotes(); for (int i=0;i<3;i++) penguins.push_back(Puppet()); penguins[0].load("Penguin-Blue.xml"); penguins[1].load("Penguin-Purple.xml"); penguins[2].load("Penguin-Green.xml"); // temp save time for (int i=0;i<3;i++) raccoons.push_back(Puppet()); raccoons[0].load("Raccoon-Blue.xml"); raccoons[1].load("Raccoon-Purple.xml"); raccoons[2].load("Raccoon-Green.xml"); tags.push_back(new Tag("Tags/TAG_Get-Ready.png",2000,0.5,0)); tags.push_back(new Tag("Tags/TAG_Level-1.png",3000,0.5,0)); tags.push_back(new Tag("Tags/TAG_Level-2.png",3000,0.5,0)); tags.push_back(new Tag("Tags/TAG_Level-3.png",3000,0.5,0)); tags.push_back(new Tag("Tags/TAG_Level-4.png",3000,0.5,0)); tags.push_back(new Tag("Tags/PreGame-Practice.png",6000,0.5,0.16667)); tags.push_back(new Tag("Tags/Game-Over.png",3000,0.5,0)); tags.push_back(new Tag("Tags/Thanks-NEW.png",3000,0.5,0)); logos.push_back(new Billboard("Logo-VF.png",0.5,0.0)); logos.push_back(new Billboard("Logo-DCC.png",0.36,0.855)); lyricspanel=new Billboard("Lyrics-panel.png",0.5,0.703); banner.load("Ribbon/Dublin/Ribbon-Dublin_%05i.png",500); banner.setAnchorPercent(0.5,0.0); banner.setFrameRate(50); banner.play(); wirebirds.load("Birds-with-Wire/Birds-with-Wire_%05i.png",125); wirebirds.setAnchorPercent(0.5,0.5); wirebirds.setFrameRate(50); wirebirds.play(); //loadanimals("Raccoons"); playanimal =&penguins; //testpenguin.load("Penguin-Blue.xml"); //debug: commented out: 436m 257m //508fr 1.7s load in use: 837m 444m //release: commented out: 436m 256m //508fr 1.4s load in use: 836m 443m //cd /home/tim/workspace/VFxmas/vfg/bin/data //mount -t tmpfs -o size=64M tmpfs /RAM //cp *.m* RAM intro.loadMovie("RAM/Game-Demo_v5.mp4"); intro.setLoopState(OF_LOOP_NONE); intro.setVolume(0.0); advert.loadMovie("RAM/GW2003761_GRY-VFBR055-060_MPEG_hi.mov"); advert.setLoopState(OF_LOOP_NONE); advert.setVolume(1.0); background.loadMovie("RAM/Background_v3.mp4"); background.setLoopState(OF_LOOP_NORMAL); background.play(); backgroundmusic.loadSound("VODA_MUS_Pre-Game-Music_v.1.1.mp3"); backgroundmusic.setLoop(true); backgroundmusic.play(); backgroundmusic.setVolume(1.0); vignette.loadImage("Vignette.png"); showFPS=true; showVis=false; fullscreenoutput=false; fadelength=3000; segmentStartTime=0; currentsong=0; nextsong=0; gamestate=GAME_READY; guiWin=new guiWindow(); gui.setup("","panel.xml",0,0); threshStart=2000; gui.add(tS.setup("start threshold",threshStart,0,4000,255)); threshEnd=500; gui.add(tE.setup("end threshold",threshEnd,0,4000,255)); timescale=5000; gui.add(ts.setup("timescale",timescale,0,10000,255)); keyThresh=1500; gui.add(kT.setup("keythresh",keyThresh,0,4000,255)); birdpoint=0.6; gui.add(bP.setup("wire level",birdpoint,0.5,0.7,255)); gui.add(showWire.setup("wire",true)); ofxFenster* win=ofxFensterManager::get()->createFenster(0, 0, 200, 400, OF_WINDOW); win->setWindowTitle("config"); win->addListener(guiWin); ofAddListener(win->events.keyPressed, this, &testApp::keyPressedEvent); guiWin->setup(); guiWin->setParent(this); } /* void testApp::loadanimals(string which) { playanimals.clear(); for (int i=0;i<3;i++) playanimals.push_back(Puppet()); if (which=="Penguins") { playanimals[0].load("Penguin-Blue.xml"); playanimals[1].load("Penguin-Purple.xml"); playanimals[2].load("Penguin-Green.xml"); } else { playanimals[0].load("Raccoon-Blue.xml"); playanimals[1].load("Raccoon-Purple.xml"); playanimals[2].load("Raccoon-Green.xml"); } } */ void testApp::exit(){ delete lyricspanel; backgroundmusic.unloadSound(); } //-------------------------------------------------------------- void testApp::update(){ int ret=game.update(); if (ret==1000) { activatePractice(); } else if (ret>48&&ret<52) { songs[currentsong]->playerControl(ret-49); practiceSong.playerControl(ret-49); (*playanimal)[ret-49].playNow("Clap"); } else if (ret>51&&ret<55) { songs[currentsong]->playerControl(ret-52); practiceSong.playerControl(ret-52); (*playanimal)[ret-52].playNow("Clap"); } if (songs[currentsong]->isPlaying&&songs[currentsong]->getLevel(ofGetElapsedTimeMillis()+4000)>currentlevel) { int anim=ofRandom(1.9999); //this gives a binary random number for (int i=0;i<3;i++) { if (anim) (*playanimal)[i].playNow("Happy"); else (*playanimal)[i].playNow("Jump"); anim=(anim+1)%2; } tags[currentlevel+1]->play(); currentlevel++; printf("finished level %i!\n",currentlevel); } switch(gamestate) { case GAME_READY: case GAME_STARTPLAYING: case GAME_PLAYING: case GAME_ENDPLAYING: case GAME_ENDINGINTRO: case GAME_PRACTICE: background.update(); banner.update(); wirebirds.update(); break; case GAME_STARTINGINTRO: background.update(); case GAME_INTRO: intro.update(); break; case GAME_STARTINGADVERT: case GAME_ENDINGADVERT: background.update(); banner.update(); case GAME_ADVERT: advert.update(); break; } } /* #define GAME_STARTINGINTRO 1 #define GAME_INTRO 2 #define GAME_ENDINGINTRO 3 #define GAME_READY 4 #define GAME_STARTINGADVERT 5 #define GAME_ADVERT 6 #define GAME_ENDINGADVERT 7 #define GAME_STARTPLAYING 8 #define GAME_PRACTICE 9 #define GAME_PLAYING 10 #define GAME_ENDPLAYING 11 */ //-------------------------------------------------------------- void testApp::drawBackgroundLayers(){ float hOffs=(ofGetWidth()-ofGetHeight())/2; background.draw(hOffs,0,ofGetHeight(),ofGetHeight()); ofEnableAlphaBlending(); vignette.draw(hOffs,0,ofGetHeight(),ofGetHeight()); ofDisableAlphaBlending(); } //-------------------------------------------------------------- void testApp::draw(){ ofDisableAlphaBlending(); ofSetColor(255,255,255); float hOffs=(ofGetWidth()-ofGetHeight())/2; float scale=ofGetHeight()/1080.0f; float bannerscale,aspect,wOffs,seg; //this old chestnut float segamt=((float)(ofGetElapsedTimeMillis()-segmentStartTime)*2.0f)/fadelength; //same variable used in all segments switch(gamestate) { case GAME_STARTINGINTRO: case GAME_INTRO: case GAME_ENDINGINTRO: case GAME_READY: case GAME_STARTINGADVERT: case GAME_ADVERT: case GAME_ENDINGADVERT: case GAME_STARTPLAYING: case GAME_PRACTICE: case GAME_PLAYING: case GAME_ENDPLAYING: case GAME_WALKON: break; } //draw backgrounds switch(gamestate) { case GAME_STARTINGINTRO: case GAME_INTRO: case GAME_ENDINGINTRO: intro.draw(hOffs,0,ofGetHeight(),ofGetHeight()); if (intro.getCurrentFrame()==intro.getTotalNumFrames()) { gamestate=GAME_READY; } break; case GAME_READY: case GAME_STARTPLAYING: case GAME_PRACTICE: case GAME_PLAYING: case GAME_ENDPLAYING: case GAME_WALKON: drawBackgroundLayers(); break; case GAME_STARTINGADVERT: if (segamt<0.5) { ofEnableAlphaBlending(); ofSetColor(255,255,255,255-(segamt*510)); drawBackgroundLayers(); break; } else if (segamt>1.0) { gamestate=GAME_ADVERT; } else { //if (!advert.isPlaying()) advert.play(); ofEnableAlphaBlending(); ofSetColor(255,255,255,((segamt-0.5)*510)); } case GAME_ADVERT: case GAME_ENDINGADVERT: if (gamestate==GAME_ENDINGADVERT) { if (segamt<0.5) { ofEnableAlphaBlending(); segamt=((float)(ofGetElapsedTimeMillis()-segmentStartTime))/fadelength; ofSetColor(255,255,255,255-(segamt*510)); } else if (segamt>1.0) { gamestate=GAME_READY; ofSetColor(255,255,255); ofDisableAlphaBlending(); drawBackgroundLayers(); break; } else { ofDisableAlphaBlending(); ofSetColor(((segamt-0.5)*510),((segamt-0.5)*510),((segamt-0.5)*510)); drawBackgroundLayers(); break; } } aspect=advert.getHeight()/advert.getWidth(); wOffs=(ofGetHeight()-(ofGetWidth()*aspect))*0.5; advert.draw(0,wOffs,ofGetWidth(),ofGetWidth()*aspect); ofDisableAlphaBlending(); //may have been turned on during intro break; } //draw game action switch(gamestate) { case GAME_STARTINGADVERT: if (segamt<0.5) { ofEnableAlphaBlending(); ofSetColor(255,255,255,255-(segamt*510)); } else break; case GAME_ENDINGADVERT: if (segamt>0.5) { ofEnableAlphaBlending(); ofSetColor(255,255,255,((segamt-0.5)*510)); } else break; case GAME_READY: for (int i=0;i<3;i++) { //break up standing around movement if (ofRandom(1.0)<.002) (*playanimal)[i].play("Shuffle"); } case GAME_PLAYING: case GAME_PRACTICE: ofEnableAlphaBlending(); if (songs[currentsong]->isPlaying) { ofSetColor(255,255,255); if (showVis) songs[currentsong]->drawNotes(hOffs); int missed=songs[currentsong]->missedNote(); if (missed>-1) (*playanimal)[missed].playNow("Shudder"); int hit=songs[currentsong]->hitNote(); if (hit>-1) (*playanimal)[hit].play("Catch"); } else if (gamestate==GAME_PRACTICE) { int missed=practiceSong.missedNote(); if (missed>-1) (*playanimal)[missed].playNow("Shudder"); int hit=practiceSong.hitNote(); if (hit>-1) (*playanimal)[hit].play("Catch"); } for (int i=0;i<3;i++) (*playanimal)[i].draw(hOffs+(gridX[i+1]*ofGetHeight()),gridY[0]*ofGetHeight(),scale); if (songs[currentsong]->isPlaying) { lyricspanel->draw(ofGetWidth()*0.5,ofGetHeight()*gridY[1],scale); songs[currentsong]->draw(hOffs,scale); } else if (gamestate==GAME_PRACTICE) { practiceSong.draw(hOffs,scale); } break; case GAME_ENDPLAYING: //6 seconds to walk in / out -> 12 seconds turnaround //frames to start/cycle/stop walking //penguin: 11,35,11 //raccoon: 20,39,43r ofEnableAlphaBlending(); seg=((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001; wOffs=hOffs+(0.7*ofGetWidth()*seg); for (int i=0;i<3;i++) (*playanimal)[i].draw(wOffs+(gridX[i+1]*ofGetHeight()),gridY[0]*ofGetHeight(),scale); break; case GAME_WALKON: ofEnableAlphaBlending(); seg=((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001; wOffs=hOffs+(0.7*ofGetWidth()*(1.0f-seg)); for (int i=0;i<3;i++) (*playanimal)[i].draw(wOffs+(gridX[i+1]*ofGetHeight()),gridY[0]*ofGetHeight(),scale); break; } //draw tags and logos switch(gamestate) { case GAME_STARTINGADVERT: if (segamt<0.5) { ofEnableAlphaBlending(); ofSetColor(255,255,255,255-(segamt*510)); } else break; case GAME_ENDINGADVERT: if (segamt>0.5) { ofEnableAlphaBlending(); ofSetColor(255,255,255,((segamt-0.5)*510)); } else break; case GAME_READY: case GAME_STARTPLAYING: case GAME_PRACTICE: case GAME_PLAYING: case GAME_ENDPLAYING: case GAME_WALKON: ofEnableAlphaBlending(); if (gamestate!=GAME_STARTINGADVERT&&gamestate!=GAME_ENDINGADVERT) ofSetColor(255,255,255); for (int i=0;iisPlaying) tags[i]->draw(0.5f*ofGetWidth(),0,scale); } logos[0]->draw((gridX[0]*ofGetHeight())+hOffs,0,scale); break; } //draw banner, DCC logo and wirebirds bannerscale=scale; ofSetColor(255,255,255); switch(gamestate) { case GAME_PRACTICE: ofEnableAlphaBlending(); bannerscale=scale*(1.0f-(max(0.0,min(((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.002,1.0))*0.325)); wirebirds.draw(ofGetWidth()/2,ofGetHeight()*birdpoint,scale); segamt=1.0; ofEnableAlphaBlending(); banner.draw(ofGetWidth()*0.5,0,bannerscale); break; case GAME_STARTINGADVERT: if (segamt<0.5) { ofEnableAlphaBlending(); ofSetColor(255,255,255,255-(segamt*510)); } else break; case GAME_ENDINGADVERT: if (segamt>0.5) { ofEnableAlphaBlending(); ofSetColor(255,255,255,((segamt-0.5)*510)); } else break; case GAME_READY: ofEnableAlphaBlending(); banner.draw(ofGetWidth()*0.5,0,bannerscale); break; case GAME_STARTPLAYING: case GAME_PLAYING: if (showWire) wirebirds.draw(ofGetWidth()/2,ofGetHeight()*birdpoint,scale); bannerscale=scale*0.675; ofEnableAlphaBlending(); banner.draw(ofGetWidth()*0.5,0,bannerscale); break; case GAME_ENDPLAYING: case GAME_WALKON: //DCC LOGO logos[1]->draw((gridX[0]*ofGetHeight())+hOffs,gridY[1]*ofGetHeight(),scale); bannerscale=scale*(0.675+(max(0.0,min(((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001,1.0))*0.325)); ofEnableAlphaBlending(); banner.draw(ofGetWidth()*0.5,0,bannerscale); break; } //switch states: switch(gamestate) { case GAME_STARTINGINTRO: case GAME_INTRO: case GAME_ENDINGINTRO: case GAME_READY: break; case GAME_STARTINGADVERT: backgroundmusic.setVolume(max(0.0,1.0-(segamt*2.0))); case GAME_ADVERT: if (advert.getCurrentFrame()==advert.getTotalNumFrames()&&gamestate==GAME_ADVERT) { gamestate=GAME_ENDINGADVERT; segmentStartTime=ofGetElapsedTimeMillis(); } break; case GAME_ENDINGADVERT: backgroundmusic.setVolume(max(0.0,(segamt-0.5)*2.0)); case GAME_STARTPLAYING: case GAME_PRACTICE: break; case GAME_PLAYING: backgroundmusic.setVolume(max(0.0,1.0-(segamt*2.0))); if (!songs[currentsong]->isPlaying) { endGame(); } break; case GAME_ENDPLAYING: backgroundmusic.setVolume(max(0.0,(segamt-0.5)*2.0)); if (((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001>6.0) { gamestate=GAME_WALKON; switchAnimals(); } break; case GAME_WALKON: if (((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001>6.0) { gamestate=GAME_READY; segmentStartTime=ofGetElapsedTimeMillis(); } break; } } //-------------------------------------------------------------- void testApp::keyPressedEvent(ofKeyEventArgs &args) { //printf("window key pressed: %i (%c)\n",args.key,args.key); keyPressed(args.key); } void testApp::keyPressed(int key, ofxFenster* win){ //xprintf("window sent %i\n",key); if(key == '='){ fullscreenoutput=!fullscreenoutput; win->setFullscreen(fullscreenoutput); printf("resolution: %ix%i %s\n",win->getWidth(),win->getHeight(),fullscreenoutput?"fullscreen":"windowed"); } else keyPressed(key); } //-------------------------------------------------------------- void testApp::activateGame(){ segmentStartTime=ofGetElapsedTimeMillis(); currentlevel=0; currentsong=nextsong; songs[currentsong]->setTimeframe(timescale); songs[currentsong]->setFlakeThresh(threshStart,threshEnd); songs[currentsong]->setKeyThresh(keyThresh); songs[currentsong]->play(); tags[0]->play(); nextsong=(nextsong+1)%songs.size(); gamestate=GAME_PLAYING; } void testApp::activatePractice(){ segmentStartTime=ofGetElapsedTimeMillis(); gamestate=GAME_PRACTICE; currentlevel=0; practiceSong.setTimeframe(timescale); practiceSong.setFlakeThresh(threshStart,threshEnd); practiceSong.setKeyThresh(keyThresh); practiceSong.preRoll(5000); tags[5]->play(); } void testApp::switchAnimals(){ if (playanimal==&raccoons) playanimal=&penguins; else playanimal =&raccoons; } void testApp::endGame(){ string score=songs[currentsong]->getName()+":"+ofToString(((float)songs[currentsong]->getCurrentTime())*.001)+(songs[currentsong]->isFinished()?":finished":":level "+ofToString(currentlevel)); //printf("current time:%i length:%i \n",songs[currentsong]->getCurrentTime(),songs[currentsong]->getLength()) printf("score: %s\n",score.c_str()); game.endGame(score); gamestate=GAME_ENDPLAYING; tags[6]->play(); segmentStartTime=ofGetElapsedTimeMillis(); //6 seconds to walk in / out -> 12 seconds turnaround //frames to start/cycle/stop walking //penguin: 11,35,11 //raccoon: 20,39,43 //penguins: start + 289 = 8.25 //raccoons: start + 280 = 7.17 for (int i=0;i<3;i++) { (*playanimal)[i].play("Walk_start"); for (int j=0;j<9;j++) (*playanimal)[i].play("Walking"); } } //-------------------------------------------------------------- void testApp::keyPressed(int key){ switch (key) { case 'x': if (gamestate==GAME_READY||gamestate==GAME_PRACTICE) { activatePractice(); } break; case ' ': if (gamestate==GAME_PRACTICE) { activateGame(); } break; case '1': case '2': case '3': songs[currentsong]->playerControl(key-'1'); practiceSong.playerControl(key-'1'); (*playanimal)[key-'1'].playNow("Clap"); break; case 's': if (gamestate==GAME_READY) { game.startGame(); } break; case 'e': if (gamestate==GAME_PLAYING||gamestate==GAME_PRACTICE) { endGame(); } break; case 'q': if (gamestate==GAME_READY) { intro.firstFrame(); intro.play(); gamestate=GAME_INTRO; } break; case 'w': if (gamestate==GAME_READY) { segmentStartTime=ofGetElapsedTimeMillis(); gamestate=GAME_STARTINGADVERT; advert.firstFrame(); advert.play(); } break; case 'f': showFPS=!showFPS; break; case 'v': showVis=!showVis; break; case 'r': //loadanimals("Raccoons"); playanimal =&raccoons; break; case 'p': //loadanimals("Penguins"); playanimal =&penguins; break; } } //-------------------------------------------------------------- void testApp::keyReleased(int key){ switch (key) { case '1': case '2': case '3': break; } } //-------------------------------------------------------------- void testApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void testApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void testApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void testApp::dragEvent(ofDragInfo dragInfo){ }