From 891b71c261a4571e0e0ba0e824e1bdb2478e0c65 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 19 Nov 2012 21:05:27 +0000 Subject: flake animations --- vfg/src/music.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'vfg/src/music.cpp') diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index 9fd88d3..ed442cd 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -29,10 +29,15 @@ void lyricscore::draw(){ //---------------------------------------------------------------------------------------------------------- musicscore::musicscore() { timeframe=2000; - flake.loadImage("flake.png"); - flake.setAnchorPercent(0.5,0.5); missedLast=false; nowpoint=1.0f; + + snowflakes.push_back(Puppet()); + snowflakes.push_back(Puppet()); + snowflakes.push_back(Puppet()); + snowflakes[0].load("Snowflake-Blue.xml"); + snowflakes[1].load("Snowflake-Purple.xml"); + snowflakes[2].load("Snowflake-Green.xml"); } void musicscore::parseMidi(string filename){ // millis = 60000 / (BPM * PPQ) @@ -126,11 +131,13 @@ void musicscore::makeFlakes(int threshStart,int threshEnd){ iter = notes.end(); iter--; float songDuration=iter->first; - flakes[notes.begin()->first]=notes.begin()->second; + flakes[notes.begin()->first]=new flake(notes.begin()->second->num,notes.begin()->second->velocity,notes.begin()->second->duration); + flakes[notes.begin()->first]->puppet=snowflakes[notemap(lastNote->num)]; for (iter = notes.begin(); iter != notes.end(); iter++) { float songPos=((float)iter->first)/songDuration; if ((notemap(iter->second->num)!=notemap(lastNote->num))||(iter->first-lastTime>((songPos*threshEnd)+((1.0f-songPos)*threshStart)))) { - flakes[iter->first]=iter->second; + flakes[iter->first]=new flake(iter->second->num,iter->second->velocity,iter->second->duration); + flakes[iter->first]->puppet=snowflakes[notemap(iter->second->num)]; } lastNote=iter->second; lastTime=iter->first; @@ -167,17 +174,22 @@ void musicscore::drawFlakes(levelscore *levels) { int firstnote=70; float widthStep=((float)ofGetWidth())/numnotes; float heightStep=((float)ofGetHeight())/timeframe; - map::iterator iter; + map::iterator iter; //draw flakes for (iter = flakes.lower_bound(scoreStart); iter != flakes.upper_bound(scoreEnd); iter++) { int thisnote=iter->second->num-firstnote; int thisstart=iter->first-scoreStart; 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((notemap(iter->second->num)*300)+100,ofGetHeight()-(thisstart*heightStep),flake.getWidth()/2,flake.getHeight()/2); - + + //if (iter->second->activated) ofSetColor(255,255,255); + //else ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,255)); + + //if (iter->second->activated&&(!iter->second->disintegrated)) iter->second->disintegrate(); + + ofSetColor(255,255,255); + iter->second->draw((notemap(iter->second->num)*300)+100,ofGetHeight()-(thisstart*heightStep)); //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? @@ -192,10 +204,10 @@ void musicscore::drawFlakes(levelscore *levels) { ofDisableAlphaBlending(); } void musicscore::playerControl(int key,int threshold){ - map::iterator iter; + map::iterator iter; int scoreTime=ofGetElapsedTimeMillis()-startTime; for (iter = flakes.lower_bound(scoreTime-threshold); iter != flakes.upper_bound(scoreTime+threshold); iter++) { - iter->second->activate(); + if (key==notemap(iter->second->num)) iter->second->activate(); } } //--------------------------------------------------------------------------------------------------------------------------------------------- -- cgit v1.2.3