summaryrefslogtreecommitdiff
path: root/vfg/src/music.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'vfg/src/music.cpp')
-rwxr-xr-xvfg/src/music.cpp49
1 files changed, 32 insertions, 17 deletions
diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp
index c920a02..4cddab9 100755
--- a/vfg/src/music.cpp
+++ b/vfg/src/music.cpp
@@ -213,8 +213,8 @@ void musicscore::drawFlakes(float hOffs,levelscore *levels,float scale) {
//else ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,255));
//if (iter->second->activated&&(!iter->second->disintegrated)) iter->second->disintegrate();
+ //ofSetColor(255,255,255); //allow external fading
- ofSetColor(255,255,255);
iter->second->draw((gridX[notemap(iter->second->num)+1]*ofGetHeight())+hOffs,ofGetHeight()-(thisstart*heightStep),scale);
//todo - make all drawing resolution independent
@@ -269,7 +269,8 @@ song::song(string backfile,string melfile,string musfile,string lyricfile,string
lyrics.load(lyricfile);
levels.load(levelfile);
isPlaying=false;
- isPractice=false;
+ isPractice=false;
+ fademillis=1000;
}
void song::setTimeframe(int millis) {notes.setTimeframe(millis);}
void song::setKeyThresh(int millis) {notes.keyThresh=millis;}
@@ -286,7 +287,8 @@ void song::play() {
void song::stop() {
backing.stop();
melody.stop();
- isPlaying=false;
+ isPlaying=false;
+ printf("stoppping song: %i (%i)\n",ofGetElapsedTimeMillis()-startTime,levels.length);
}
void song::preRoll(long preroll) {
startTime=ofGetElapsedTimeMillis()+preroll;
@@ -318,12 +320,18 @@ int song::getLength(){
}
bool song::isGameover(){
return gameover;
+}
+void song::gameOver(){
+
+ gameover=true;
+ gameoverTime=ofGetElapsedTimeMillis();
}
bool song::isFinished(){
return (ofGetElapsedTimeMillis()-startTime>=levels.length);
}
void song::draw(float hOffs,float scale){
- int songTime=ofGetElapsedTimeMillis()-startTime;
+ int songTime=ofGetElapsedTimeMillis()-startTime;
+ int fadeout=(gameover?max(0,255-((int)((((float)ofGetElapsedTimeMillis()-gameoverTime)/fademillis)*255))):255);
if (isPlaying) {
if (isPreroll&&(!isPractice)) {
if (startTime<ofGetElapsedTimeMillis()) {
@@ -331,29 +339,36 @@ void song::draw(float hOffs,float scale){
melody.play();
isPreroll=false;
}
- }
+ }
+ ofSetColor(255,255,255,fadeout);
notes.drawFlakes(hOffs,&levels,scale);
if (notes.missedLast) {
melody.setVolume(0.0f);
if (levels.getLives(songTime)) {
- if (notes.missedFlakes>levels.getLives(songTime)) {
+ if (notes.missedFlakes>levels.getLives(songTime)&&!gameover) {
//work out score
- //stop();
- gameover=true;
+ //stop();
+ printf("game over! %i (%i)\n",songTime,levels.length);
+ gameOver();
}
}
}
- else melody.setVolume(1.0f);
- if (!isPractice) lyrics.draw(hOffs);
- if (songTime>levels.length) {
- printf("stopping: %i (%i)\n",songTime,levels.length);
+ if (!notes.missedLast&&!gameover) melody.setVolume(1.0f);
+ if (!isPractice&&!gameover) lyrics.draw(hOffs);
+ if (songTime>levels.length&&!gameover) {
+ printf("finished! %i (%i)\n",songTime,levels.length);
+ //this played loads of times
//stop();
- gameover=true;
- }
- }
- else {
- //fade out song + melody :: clean up
+ gameOver();
+ }
+ ofSetColor(255,255,255);
+ if (gameover) {
+ melody.setVolume(notes.missedLast?0.0f:((float)fadeout)/255.0f);
+ backing.setVolume(((float)fadeout)/255.0f);
+ if (fadeout==0) stop();
+ }
}
+
}
void song::playerControl(int key){
notes.playerControl(key);