summaryrefslogtreecommitdiff
path: root/vfg/src
diff options
context:
space:
mode:
Diffstat (limited to 'vfg/src')
-rwxr-xr-xvfg/src/Asterisk.cpp2
-rwxr-xr-xvfg/src/music.cpp21
-rwxr-xr-xvfg/src/music.h23
-rwxr-xr-xvfg/src/testApp.cpp46
-rwxr-xr-xvfg/src/testApp.h9
5 files changed, 70 insertions, 31 deletions
diff --git a/vfg/src/Asterisk.cpp b/vfg/src/Asterisk.cpp
index 8a2309e..5392ade 100755
--- a/vfg/src/Asterisk.cpp
+++ b/vfg/src/Asterisk.cpp
@@ -47,7 +47,7 @@ int Asterisk::update(){
udpConnection.Receive(udpMessage,10000);
string msg=udpMessage;
if(msg!=""){
- if (msg.length()>2) {
+ if (msg.length()>3) {
//printf("status msg: %s\n",msg.c_str());
if (msg.substr(0,5)=="Local") {
state=PLAYING;
diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp
index 359b21d..b5b584c 100755
--- a/vfg/src/music.cpp
+++ b/vfg/src/music.cpp
@@ -28,7 +28,7 @@ void lyricscore::draw(){
}
//----------------------------------------------------------------------------------------------------------
musicscore::musicscore() {
- timeframe=2000;
+ timeframe=5000;
missedLast=false;
nowpoint=1.0f;
missedNote=-1;
@@ -124,7 +124,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);
}
-void musicscore::makeFlakes(int threshStart,int threshEnd){
+void musicscore::makeFlakes(int threshStart,int threshEnd,levelscore *levels){
flakes.clear();
//decimate notes to generate flakes that can be interacted with
map<int,note*>::iterator iter;
@@ -137,12 +137,12 @@ void musicscore::makeFlakes(int threshStart,int threshEnd){
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)))) {
+ if ((levels->nextLevelTime(iter->first)>2000)&&((notemap(iter->second->num)!=notemap(lastNote->num))||(iter->first-lastTime>((songPos*threshEnd)+((1.0f-songPos)*threshStart))))) {
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;
}
- lastNote=iter->second;
- lastTime=iter->first;
}
missedFlake=flakes.end();
missedNote=-1;
@@ -210,7 +210,7 @@ void musicscore::drawFlakes(levelscore *levels) {
}
missedLast=!iter->second->activated;
}
- //at this point missed points to the latest unactivated flake in the level
+ //at this point missed points to the latest unactivated flake in the level if there is one
if ((missed!=flakes.end())&&(missedFlake!=missed)) {
missedFlake=missed;
missedNote=notemap(missed->second->num);
@@ -237,7 +237,7 @@ song::song(string backfile,string melfile,string musfile,string lyricfile,string
lyrics.load(lyricfile);
levels.load(levelfile);
isPlaying=false;
- keyThresh=400;
+ keyThresh=500;
notes.setNowpoint(0.8f);
}
void song::setTimeframe(int millis) {notes.setTimeframe(millis);}
@@ -253,7 +253,7 @@ void song::play() {
notes.start();
lyrics.start();
isPlaying=true;
- notes.makeFlakes(fThreshStart,fThreshEnd);
+ notes.makeFlakes(fThreshStart,fThreshEnd,&levels);
}
void song::stop() {
backing.stop();
@@ -266,7 +266,7 @@ void song::preRoll(long preroll) {
lyrics.start(startTime);
isPreroll=true;
isPlaying=true;
- notes.makeFlakes(fThreshStart,fThreshEnd);
+ notes.makeFlakes(fThreshStart,fThreshEnd,&levels);
}
void song::drawNotes(){
notes.drawNotes(&levels);
@@ -307,4 +307,7 @@ int song::hitNote(){
int n=notes.hitNote;
notes.hitNote=-1;
return n;
+}
+int song::getLevel(long time){
+ return levels.getLevel(time-startTime);
}
diff --git a/vfg/src/music.h b/vfg/src/music.h
index 7e54292..1cb92ff 100755
--- a/vfg/src/music.h
+++ b/vfg/src/music.h
@@ -17,14 +17,22 @@ class levelscore {
if( !XML.loadFile(filename) ){
printf("unable to load %s check data/ folder\n",filename.c_str());
}else{
+ int multiplier=1000/XML.getAttribute("VFxmas", "timebase",1000,0);
if(XML.pushTag("VFxmas")) {
for (int i=0;i<XML.getNumTags("Level");i++) {
- levels[XML.getAttribute("Level", "Time",0,i)]=XML.getAttribute("Level", "Lives",0,i);
+ levels[XML.getAttribute("Level", "Time",0,i)*multiplier]=XML.getAttribute("Level", "Lives",0,i);
}
printf("processed %s: %i difficulty levels \n",filename.c_str(),levels.size());
}
}
}
+ void test() {
+ map<int,int>::iterator iter=levels.end();
+ iter--;
+ for (int i=0;i<iter->first;i+=500) {
+ printf("time %i: level %i, nextleveltime %i\n",i,getLevel(i), nextLevelTime(i));
+ }
+ }
int getLives(int time) {
map<int,int>::iterator iter;
int lives=0;
@@ -52,6 +60,14 @@ class levelscore {
}
return bound;
}
+ int nextLevelTime(int time) {
+ map<int,int>::iterator iter;
+ int level=-1;
+ for (iter = levels.begin(); iter != levels.end(); ++iter) {
+ if (iter->first>time) return iter->first-time;
+ }
+ return 2<<20; // a big number
+ }
private:
map<int,int> levels;
};
@@ -115,7 +131,7 @@ class lyricscore: public score {
if( !XML.loadFile(filename) ){
printf("unable to load %s check data/ folder\n",filename.c_str());
}else{
- int multiplier=1000/XML.getAttribute("VFxmas", "timebase",0,0);
+ int multiplier=1000/XML.getAttribute("VFxmas", "timebase",1000,0);
if(XML.pushTag("VFxmas")) {
for (int i=0;i<XML.getNumTags("Lyric");i++) {
int in=XML.getAttribute("Lyric", "In",0,i)*multiplier;
@@ -144,7 +160,7 @@ class musicscore: public score {
void drawNotes(levelscore *levels);
void drawFlakes(levelscore *levels);
void playerControl(int key,int threshold);
- void makeFlakes(int threshStart,int threshEnd);
+ void makeFlakes(int threshStart,int threshEnd,levelscore *levels);
int missedFlakes;
int missedNote;
@@ -178,6 +194,7 @@ class song {
int hitNote();
bool isPlaying;
void playerControl(int key);
+ int getLevel(long time);
private:
ofSoundPlayer backing;
ofSoundPlayer melody;
diff --git a/vfg/src/testApp.cpp b/vfg/src/testApp.cpp
index ab044a9..4385593 100755
--- a/vfg/src/testApp.cpp
+++ b/vfg/src/testApp.cpp
@@ -1,30 +1,32 @@
#include "testApp.h"
-
+//bug in codeblocks: it sometimes checks for existence of executable from previous project
//--------------------------------------------------------------
void testApp::setup(){
- testsong=new song("VODA_MUS_DeckTheHalls-Backing_v.1.5.mp3","VODA_MUS_DeckTheHalls-Melody_v.1.5.mp3","MIDI_DeckTheHalls_MIDI.1.5.xml","Lyrics_DeckTheHalls.1.5.xml","Levels_DeckTheHalls.1.5.xml");
- testsong->setTimeframe(2500);
+ //testsong=new song("VODA_MUS_DeckTheHalls-Backing_v.1.5.mp3","VODA_MUS_DeckTheHalls-Melody_v.1.5.mp3","MIDI_DeckTheHalls_MIDI.1.5.xml","Lyrics_DeckTheHalls.1.5.xml","Levels_DeckTheHalls.1.5.xml");
+ testsong=new song("JingleBells_v.4.0/VODA_MUS_JingleBells_Backing_v.4.0.mp3","JingleBells_v.4.0/VODA_MUS_JingleBells_Melody_v.4.0.mp3","VODA_MUS_JingleBells_MIDI_v.4.0.xml","Lyrics_JingleBells.4.0.xml","Levels_JingleBells.4.0.xml");
+
+ testsong->setTimeframe(3000);
testsong->setFlakeThresh(1000,100);
ofSetBackgroundAuto(false);
ofBackground(0,0,0);
- /*
+
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");
- for (int i=0;i<3;i++) raccoons.push_back(Animal());
+ for (int i=0;i<3;i++) raccoons.push_back(Animal());
raccoons[0].load("Raccoon-Blue.xml");
raccoons[1].load("Raccoon-Purple.xml");
raccoons[2].load("Raccoon-Green.xml");
- */
- loadanimals("Raccoons");
- playanimal =&playanimals;
+
+ //loadanimals("Raccoons");
+ playanimal =&penguins;
//testpenguin.load("Penguin-Blue.xml");
//debug: commented out: 436m 257m
@@ -41,8 +43,9 @@ void testApp::setup(){
showFPS=false;
-}
+}
+/*
void testApp::loadanimals(string which) {
playanimals.clear();
@@ -60,6 +63,7 @@ void testApp::loadanimals(string which) {
}
}
+*/
void testApp::exit(){
delete testsong;
@@ -69,11 +73,22 @@ void testApp::exit(){
void testApp::update(){
int ret=game.update();
if (ret==1000) {
+ currentlevel=0;
testsong->preRoll(250);
}
- else if (ret>0) {
- testsong->playerControl(ret);
- (*playanimal)[ret-1].playNow("Clap");
+ else if (ret>48&&ret<52) {
+ testsong->playerControl(ret-48);
+ (*playanimal)[ret-49].playNow("Clap");
+ }
+ if (testsong->isPlaying&&testsong->getLevel(ofGetElapsedTimeMillis()+2000)>currentlevel) {
+ int anim=ofRandom(1.9999); //this gives a binary random number
+ for (int i=0;i<3;i++) {
+ if (anim) (*playanimal)[i].playNow("Happy");
+ else (*playanimal)[i].playNow("Jump");
+ anim=(anim+1)%2;
+ }
+ //printf("finished level %i!\n",currentlevel);
+ currentlevel++;
}
for (int i=0;i<3;i++) {
(*playanimal)[i].update();
@@ -121,6 +136,7 @@ void testApp::keyPressed(int key){
switch (key) {
case ' ':
if (!testsong->isPlaying) {
+ currentlevel=0;
testsong->preRoll(250);
}
break;
@@ -137,10 +153,12 @@ void testApp::keyPressed(int key){
showFPS=!showFPS;
break;
case 'r':
- loadanimals("Raccoons");
+ //loadanimals("Raccoons");
+ playanimal =&raccoons;
break;
case 'p':
- loadanimals("Penguins");
+ //loadanimals("Penguins");
+ playanimal =&penguins;
break;
}
diff --git a/vfg/src/testApp.h b/vfg/src/testApp.h
index 4ab807f..2518b55 100755
--- a/vfg/src/testApp.h
+++ b/vfg/src/testApp.h
@@ -73,23 +73,24 @@ class testApp : public ofBaseApp{
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
- void loadanimals(string which);
+ //void loadanimals(string which);
ofVideoPlayer background;
ofImage vignette;
song *testsong;
- /*
+
vector<Animal> penguins;
vector<Animal> raccoons;
- */
- vector<Animal> playanimals;
+
+ //vector<Animal> playanimals;
vector<Animal>* playanimal;
Puppet testpenguin;
+ int currentlevel;
Asterisk game;