diff options
| author | Tim Redfern <tim@gray.(none)> | 2012-11-10 20:52:55 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@gray.(none)> | 2012-11-10 20:52:55 +0000 |
| commit | 275acd8fe15ca66401cff428091772e7ab71444e (patch) | |
| tree | 9a122a9385ff56006a67a37e34e0c41bee690873 | |
| parent | eda90b505d3a583e0c3788ca1ad924d75b02fe01 (diff) | |
lyrics displaying correctly
| -rwxr-xr-x | vfg/bin/data/verdana.ttf | bin | 0 -> 171792 bytes | |||
| -rwxr-xr-x | vfg/src/music.cpp | 30 | ||||
| -rwxr-xr-x | vfg/src/music.h | 30 | ||||
| -rw-r--r-- | vfg/vfg.layout | 10 |
4 files changed, 50 insertions, 20 deletions
diff --git a/vfg/bin/data/verdana.ttf b/vfg/bin/data/verdana.ttf Binary files differnew file mode 100755 index 0000000..8f25a64 --- /dev/null +++ b/vfg/bin/data/verdana.ttf 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<int,lyric*>::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)<fadeout?(int)((((float)((iter->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<int,lyric*> lyrics;
+ map<int,lyric*> 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 – 5 notes missed will mean Game Over 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 @@ <Cursor position="219" topLine="0" /> </File> <File name="src/music.cpp" open="1" top="0" tabpos="2"> - <Cursor position="6645" topLine="145" /> + <Cursor position="270" topLine="0" /> </File> - <File name="src/music.h" open="1" top="1" tabpos="3"> - <Cursor position="2920" topLine="67" /> + <File name="src/music.h" open="1" top="0" tabpos="3"> + <Cursor position="3005" topLine="0" /> </File> - <File name="src/testApp.cpp" open="0" top="0" tabpos="2"> - <Cursor position="1017" topLine="5" /> + <File name="src/testApp.cpp" open="1" top="1" tabpos="4"> + <Cursor position="1017" topLine="0" /> </File> <File name="src/testApp.h" open="0" top="0" tabpos="1"> <Cursor position="576" topLine="0" /> |
