From a0ab2cd35d91ba0080f9fb870d82aa90a51a0d6c Mon Sep 17 00:00:00 2001 From: Comment Date: Wed, 28 Nov 2012 18:40:32 +0000 Subject: nearly finished except latency --- vfg/src/Puppet.h | 1 + vfg/src/Tag.cpp | 18 ++++++++++++ vfg/src/Tag.h | 34 ++++++++++++++++++++++ vfg/src/music.cpp | 28 +++++++++++------- vfg/src/music.h | 22 +++++++------- vfg/src/testApp.cpp | 83 +++++++++++++++++++++++++++++++++++++---------------- vfg/src/testApp.h | 13 ++++++++- 7 files changed, 153 insertions(+), 46 deletions(-) create mode 100755 vfg/src/Tag.cpp create mode 100755 vfg/src/Tag.h (limited to 'vfg/src') diff --git a/vfg/src/Puppet.h b/vfg/src/Puppet.h index 7ee80ee..4bebb45 100755 --- a/vfg/src/Puppet.h +++ b/vfg/src/Puppet.h @@ -12,6 +12,7 @@ TODO: make resolution independent */ class puppetSprite: public ofxSprite { + //puppetSprite loops by default public: void draw(float x, float y, float scale) { getCurrentImage().draw(x-(anchorPoint.x*scale),y-(anchorPoint.y*scale),getWidth()*scale,getHeight()*scale); diff --git a/vfg/src/Tag.cpp b/vfg/src/Tag.cpp new file mode 100755 index 0000000..e3ad080 --- /dev/null +++ b/vfg/src/Tag.cpp @@ -0,0 +1,18 @@ +#include "Tag.h" + + +void Billboard::draw(float x, float y, float scale){ + img.draw(x-(anchorPoint.x*scale),y-(anchorPoint.y*scale),img.getWidth()*scale,img.getHeight()*scale); +} +void Tag::play(){ + isPlaying=true; + startTime=ofGetElapsedTimeMillis(); +} +void Tag::draw(float x, float y, float scale){ + float time=((float)ofGetElapsedTimeMillis()-startTime)/duration; + float yshift=0.0f; + if (time<0.4) yshift=pow((time/0.4),0.7)-1.0; + else if (time>0.75) yshift=-pow((time-0.75)/0.25,0.75); + img.draw(x-(anchorPoint.x*scale),y-(anchorPoint.y*scale)+(yshift*img.getHeight()*scale),img.getWidth()*scale,img.getHeight()*scale); + if ((ofGetElapsedTimeMillis()-startTime)>duration) isPlaying=false; +} diff --git a/vfg/src/Tag.h b/vfg/src/Tag.h new file mode 100755 index 0000000..a75e442 --- /dev/null +++ b/vfg/src/Tag.h @@ -0,0 +1,34 @@ +#ifndef TAG_H +#define TAG_H + +#include "ofMain.h" + +//class for resolution independent ofImage billbaord & level tag animator + +class Billboard +{ + public: + Billboard(string name,float xPct=0.5f,float yPct=0.5f) { + img.loadImage(name); + anchorPoint=ofPoint(img.getWidth()*xPct,img.getHeight()*yPct); + } + void draw(float x, float y, float scale=1.0f); + protected: + ofImage img; + ofPoint anchorPoint; + private: + +}; + +class Tag: public Billboard { + public: + Tag(string name,int d,float xPct=0.5f,float yPct=0.5f): Billboard(name,xPct,yPct) {duration =d; }; + void draw(float x, float y, float scale=1.0f); + void play(); + bool isPlaying; + protected: + int startTime; + int duration; +}; + +#endif // TAG_H diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index b5b584c..32f9d3e 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -3,13 +3,13 @@ //event times & durations are absolute integer milliseconds int notemap(int n) { - //nonlinear mapping of notes to 3 columns - space 5,4,7 - //note drawing 46h - 52h + //nonlinear mapping of notes to 3 columns - space 5,4,7 - trying 5,5,6 + //note drawing 46h - 52h int numnotes=16; int firstnote=70; int note=n-firstnote; if (note<5) return 0; - else if (note <9) return 1; + else if (note <10) return 1; else return 2; } //---------------------------------------------------------------------------------------------------------- @@ -22,7 +22,7 @@ void lyricscore::draw(){ if ((iter->first+iter->second->duration)>scoreTime) { //outpoint of lyric previous to the one next soonest is afterwards => this lyric is visible int alpha=((iter->first+iter->second->duration)-scoreTime)first+iter->second->duration)-scoreTime))/((float)fadeout))*255.0f):255; ofSetColor(255,255,255,alpha); - font.drawString(iter->second->text,(ofGetWidth()/2)-(font.stringWidth(iter->second->text)/2.0f), ypos); + font.drawString(iter->second->text,(ofGetWidth()/2)-(font.stringWidth(iter->second->text)/2.0f), gridY[1]*ofGetHeight()); } } } @@ -164,16 +164,15 @@ void musicscore::drawNotes(levelscore *levels) { int thisnote=iter->second->num-firstnote; int thisstart=iter->first-scoreStart; int thislength=iter->second->duration; - ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,100),120); + ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,100),(((float)(thisstart*heightStep))/ofGetHeight()*128)+32); ofRect(thisnote*widthStep,ofGetHeight()-(thisstart*heightStep),widthStep,-(thislength*heightStep)); } } -void musicscore::drawFlakes(levelscore *levels) { +void musicscore::drawFlakes(levelscore *levels,float scale) { ofEnableAlphaBlending(); int scoreStart=ofGetElapsedTimeMillis()-startTime-((1.0f-nowpoint)*timeframe); int scoreEnd=scoreStart+timeframe; - float scale=ofGetHeight()/1080.0f; //note drawing 46h - 52h int numnotes=16; int firstnote=70; @@ -192,7 +191,7 @@ void musicscore::drawFlakes(levelscore *levels) { //if (iter->second->activated&&(!iter->second->disintegrated)) iter->second->disintegrate(); ofSetColor(255,255,255); - iter->second->draw(gridX[notemap(iter->second->num)]*ofGetWidth(),ofGetHeight()-(thisstart*heightStep),scale); + iter->second->draw(gridX[notemap(iter->second->num)+1]*ofGetWidth(),ofGetHeight()-(thisstart*heightStep),scale); //todo - make all drawing resolution independent } @@ -246,6 +245,9 @@ void song::setFlakeThresh(int tS,int tE) { fThreshStart=tS; fThreshEnd=tE; } +int song::getCurrentTime(){ + return ofGetElapsedTimeMillis()-startTime; +} void song::play() { backing.play(); melody.play(); @@ -271,7 +273,7 @@ void song::preRoll(long preroll) { void song::drawNotes(){ notes.drawNotes(&levels); } -void song::draw(){ +void song::draw(float scale){ int songTime=ofGetElapsedTimeMillis()-startTime; if (isPlaying) { if (isPreroll) { @@ -291,11 +293,15 @@ void song::draw(){ } } else melody.setVolume(1.0f); - notes.drawFlakes(&levels); + notes.drawFlakes(&levels,scale); lyrics.draw(); + if (songTime>levels.length) { + printf("stopping: %i (%i)\n",songTime,levels.length); + stop(); + } } - ofDrawBitmapString(ofToString((float)songTime/1000.0f,1)+" "+ofToString(levels.getLevel(songTime))+" "+ofToString(notes.missedFlakes)+" of "+ofToString(levels.getLives(songTime)),10,ofGetHeight()-15); + ofDrawBitmapString(ofToString((float)songTime/1000.0f,1)+" "+ofToString(levels.getLevel(songTime))+" "+ofToString(notes.missedFlakes)+" of "+ofToString(levels.getLives(songTime)),10,(ofGetHeight()*gridY[1])-3); } void song::playerControl(int key){ notes.playerControl(key,keyThresh); diff --git a/vfg/src/music.h b/vfg/src/music.h index 1cb92ff..a1eddc4 100755 --- a/vfg/src/music.h +++ b/vfg/src/music.h @@ -5,8 +5,8 @@ #include "Puppet.h" //Grid for drawing -static float gridX[3]={0.3,0.5,0.7}; -static float gridY[1]={0.8}; +static float gridX[4]={0.1083,0.3,0.5,0.7}; +static float gridY[2]={0.7713,0.963}; //event times are absolute integer milliseconds //--------------------------------------------------------------------------------------------------------------------------------------------- @@ -18,6 +18,7 @@ class levelscore { printf("unable to load %s check data/ folder\n",filename.c_str()); }else{ int multiplier=1000/XML.getAttribute("VFxmas", "timebase",1000,0); + length=XML.getAttribute("VFxmas", "length",0,0)*multiplier; if(XML.pushTag("VFxmas")) { for (int i=0;i levels; + }; //--------------------------------------------------------------------------------------------------------------------------------------------- class note { @@ -121,11 +124,10 @@ class lyricscore: public score { //draws lyrics to screen for a certain time public: lyricscore() { - font.loadFont("verdana.ttf", 30, true, true); - font.setLineHeight(34.0f); - font.setLetterSpacing(1.035); - ypos=(int)(((float)ofGetHeight())*0.97f); //set lyric position - fadeout=500; //ms + font.loadFont("VodafoneRg_Bd.ttf", 31*(ofGetHeight()/1080.0f), true, true); //hard coded scaling + font.setLineHeight(34.0f); + font.setLetterSpacing(1.035); + fadeout=500; //ms } void load(string filename) { if( !XML.loadFile(filename) ){ @@ -146,7 +148,6 @@ class lyricscore: public score { private: map lyrics; ofTrueTypeFont font; - int ypos; int fadeout; }; //--------------------------------------------------------------------------------------------------------------------------------------------- @@ -158,7 +159,7 @@ class musicscore: public score { void setTimeframe(int millis); void setNowpoint(float pct); void drawNotes(levelscore *levels); - void drawFlakes(levelscore *levels); + void drawFlakes(levelscore *levels,float scale); void playerControl(int key,int threshold); void makeFlakes(int threshStart,int threshEnd,levelscore *levels); @@ -189,12 +190,13 @@ class song { void setFlakeThresh(int tS,int tE); void setKeythresh(int millis); void drawNotes(); - void draw(); + void draw(float scale); int missedNote(); int hitNote(); bool isPlaying; void playerControl(int key); int getLevel(long time); + int getCurrentTime(); private: ofSoundPlayer backing; ofSoundPlayer melody; diff --git a/vfg/src/testApp.cpp b/vfg/src/testApp.cpp index 4385593..d20bb23 100755 --- a/vfg/src/testApp.cpp +++ b/vfg/src/testApp.cpp @@ -3,12 +3,9 @@ //-------------------------------------------------------------- void testApp::setup(){ - //testsong=new song("VODA_MUS_DeckTheHalls-Backing_v.1.5.mp3","VODA_MUS_DeckTheHalls-Melody_v.1.5.mp3","MIDI_DeckTheHalls_MIDI.1.5.xml","Lyrics_DeckTheHalls.1.5.xml","Levels_DeckTheHalls.1.5.xml"); - testsong=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"); + 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")); + 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")); - testsong->setTimeframe(3000); - testsong->setFlakeThresh(1000,100); - ofSetBackgroundAuto(false); ofBackground(0,0,0); @@ -23,7 +20,21 @@ void testApp::setup(){ 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)); + + 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_%05i.png",500); + banner.setAnchorPercent(0.5,0.0); + banner.setFrameRate(50); + banner.play(); //loadanimals("Raccoons"); playanimal =&penguins; @@ -43,7 +54,8 @@ void testApp::setup(){ showFPS=false; - + currentsong=0; + nextsong=0; } /* void testApp::loadanimals(string which) { @@ -66,7 +78,7 @@ void testApp::loadanimals(string which) { */ void testApp::exit(){ - delete testsong; + delete lyricspanel; } //-------------------------------------------------------------- @@ -74,26 +86,32 @@ void testApp::update(){ int ret=game.update(); if (ret==1000) { currentlevel=0; - testsong->preRoll(250); + currentsong=nextsong; + songs[currentsong]->setTimeframe(3000); + songs[currentsong]->setFlakeThresh(1000,100); + songs[currentsong]->preRoll(750); + tags[0]->play(); } else if (ret>48&&ret<52) { - testsong->playerControl(ret-48); + songs[currentsong]->playerControl(ret-48); (*playanimal)[ret-49].playNow("Clap"); } - if (testsong->isPlaying&&testsong->getLevel(ofGetElapsedTimeMillis()+2000)>currentlevel) { + 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; } - //printf("finished level %i!\n",currentlevel); + tags[currentlevel+1]->play(); currentlevel++; + printf("finished level %i!\n",currentlevel); } for (int i=0;i<3;i++) { (*playanimal)[i].update(); } background.update(); + banner.update(); } //-------------------------------------------------------------- @@ -111,23 +129,35 @@ void testApp::draw(){ ofRect(0,0,ofGetWidth(),ofGetHeight()); */ - if (testsong->isPlaying) { + if (songs[currentsong]->isPlaying) { ofSetColor(255,255,255); - testsong->drawNotes(); - int missed=testsong->missedNote(); + songs[currentsong]->drawNotes(); + int missed=songs[currentsong]->missedNote(); if (missed>-1) (*playanimal)[missed].playNow("Shudder"); - int hit=testsong->hitNote(); + int hit=songs[currentsong]->hitNote(); if (hit>-1) (*playanimal)[hit].play("Catch"); } ofSetColor(255,255,255); - for (int i=0;i<3;i++) (*playanimal)[i].draw(gridX[i]*ofGetWidth(),gridY[0]*ofGetHeight(),scale); - if (testsong->isPlaying) { + for (int i=0;i<3;i++) (*playanimal)[i].draw(gridX[i+1]*ofGetWidth(),gridY[0]*ofGetHeight(),scale); + if (songs[currentsong]->isPlaying) { ofSetColor(255,255,255); - testsong->draw(); + lyricspanel->draw(ofGetWidth()*0.5,ofGetHeight()*gridY[1],scale); + songs[currentsong]->draw(scale); } - else ofDrawBitmapString("game over!", (ofGetWidth()/2)-25,(ofGetHeight()/2)-5); - - if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate()), ofGetWidth()-50,ofGetHeight()-15); + else { + ofDrawBitmapString("game over!", (ofGetWidth()/2)-25,(ofGetHeight()/2)-5); + logos[1]->draw(gridX[0]*ofGetWidth(),gridY[1]*ofGetHeight(),scale); + } + ofSetColor(255,255,255); + for (int i=0;iisPlaying) tags[i]->draw(0.5f*ofGetWidth(),0,scale); + } + logos[0]->draw(gridX[0]*ofGetWidth(),0,scale); + float bannerscale=songs[currentsong]->isPlaying?scale*(1.0f-(max(0.0,min(((float)songs[currentsong]->getCurrentTime())*.001,1.0))*0.325)):scale; + banner.draw(ofGetWidth()*0.5,0,bannerscale); + char buf[30]; + sprintf(buf,"%.1f",ofGetFrameRate()); + if (showFPS) ofDrawBitmapString(buf, ofGetWidth()-50,(ofGetHeight()*gridY[1])-3); } @@ -135,15 +165,20 @@ void testApp::draw(){ void testApp::keyPressed(int key){ switch (key) { case ' ': - if (!testsong->isPlaying) { + nextsong=(nextsong+1)%songs.size(); + if (!songs[currentsong]->isPlaying) { currentlevel=0; - testsong->preRoll(250); + currentsong=nextsong; + songs[currentsong]->setTimeframe(3000); + songs[currentsong]->setFlakeThresh(1000,100); + songs[currentsong]->preRoll(750); + tags[0]->play(); } break; case '1': case '2': case '3': - testsong->playerControl(key-'1'); + songs[currentsong]->playerControl(key-'1'); (*playanimal)[key-'1'].playNow("Clap"); break; case 's': diff --git a/vfg/src/testApp.h b/vfg/src/testApp.h index 2518b55..143885c 100755 --- a/vfg/src/testApp.h +++ b/vfg/src/testApp.h @@ -7,6 +7,7 @@ #include "Asterisk.h" #include "Puppet.h" #include "Animal.h" +#include "Tag.h"; /* this library? @@ -78,16 +79,24 @@ class testApp : public ofBaseApp{ ofVideoPlayer background; ofImage vignette; - song *testsong; + vector songs; vector penguins; vector raccoons; + vector > animals; //vector playanimals; vector* playanimal; + vector tags; + + vector logos; + + puppetSprite banner; + + Billboard* lyricspanel; Puppet testpenguin; int currentlevel; @@ -95,6 +104,8 @@ class testApp : public ofBaseApp{ Asterisk game; bool showFPS; + + int currentsong,nextsong; }; -- cgit v1.2.3