diff options
Diffstat (limited to 'vfg/src')
| -rwxr-xr-x | vfg/src/music.cpp | 41 | ||||
| -rwxr-xr-x | vfg/src/music.h | 16 | ||||
| -rwxr-xr-x | vfg/src/testApp.cpp | 22 | ||||
| -rwxr-xr-x | vfg/src/testApp.h | 10 |
4 files changed, 85 insertions, 4 deletions
diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index bbdfdc9..286bdcb 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -6,6 +6,7 @@ note::note(int n,int v,int d){ num=n;
velocity=v;
duration=d;
+ activated=false;
}
//---------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------
@@ -98,7 +99,7 @@ void musicscore::parseMidi(string filename){ iter1--;
printf("processed %s: length %f, %i notes in %f seconds\n",filename.c_str(),((float)(iter1->first+iter1->second->duration)*.001f),notes.size(),ofGetElapsedTimef()-wt);
- //decimate notes to generate flakes that can be interacted with
+//decimate notes to generate flakes that can be interacted with
int noteThresh=1000;
note *lastNote=notes.begin()->second;
int lastTime=0;
@@ -111,6 +112,10 @@ void musicscore::parseMidi(string filename){ lastTime=iter1->first;
}
+ interactionThresh=100; //how long player has to respond
+ missedTime=-1;
+
+
}
void musicscore::setTimeframe(int millis) {timeframe=millis;}
void musicscore::draw() {
@@ -144,17 +149,38 @@ void musicscore::draw() { int thisnote=iter->second->num-firstnote;
int thisstart=iter->first-scoreStart;
int thislength=iter->second->duration;
- ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,255));
+
+ // check player interaction
+ if (thisstart<interactionThresh) {
+ //this star needs to be interacted with
+ if (((thisnote/5)+1)==playerKey) {
+ //success!
+ iter->second->playerActivated();
+ }
+ }
+ 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));
}
+ //check for unactivated stars. must be a better way
+ missedTime=-1;
+ for (iter = stars.upper_bound(scoreStart); iter != stars.lower_bound(0); --iter) {
+ if (!iter->second->activated) missedTime=scoreStart-iter->first;
+ else break;
+ }
ofDisableAlphaBlending();
}
+void musicscore::playerControl(int key){
+ //0-3 - 0 is off
+ playerKey=key;
+}
//---------------------------------------------------------------------------------------------------------------------------------------------
song::song(string backfile,string melfile,string notefile) {
backing.loadSound(backfile);
melody.loadSound(melfile);
notes.parseMidi(notefile);
- isPlaying=false;
+ isPlaying=false;
+ missedInterval=5000;
}
void song::setTimeframe(int millis) {notes.setTimeframe(millis);}
void song::play() {
@@ -184,5 +210,14 @@ void song::draw(){ isPreroll=false;
}
}
+ if (notes.missedTime>0) {
+ if (notes.missedTime>missedInterval) stop();
+ else melody.setVolume(1.0f-((float)notes.missedTime/(float)missedInterval));
+ }
+ else melody.setVolume(1.0f);
notes.draw();
+}
+void song::playerControl(int key){
+ //0-3 - 0 is off
+ notes.playerControl(key);
} diff --git a/vfg/src/music.h b/vfg/src/music.h index aa38f46..39ffd95 100755 --- a/vfg/src/music.h +++ b/vfg/src/music.h @@ -12,6 +12,8 @@ class note { int velocity;
int duration; //may be needed another time?
int updown; //-1 0 1 used for 3-button interaction
+ bool activated;
+ void playerActivated() { activated=true; }
};
//---------------------------------------------------------------------------------------------------------------------------------------------
class score {
@@ -34,11 +36,21 @@ class musicscore: public score { void parseMidi(string filename);
void setTimeframe(int millis);
void draw();
+
+ void playerControl(int key);
+ //in wrong object?
+ int missedTime;
private:
map<int,note*> notes; map<int,note*> stars;
int timeframe;
ofImage flake;
+
+ //in wrong object?
+ int interactionThresh;
+
+
+ int playerKey;
};
//---------------------------------------------------------------------------------------------------------------------------------------------
class song {
@@ -50,6 +62,7 @@ class song { void setTimeframe(int millis);
void draw();
bool isPlaying;
+ void playerControl(int key);
private:
ofSoundPlayer backing;
ofSoundPlayer melody;
@@ -57,6 +70,9 @@ class song { musicscore notes;
long startTime;
bool isPreroll;
+
+ int missedInterval;
+
};
//---------------------------------------------------------------------------------------------------------------------------------------------
diff --git a/vfg/src/testApp.cpp b/vfg/src/testApp.cpp index 675baef..2a67d8f 100755 --- a/vfg/src/testApp.cpp +++ b/vfg/src/testApp.cpp @@ -25,16 +25,36 @@ void testApp::draw(){ ofSetColor(0,0,0,100); ofRect(0,0,ofGetWidth(),ofGetHeight()); if (testsong->isPlaying) testsong->draw(); + else { + ofSetColor(255,255,255); + ofDrawBitmapString("game over!", (ofGetWidth()/2)-25,(ofGetHeight()/2)-5); + } } //-------------------------------------------------------------- void testApp::keyPressed(int key){ + switch (key) { + case '0': + if (!testsong->isPlaying) testsong->preRoll(250); + break; + case '1': + case '2': + case '3': + testsong->playerControl(key-'0'); + break; + } } //-------------------------------------------------------------- void testApp::keyReleased(int key){ - + switch (key) { + case '1': + case '2': + case '3': + testsong->playerControl(0); + break; + } } //-------------------------------------------------------------- diff --git a/vfg/src/testApp.h b/vfg/src/testApp.h index 94691a5..cb29222 100755 --- a/vfg/src/testApp.h +++ b/vfg/src/testApp.h @@ -22,6 +22,16 @@ Maximilian is an audio synthesis and signal processing library written in C++. I - realtime music information retrieval functions: spectrum analysis, spectral features, octave analysis, and MFCCs - example projects for Windows and MacOS, using command line and OpenFrameworks environments + + +game design demo + +state - game started, game over + +while playing - game full volume - if you miss a flake - starts countdown - game gets quieter and stars get fainter - when countdown is down 'game over' + +keys - volume - control drawing of stars - game state + */ class game { |
