From 275acd8fe15ca66401cff428091772e7ab71444e Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sat, 10 Nov 2012 20:52:55 +0000 Subject: lyrics displaying correctly --- vfg/bin/data/verdana.ttf | Bin 0 -> 171792 bytes vfg/src/music.cpp | 30 ++++++++++++++++++++++++------ vfg/src/music.h | 30 +++++++++++++++++++++--------- vfg/vfg.layout | 10 +++++----- 4 files changed, 50 insertions(+), 20 deletions(-) create mode 100755 vfg/bin/data/verdana.ttf diff --git a/vfg/bin/data/verdana.ttf b/vfg/bin/data/verdana.ttf new file mode 100755 index 0000000..8f25a64 Binary files /dev/null and b/vfg/bin/data/verdana.ttf differ diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index 29b1ef6..ef43c11 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -1,7 +1,22 @@ #include "music.h" -//event times & durations are absolute integer milliseconds -//--------------------------------------------------------------------------------------------------------------------------------------------- +//event times & durations are absolute integer milliseconds + + +void lyricscore::draw(){ + int scoreTime=ofGetElapsedTimeMillis()-startTime; + map::iterator iter; + iter=lyrics.upper_bound(scoreTime); + if (iter!=lyrics.begin()) { + iter--; + 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); + } + } +} +//---------------------------------------------------------------------------------------------------------- musicscore::musicscore() { timeframe=2000; flake.loadImage("flake.png"); @@ -177,7 +192,8 @@ void song::play() { backing.play(); melody.play(); startTime=ofGetElapsedTimeMillis(); - notes.startTime=startTime; + notes.start(); + lyrics.start(); isPlaying=true; notes.makeFlakes(fThreshStart,fThreshEnd); } @@ -188,7 +204,8 @@ void song::stop() { } void song::preRoll(long preroll) { startTime=ofGetElapsedTimeMillis()+preroll; - notes.startTime=startTime; + notes.start(startTime); + lyrics.start(startTime); isPreroll=true; isPlaying=true; notes.makeFlakes(fThreshStart,fThreshEnd); @@ -213,9 +230,10 @@ void song::draw(){ } } else melody.setVolume(1.0f); - notes.draw(&levels); + notes.draw(&levels); + lyrics.draw(); } - + ofDrawBitmapString(ofToString((float)songTime/1000.0f,3)+" "+ofToString(levels.getLevel(songTime))+" "+ofToString(notes.missedFlakes)+" of "+ofToString(levels.getLives(songTime)),10,ofGetHeight()-15); } void song::playerControl(int key){ diff --git a/vfg/src/music.h b/vfg/src/music.h index 292e05f..f20838f 100755 --- a/vfg/src/music.h +++ b/vfg/src/music.h @@ -79,14 +79,22 @@ class lyric { class score { //basics of timelime public: - long startTime; - protected: + long startTime; + void start() { startTime=ofGetElapsedTimeMillis(); } + void start(int _st) { startTime=_st; } ofxXmlSettings XML; }; //--------------------------------------------------------------------------------------------------------------------------------------------- class lyricscore: public score { //draws lyrics to screen for a certain time - public: + public: + lyricscore() { + font.loadFont("verdana.ttf", 30, true, true); + font.setLineHeight(34.0f); + font.setLetterSpacing(1.035); + ypos=(int)(((float)ofGetHeight())*0.9f); //set lyric position + fadeout=500; //ms + } void load(string filename) { if( !XML.loadFile(filename) ){ printf("unable to load %s check data/ folder\n",filename.c_str()); @@ -99,11 +107,15 @@ class lyricscore: public score { } printf("processed %s: %i lyrics \n",filename.c_str(),lyrics.size()); } - + } - } + } + void draw(); private: - map lyrics; + map lyrics; + ofTrueTypeFont font; + int ypos; + int fadeout; }; //--------------------------------------------------------------------------------------------------------------------------------------------- class musicscore: public score { @@ -147,8 +159,8 @@ class song { levelscore levels; long startTime; bool isPreroll; - - int fThreshStart,fThreshEnd,keyThresh; + + int fThreshStart,fThreshEnd,keyThresh; }; //--------------------------------------------------------------------------------------------------------------------------------------------- /* @@ -163,7 +175,7 @@ Stage 2 Stage 3 – 4 notes missed will mean Game Over Stage 4 – 3 notes missed will mean Game Over -Scoring – Scoring will be based on the level of the game you achieve. There will be 4 scoring brackets (subject to testing and tweaking): +Scoring – Scoring will be based on the level of the game you achieve. There will be 4 scoring brackets (subject to testing and tweaking): Scoring Bracket 1 - Those who make it to Level 2 (see above - it's not possible to be kicked out in Level 1) Scoring Bracket 2 – Those who make it to Level 3 diff --git a/vfg/vfg.layout b/vfg/vfg.layout index 7fe831e..e831224 100644 --- a/vfg/vfg.layout +++ b/vfg/vfg.layout @@ -8,13 +8,13 @@ - + - - + + - - + + -- cgit v1.2.3