summaryrefslogtreecommitdiff
path: root/vfg/src
diff options
context:
space:
mode:
authorTim Redfern <tim@gray.(none)>2012-11-19 21:05:27 +0000
committerTim Redfern <tim@gray.(none)>2012-11-19 21:05:27 +0000
commit891b71c261a4571e0e0ba0e824e1bdb2478e0c65 (patch)
tree2005ff07fb391fcead17d3a0679cc3f82d0ff4cd /vfg/src
parent1b56a18fc25f86591b410d32ceb19faea6fc74ea (diff)
flake animations
Diffstat (limited to 'vfg/src')
-rwxr-xr-xvfg/src/Puppet.cpp66
-rwxr-xr-xvfg/src/Puppet.h29
-rwxr-xr-xvfg/src/music.cpp34
-rwxr-xr-xvfg/src/music.h26
-rwxr-xr-xvfg/src/testApp.cpp19
-rwxr-xr-xvfg/src/testApp.h7
6 files changed, 163 insertions, 18 deletions
diff --git a/vfg/src/Puppet.cpp b/vfg/src/Puppet.cpp
new file mode 100755
index 0000000..46eee5e
--- /dev/null
+++ b/vfg/src/Puppet.cpp
@@ -0,0 +1,66 @@
+#include "Puppet.h"
+
+Puppet::Puppet()
+{
+
+}
+
+Puppet::~Puppet()
+{
+ //dtor
+}
+
+void Puppet::load(string filename) {
+ ofxXmlSettings XML;
+ int frames=0;
+ long t=ofGetElapsedTimeMillis();
+ if( !XML.loadFile(filename) ){
+ printf("unable to load %s check data/ folder\n",filename.c_str());
+ }else{
+ if(XML.pushTag("VFxmas")) {
+ for (int i=0;i<XML.getNumTags("Clip");i++) {
+ string name=XML.getAttribute("Clip", "name","",i);
+ if (name!="") {
+ clips[name]=ofxSprite();
+ clips[name].load(XML.getAttribute("Clip", "files","",i),XML.getAttribute("Clip", "frames",0,i));
+ clips[name].setAnchorPercent(XML.getAttribute("Clip", "xAnchorPct",0.5,i),XML.getAttribute("Clip", "yAnchorPct",0.5,i));
+ clips[name].setFrameRate(XML.getAttribute("Clip", "rate",25,i));
+ clips[name].setLoop(false);
+ frames+=clips[name].getTotalFrames();
+ }
+ }
+ printf("loaded %s: %i animation clips with %i frames in %2fs\n",filename.c_str(),clips.size(),frames,((float)(ofGetElapsedTimeMillis()-t))*.001f);
+ }
+ }
+}
+
+void Puppet::draw(float x, float y) {
+ if (playlist.size()>0) {
+ if (!clips[playlist[0]].getIsPlaying()) {
+ playlist.erase(playlist.begin());
+ if (playlist.size()>0) {
+ clips[playlist[0]].play();
+ }
+ }
+ }
+ if (playlist.size()==0) {
+ if (clips.find("base") != clips.end()) clips["base"].draw(x,y);
+ }
+ else {
+ clips[playlist[0]].update();
+ clips[playlist[0]].draw(x,y);
+ }
+}
+
+void Puppet::play(string clip){
+ if (clips.find(clip) != clips.end()) {
+ playlist.push_back(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");
+ }
+}
+
+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
new file mode 100755
index 0000000..91f32fd
--- /dev/null
+++ b/vfg/src/Puppet.h
@@ -0,0 +1,29 @@
+#ifndef PUPPET_H
+#define PUPPET_H
+
+#include "ofMain.h"
+#include "ofxSprite.h"
+#include "ofxXmlSettings.h"
+
+/*
+"base" clip will be drawn unless another clip is playing
+
+TODO: make resolution independent
+*/
+
+class Puppet
+{
+ public:
+ Puppet();
+ virtual ~Puppet();
+ void load(string filename);
+ void play(string clip);
+ void draw(float x, float y);
+ bool isPlaying();
+ protected:
+ private:
+ map<string,ofxSprite> clips;
+ deque<string> playlist;
+};
+
+#endif // PUPPET_H
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<int,note*>::iterator iter;
+ map<int,flake*>::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<int,note*>::iterator iter;
+ map<int,flake*>::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();
}
}
//---------------------------------------------------------------------------------------------------------------------------------------------
diff --git a/vfg/src/music.h b/vfg/src/music.h
index aaec003..96c8e1d 100755
--- a/vfg/src/music.h
+++ b/vfg/src/music.h
@@ -2,6 +2,7 @@
#include "ofMain.h"
#include "ofxXmlSettings.h"
+#include "Puppet.h"
//event times are absolute integer milliseconds
//---------------------------------------------------------------------------------------------------------------------------------------------
@@ -57,13 +58,26 @@ class note {
num=n;
velocity=v;
duration=d;
- activated=false;
}
int num;
int velocity;
int duration; //may be needed another time?
+};
+//---------------------------------------------------------------------------------------------------------------------------------------------
+class flake: public note {
+ public:
+ flake(int n,int v,int d=0) : note(n,v,d) { activated=false; }
+ Puppet puppet;
bool activated;
- void activate() { activated=true; }
+ 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 {
@@ -136,10 +150,12 @@ class musicscore: public score {
private:
map<int,note*> notes;
- map<int,note*> flakes;
- int timeframe;
- ofImage flake;
+ map<int,flake*> flakes;
+ int timeframe;
float nowpoint;
+
+ vector<Puppet> snowflakes;
+
};
//---------------------------------------------------------------------------------------------------------------------------------------------
class song {
diff --git a/vfg/src/testApp.cpp b/vfg/src/testApp.cpp
index 427ece9..ddc5cfe 100755
--- a/vfg/src/testApp.cpp
+++ b/vfg/src/testApp.cpp
@@ -28,6 +28,17 @@ void testApp::setup(){
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(){
@@ -67,6 +78,8 @@ void testApp::draw(){
testsong->draw();
}
else ofDrawBitmapString("game over!", (ofGetWidth()/2)-25,(ofGetHeight()/2)-5);
+
+ if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate()), 10,ofGetHeight()-20);
}
@@ -81,12 +94,15 @@ void testApp::keyPressed(int key){
case '1':
case '2':
case '3':
- testsong->playerControl(key-'0');
+ testsong->playerControl(key-'1');
penguins[key-'1'].play();
break;
case 's':
game.startGame();
break;
+ case 'f':
+ showFPS=!showFPS;
+ break;
}
}
@@ -97,7 +113,6 @@ void testApp::keyReleased(int key){
case '1':
case '2':
case '3':
- testsong->playerControl(0);
break;
}
}
diff --git a/vfg/src/testApp.h b/vfg/src/testApp.h
index 8f52ef7..16e4d05 100755
--- a/vfg/src/testApp.h
+++ b/vfg/src/testApp.h
@@ -2,8 +2,10 @@
#include "ofMain.h"
#include "ofxSprite.h"
+
#include "music.h"
#include "Asterisk.h"
+#include "Puppet.h"
/*
this library?
@@ -74,7 +76,12 @@ class testApp : public ofBaseApp{
vector<ofxSprite> penguins;
+ Puppet testpenguin;
+
+
Asterisk game;
+
+ bool showFPS;
};