From 27b7b4c5ce0102c6089cd0b6cc58096b0c5ccf36 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 13 Nov 2012 00:16:01 +0000 Subject: penguin sprites --- vfg/src/music.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'vfg/src/music.cpp') diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index ef43c11..4d62f6f 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -21,7 +21,8 @@ musicscore::musicscore() { timeframe=2000; flake.loadImage("flake.png"); flake.setAnchorPercent(0.5,0.5); - missedLast=false; + missedLast=false; + nowpoint=1.0f; } void musicscore::parseMidi(string filename){ // millis = 60000 / (BPM * PPQ) @@ -124,10 +125,10 @@ void musicscore::makeFlakes(int threshStart,int threshEnd){ lastTime=iter->first; } } -void musicscore::setTimeframe(int millis) {timeframe=millis;} -void musicscore::draw(levelscore *levels) { - ofEnableAlphaBlending(); - int scoreStart=ofGetElapsedTimeMillis()-startTime; +void musicscore::setTimeframe(int millis) {timeframe=millis;} +void musicscore::setNowpoint(float pct) {nowpoint=pct;} +void musicscore::drawNotes(levelscore *levels) { + int scoreStart=ofGetElapsedTimeMillis()-startTime-((1.0f-nowpoint)*timeframe); int scoreEnd=scoreStart+timeframe; //note drawing 46h - 52h int numnotes=16; @@ -144,6 +145,18 @@ void musicscore::draw(levelscore *levels) { ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,100)); ofRect(thisnote*widthStep,ofGetHeight()-(thisstart*heightStep),widthStep,-(thislength*heightStep)); } + +} +void musicscore::drawFlakes(levelscore *levels) { + ofEnableAlphaBlending(); + int scoreStart=ofGetElapsedTimeMillis()-startTime-((1.0f-nowpoint)*timeframe); + int scoreEnd=scoreStart+timeframe; + //note drawing 46h - 52h + int numnotes=16; + int firstnote=70; + float widthStep=((float)ofGetWidth())/numnotes; + float heightStep=((float)ofGetHeight())/timeframe; + map::iterator iter; //draw flakes for (iter = flakes.lower_bound(scoreStart-200); iter != flakes.upper_bound(scoreEnd); ++iter) { //extra 200ms for flake to leave screen int thisnote=iter->second->num-firstnote; @@ -151,7 +164,9 @@ void musicscore::draw(levelscore *levels) { int thislength=iter->second->duration; if (iter->second->activated) ofSetColor(255,255,255); else ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,255)); - flake.draw((((thisnote/5)*5)+3.5f)*widthStep,ofGetHeight()-(thisstart*heightStep),flake.getWidth()/2,flake.getHeight()/2); + flake.draw(((thisnote/5)*300)+100,ofGetHeight()-(thisstart*heightStep),flake.getWidth()/2,flake.getHeight()/2); + + //todo - make all drawing resolution independent } //check for unactivated flakes within this segment: is there a more efficient way? //is it the number of flakes they can lose per segment? @@ -180,7 +195,8 @@ song::song(string backfile,string melfile,string musfile,string lyricfile,string lyrics.load(lyricfile); levels.load(levelfile); isPlaying=false; - keyThresh=200; + keyThresh=200; + notes.setNowpoint(0.8f); } void song::setTimeframe(int millis) {notes.setTimeframe(millis);} void song::setKeythresh(int millis) {keyThresh=millis;} @@ -210,6 +226,9 @@ void song::preRoll(long preroll) { isPlaying=true; notes.makeFlakes(fThreshStart,fThreshEnd); } +void song::drawNotes(){ + notes.drawNotes(&levels); +} void song::draw(){ int songTime=ofGetElapsedTimeMillis()-startTime; if (isPlaying) { @@ -230,11 +249,11 @@ void song::draw(){ } } else melody.setVolume(1.0f); - notes.draw(&levels); + notes.drawFlakes(&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); + ofDrawBitmapString(ofToString((float)songTime/1000.0f,1)+" "+ofToString(levels.getLevel(songTime))+" "+ofToString(notes.missedFlakes)+" of "+ofToString(levels.getLives(songTime)),10,ofGetHeight()-15); } void song::playerControl(int key){ notes.playerControl(key,keyThresh); -- cgit v1.2.3