diff options
Diffstat (limited to 'vfg')
| -rw-r--r-- | vfg/src/Animal.cpp | 13 | ||||
| -rw-r--r-- | vfg/src/Animal.h | 19 | ||||
| -rwxr-xr-x | vfg/src/Puppet.cpp | 9 | ||||
| -rwxr-xr-x | vfg/src/Puppet.h | 15 | ||||
| -rwxr-xr-x | vfg/src/music.cpp | 42 | ||||
| -rwxr-xr-x | vfg/src/music.h | 19 | ||||
| -rwxr-xr-x | vfg/src/testApp.cpp | 36 | ||||
| -rwxr-xr-x | vfg/src/testApp.h | 8 |
8 files changed, 113 insertions, 48 deletions
diff --git a/vfg/src/Animal.cpp b/vfg/src/Animal.cpp new file mode 100644 index 0000000..815aa81 --- /dev/null +++ b/vfg/src/Animal.cpp @@ -0,0 +1,13 @@ +#include "Animal.h"
+
+Animal::Animal()
+{
+ //ctor
+}
+
+Animal::~Animal()
+{
+ //dtor
+}
+void Animal::update(){ +} diff --git a/vfg/src/Animal.h b/vfg/src/Animal.h new file mode 100644 index 0000000..4155901 --- /dev/null +++ b/vfg/src/Animal.h @@ -0,0 +1,19 @@ +#ifndef ANIMAL_H
+#define ANIMAL_H + +#include "ofMain.h"
+#include "ofxXmlSettings.h"
+#include "Puppet.h"
+
+
+class Animal: public Puppet
+{
+ public:
+ Animal();
+ virtual ~Animal(); + void update();
+ protected:
+ private:
+};
+
+#endif // ANIMAL_H
diff --git a/vfg/src/Puppet.cpp b/vfg/src/Puppet.cpp index 46eee5e..0fd07a6 100755 --- a/vfg/src/Puppet.cpp +++ b/vfg/src/Puppet.cpp @@ -58,9 +58,16 @@ void Puppet::play(string clip){ if (playlist.size()==1) clips[playlist[0]].play();
//printf("playing %s, %i, %s\n",playlist[0].c_str(),playlist.size(),clips[playlist[0]].getIsPlaying()?"true":"false");
}
+} +void Puppet::playNow(string clip){ + if (playlist.size()>0) { + clips[playlist[0]].stop(); + playlist.clear(); + } + play(clip); }
bool Puppet::isPlaying(){
if (playlist.size()>0) return clips[playlist[0]].getIsPlaying();
else return false;
-}
\ No newline at end of file +} diff --git a/vfg/src/Puppet.h b/vfg/src/Puppet.h index 91f32fd..e0df87a 100755 --- a/vfg/src/Puppet.h +++ b/vfg/src/Puppet.h @@ -8,7 +8,7 @@ /*
"base" clip will be drawn unless another clip is playing
-TODO: make resolution independent
+TODO: make resolution independent
*/
class Puppet
@@ -16,14 +16,15 @@ class Puppet public:
Puppet();
virtual ~Puppet();
- void load(string filename);
- void play(string clip);
- void draw(float x, float y);
- bool isPlaying();
+ void load(string filename);
+ void play(string clip); + void playNow(string clip);
+ void draw(float x, float y);
+ bool isPlaying();
protected:
private:
- map<string,ofxSprite> clips;
- deque<string> playlist;
+ map<string,ofxSprite> clips;
+ deque<string> playlist;
};
#endif // PUPPET_H
diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index ed442cd..eda58be 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -10,7 +10,7 @@ int notemap(int n) { int note=n-firstnote;
if (note<5) return 0;
else if (note <9) return 1;
- else return 2;
+ else return 2;
} //---------------------------------------------------------------------------------------------------------- void lyricscore::draw(){ @@ -30,8 +30,9 @@ void lyricscore::draw(){ musicscore::musicscore() {
timeframe=2000;
missedLast=false; - nowpoint=1.0f;
-
+ nowpoint=1.0f; + missedNote=-1;
+
snowflakes.push_back(Puppet());
snowflakes.push_back(Puppet());
snowflakes.push_back(Puppet());
@@ -141,7 +142,9 @@ void musicscore::makeFlakes(int threshStart,int threshEnd){ }
lastNote=iter->second;
lastTime=iter->first;
- }
+ } + missedFlake=flakes.end(); + missedNote=-1;
}
void musicscore::setTimeframe(int millis) {timeframe=millis;} void musicscore::setNowpoint(float pct) {nowpoint=pct;}
@@ -180,27 +183,37 @@ void musicscore::drawFlakes(levelscore *levels) { 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));
-
+
//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?
+ //check for unactivated flakes within this segment: is there a more efficient way? + //need to know when a flake has just been missed +
missedFlakes=0;
- missedLast=false;
+ missedLast=false; + map<int,flake*>::iterator missed=flakes.end();
+ int scoreTime=ofGetElapsedTimeMillis()-startTime;
for (iter = flakes.lower_bound(levels->getLowerBound(levels->getLevel(scoreStart))); iter != flakes.upper_bound(scoreStart); iter++){
if (!iter->second->activated) {
- missedFlakes++;
+ missedFlakes++; + missed=iter;
}
missedLast=!iter->second->activated;
- }
+ } + if ((missed!=flakes.end())&&(missedFlake!=missed)) { + missedFlake=missed; + missedNote=notemap(iter->second->num); + } + else missedNote=-1; +
ofDisableAlphaBlending();
}
void musicscore::playerControl(int key,int threshold){
@@ -281,3 +294,6 @@ void song::draw(){ void song::playerControl(int key){
notes.playerControl(key,keyThresh);
} +int song::missedNote(){
+ return notes.missedNote;
+} diff --git a/vfg/src/music.h b/vfg/src/music.h index 96c8e1d..f9317de 100755 --- a/vfg/src/music.h +++ b/vfg/src/music.h @@ -64,20 +64,18 @@ class note { int duration; //may be needed another time?
};
//---------------------------------------------------------------------------------------------------------------------------------------------
-class flake: public note {
+class flake: public note, public Puppet {
public:
flake(int n,int v,int d=0) : note(n,v,d) { activated=false; }
Puppet puppet;
bool activated;
- void activate() {
+ void activate() {
activated=true;
puppet.play("shatter");
}
void draw(float x, float y) {
if (!activated||puppet.isPlaying()) puppet.draw(x,y);
}
- bool disintegrated;
- void disintegrate() { disintegrated=true; }
};
//---------------------------------------------------------------------------------------------------------------------------------------------
class lyric {
@@ -144,18 +142,20 @@ class musicscore: public score { void playerControl(int key,int threshold);
void makeFlakes(int threshStart,int threshEnd);
- int missedFlakes;
+ int missedFlakes; + int missedNote;
bool missedLast;
bool perfect;
private:
map<int,note*> notes;
- map<int,flake*> flakes;
+ map<int,flake*> flakes; + map<int,flake*>::iterator missedFlake;
int timeframe; float nowpoint;
-
+
vector<Puppet> snowflakes;
-
+
};
//---------------------------------------------------------------------------------------------------------------------------------------------
class song {
@@ -168,7 +168,8 @@ class song { void setFlakeThresh(int tS,int tE);
void setKeythresh(int millis);
void drawNotes();
- void draw();
+ void draw(); + int missedNote();
bool isPlaying;
void playerControl(int key);
private:
diff --git a/vfg/src/testApp.cpp b/vfg/src/testApp.cpp index ddc5cfe..8dd6110 100755 --- a/vfg/src/testApp.cpp +++ b/vfg/src/testApp.cpp @@ -13,7 +13,12 @@ void testApp::setup(){ ofBackground(0,0,0); //printf("%s\n",ofVAArgsToString("Penguin-Clap-Blue_00000.png", 1).c_str()); ??? - for (int i=0;i<3;i++) penguins.push_back(ofxSprite()); + for (int i=0;i<3;i++) penguins.push_back(Animal()); + penguins[0].load("Penguin-Blue.xml"); + penguins[1].load("Penguin-Purple.xml"); + penguins[2].load("Penguin-Green.xml"); + + /* penguins[0].load("Penguin-Clap-Blue/Penguin-Clap-Blue_%05i.png",20); penguins[0].setAnchorPercent(0.5, 1.0); penguins[0].setFrameRate(50); @@ -26,19 +31,20 @@ void testApp::setup(){ penguins[2].setAnchorPercent(0.5, 1.0); penguins[2].setFrameRate(50); penguins[2].setLoop(false); + */ //printf(ofSystem("ls -la").c_str()); - + //testpenguin.load("Penguin-Blue.xml"); //debug: commented out: 436m 257m //508fr 1.7s load in use: 837m 444m - + //release: commented out: 436m 256m //508fr 1.4s load in use: 836m 443m - - + + showFPS=false; - + } void testApp::exit(){ @@ -53,7 +59,7 @@ void testApp::update(){ } else if (ret>0) { testsong->playerControl(ret); - penguins[ret-1].play(); + penguins[ret-1].playNow("Clap"); } for (int i=0;i<3;i++) { penguins[i].update(); @@ -66,20 +72,22 @@ void testApp::draw(){ //ofBackground(0,0,0,0.1); ofSetColor(0,0,0,100); ofRect(0,0,ofGetWidth(),ofGetHeight()); - + if (testsong->isPlaying) { ofSetColor(255,255,255); testsong->drawNotes(); + int missed=testsong->missedNote(); + if (missed>-1) penguins[missed].playNow("Shudder"); } ofSetColor(255,255,255); - for (int i=0;i<3;i++) penguins[i].draw((i*300)+100,800); + for (int i=0;i<3;i++) penguins[i].draw((i*300)+100,600); if (testsong->isPlaying) { ofSetColor(255,255,255); testsong->draw(); } else ofDrawBitmapString("game over!", (ofGetWidth()/2)-25,(ofGetHeight()/2)-5); - - if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate()), 10,ofGetHeight()-20); + + if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate()), ofGetWidth()-50,ofGetHeight()-15); } @@ -95,12 +103,12 @@ void testApp::keyPressed(int key){ case '2': case '3': testsong->playerControl(key-'1'); - penguins[key-'1'].play(); + penguins[key-'1'].playNow("Clap"); break; - case 's': + case 's': game.startGame(); break; - case 'f': + case 'f': showFPS=!showFPS; break; } diff --git a/vfg/src/testApp.h b/vfg/src/testApp.h index 16e4d05..f62c098 100755 --- a/vfg/src/testApp.h +++ b/vfg/src/testApp.h @@ -6,6 +6,7 @@ #include "music.h" #include "Asterisk.h" #include "Puppet.h" +#include "Animal.h" /* this library? @@ -74,13 +75,12 @@ class testApp : public ofBaseApp{ song *testsong; - vector<ofxSprite> penguins; - + vector<Animal> penguins; + Puppet testpenguin; - Asterisk game; - + bool showFPS; }; |
