diff options
| -rwxr-xr-x | ofAsterisk/src/Asterisk.cpp | 33 | ||||
| -rwxr-xr-x | ofAsterisk/src/Asterisk.h | 10 | ||||
| -rwxr-xr-x | ofAsterisk/src/testApp.cpp | 10 | ||||
| -rwxr-xr-x | ofAsterisk/src/testApp.h | 2 | ||||
| -rwxr-xr-x | vfg/bin/data/Penguin-Blue.xml | 6 | ||||
| -rwxr-xr-x | vfg/bin/data/Penguin-Green.xml | 6 | ||||
| -rwxr-xr-x | vfg/bin/data/Penguin-Purple.xml | 6 | ||||
| -rwxr-xr-x | vfg/bin/data/Raccoon-Blue.xml | 6 | ||||
| -rwxr-xr-x | vfg/bin/data/Raccoon-Green.xml | 6 | ||||
| -rwxr-xr-x | vfg/bin/data/Raccoon-Purple.xml | 6 | ||||
| -rwxr-xr-x | vfg/src/Asterisk.cpp | 92 | ||||
| -rwxr-xr-x | vfg/src/Asterisk.h | 40 | ||||
| -rwxr-xr-x | vfg/src/music.cpp | 52 | ||||
| -rwxr-xr-x | vfg/src/music.h | 13 | ||||
| -rwxr-xr-x | vfg/src/testApp.cpp | 387 | ||||
| -rwxr-xr-x | vfg/src/testApp.h | 24 | ||||
| -rw-r--r-- | vfg/vfg.layout | 24 |
17 files changed, 506 insertions, 217 deletions
diff --git a/ofAsterisk/src/Asterisk.cpp b/ofAsterisk/src/Asterisk.cpp index f5e7705..7c4f050 100755 --- a/ofAsterisk/src/Asterisk.cpp +++ b/ofAsterisk/src/Asterisk.cpp @@ -13,30 +13,14 @@ std::vector<std::string> &split(const std::string &s, char delim, std::vector<st return elems;
}
-std::vector<std::string> split(const std::string &s, char delim) {
- std::vector<std::string> elems;
- return split(s, delim, elems);
-}
-Asterisk::Asterisk()
+Asterisk::Asterisk(string passcode)
{
udpConnection.Create();
udpConnection.Bind(5000);
udpConnection.SetNonBlocking(true);
- //cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME passcode 1234\"'");
+ cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME passcode "+passcode+"\"'");
state=WAITING; //for acknowledge
- printf("Asterisk: created socket and connected to server\n");
-
- string test=string("gameQ has 1 calls (max unlimited) in 'rrmemory' strategy (8s holdtime, 50s talktime), W:0, C:38, A:26, SL:36.8% within 0s\
- Members: \
- Game AGI (Local/9999@default) with penalty 1 (In use) has taken 31 calls (last was 5333 secs ago)\
- Callers: \
- 1. SIP/sip_proxy-00000045 (wait: 0:06, prio: 0)");
- vector<std::string> lines=split(test,'\n');
- for (int i=0;i<test.size();i++) {
- string s=ofToString(i)+": '"+lines[i]+"'\n";
- printf(s.c_str());
- }
}
void Asterisk::startGame(){
@@ -70,6 +54,11 @@ gameQ has 1 calls (max unlimited) in 'rrmemory' strategy (8s holdtime, 50s talkt 1. SIP/sip_proxy-00000045 (wait: 0:06, prio: 0)
*/
+void Asterisk::requestStatus(){
+ cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"queue show gameQ\"'");
+ state=WAITING;
+}
+
int Asterisk::update(){
//capture stdin response from popen
@@ -82,14 +71,18 @@ int Asterisk::update(){ if (r > 0) {
pclose(file);
string msg=string(buf);
- vector<std::string> lines=split(msg,'\n');
//received data is always a command ACKNOWLEDGEMENT
if (msg.compare("Changing GAME to NOT_INUSE")==0) {
printf("player dequeued\n");
state=PLAYING;
}
else if (msg.compare(0,5,"gameQ")==0) {
- //queue status message
+ vector<std::string> lines;
+ split(msg,'\n',lines);
+ queued=0;
+ for (int i=4;i<lines.size();i++) {
+ if (lines[i].compare(0,6," ")==0&&lines[i].compare(7,1,".")==0) queued++;
+ }
}
else {
printf("stdin says: %s\n",buf);
diff --git a/ofAsterisk/src/Asterisk.h b/ofAsterisk/src/Asterisk.h index 3acdb6e..d3e3786 100755 --- a/ofAsterisk/src/Asterisk.h +++ b/ofAsterisk/src/Asterisk.h @@ -13,22 +13,24 @@ class Asterisk
{
public:
- Asterisk();
+ Asterisk(string passcode="1111");
virtual ~Asterisk();
void startGame();
void endGame(string score);
int update();
- void cmd(string s);
-
+ void requestStatus();
int state;
-
+
+ int queued;
protected:
+ void cmd(string s);
private:
int startTime;
FILE *file;
int filenum;
ofxUDPManager udpConnection;
string playerCode;
+
};
#endif // ASTERISK_H
diff --git a/ofAsterisk/src/testApp.cpp b/ofAsterisk/src/testApp.cpp index a69a084..1a172ee 100755 --- a/ofAsterisk/src/testApp.cpp +++ b/ofAsterisk/src/testApp.cpp @@ -2,17 +2,23 @@ //-------------------------------------------------------------- void testApp::setup(){ - + queuecheck=0; } //-------------------------------------------------------------- void testApp::update(){ int ret=game.update(); + if (ofGetElapsedTimeMillis()-queuecheck>5000) { + game.requestStatus(); + queuecheck=ofGetElapsedTimeMillis(); + } } //-------------------------------------------------------------- void testApp::draw(){ - + ofClear(0,0,0); + ofSetColor(255,255,255); + ofDrawBitmapString(ofToString(game.queued), ofGetWidth()/2,ofGetHeight()/2); } //-------------------------------------------------------------- diff --git a/ofAsterisk/src/testApp.h b/ofAsterisk/src/testApp.h index 84c984c..61570bc 100755 --- a/ofAsterisk/src/testApp.h +++ b/ofAsterisk/src/testApp.h @@ -21,5 +21,7 @@ class testApp : public ofBaseApp{ void gotMessage(ofMessage msg); Asterisk game; + + int queuecheck; }; diff --git a/vfg/bin/data/Penguin-Blue.xml b/vfg/bin/data/Penguin-Blue.xml index f14ca16..494140e 100755 --- a/vfg/bin/data/Penguin-Blue.xml +++ b/vfg/bin/data/Penguin-Blue.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ISO-8859-1"?>
<VFxmas> <Clip name="base" files="Penguin/Penguin-Blue.png" frames="1"/>
- <Clip name="Clap" files="Penguin/Penguin-Clap-Blue/Penguin-Clap-Blue_%05i.png" rate="50" frames="20"/>
- <Clip name="Catch" files="Penguin/Penguin-Catch-Blue/Penguin-Catch-Blue_%05i.png" rate="50" frames="34"/>
+ <Clip name="Clap" files="Penguin2/Clap-Blue2/Penguin-Clap-Blue2_%05i.png" rate="50" frames="30"/>
+ <Clip name="Catch" files="Penguin2/Catch-Blue2/Catch-Blue2_%05i.png" rate="50" frames="34"/>
<Clip name="Happy" files="Penguin/Penguin-Happy-Blue/Penguin-Happy-Blue_%05i.png" rate="50" frames="100"/>
<Clip name="Jump" files="Penguin/Penguin-Jump-Blue/Penguin-Jump-Blue_%05i.png" rate="50" frames="49"/>
- <Clip name="Shudder" files="Penguin/Penguin-Shudder-Blue/Penguin-Shudder-Blue_%05i.png" rate="50" frames="30"/>
+ <Clip name="Shudder" files="Penguin2/Shudder-Blue2/Shudder-Blue2_%05i.png" rate="50" frames="30"/>
<Clip name="Shuffle" files="Penguin/Penguin-ShuffleShort-Blue/Penguin-ShuffleShort-Blue_%05i.png" rate="50" frames="101"/>
<Clip name="Walk_start" files="Penguin/Penguin-WalkingStart-Blue/Penguin-WalkingStart-Blue_%05i.png" rate="50" frames="11"/>
<Clip name="Walking" files="Penguin/Penguin-WalkingLoop-Blue/Penguin-WalkLoop-Blue_%05i.png" rate="50" frames="35"/>
diff --git a/vfg/bin/data/Penguin-Green.xml b/vfg/bin/data/Penguin-Green.xml index 7d8fe2c..f7c4f20 100755 --- a/vfg/bin/data/Penguin-Green.xml +++ b/vfg/bin/data/Penguin-Green.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ISO-8859-1"?>
<VFxmas> <Clip name="base" files="Penguin/Penguin-Green.png" frames="1"/>
- <Clip name="Clap" files="Penguin/Penguin-Clap-Green/Penguin-Clap-Green_%05i.png" rate="50" frames="20"/>
- <Clip name="Catch" files="Penguin/Penguin-Catch-Green/Penguin-Catch-Green_%05i.png" rate="50" frames="34"/>
+ <Clip name="Clap" files="Penguin2/Clap-Green2/Penguin-Clap-Green2_%05i.png" rate="50" frames="30"/>
+ <Clip name="Catch" files="Penguin2/Catch-Green2/Catch-Green2_%05i.png" rate="50" frames="34"/>
<Clip name="Happy" files="Penguin/Penguin-Happy-Green/Penguin-Happy-Green_%05i.png" rate="50" frames="100"/>
<Clip name="Jump" files="Penguin/Penguin-Jump-Green/Penguin-Jump-Green_%05i.png" rate="50" frames="49"/>
- <Clip name="Shudder" files="Penguin/Penguin-Shudder-Green/Penguin-Shudder-Green_%05i.png" rate="50" frames="30"/>
+ <Clip name="Shudder" files="Penguin2/Shudder-Green2/Shudder-Green2_%05i.png" rate="50" frames="30"/>
<Clip name="Shuffle" files="Penguin/Penguin-ShuffleShort-Green/Penguin-ShuffleShort-Green_%05i.png" rate="50" frames="101"/>
<Clip name="Walk_start" files="Penguin/Penguin-WalkingStart-Green/Penguin-WalkingStart-Green_%05i.png" rate="50" frames="11"/>
<Clip name="Walking" files="Penguin/Penguin-WalkingLoop-Green/Penguin-WalkLoop-Green_%05i.png" rate="50" frames="35"/>
diff --git a/vfg/bin/data/Penguin-Purple.xml b/vfg/bin/data/Penguin-Purple.xml index 6f86554..2d5aa4c 100755 --- a/vfg/bin/data/Penguin-Purple.xml +++ b/vfg/bin/data/Penguin-Purple.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ISO-8859-1"?>
<VFxmas> <Clip name="base" files="Penguin/Penguin-Purple.png" frames="1"/>
- <Clip name="Clap" files="Penguin/Penguin-Clap-Purple/Penguin-Clap-Purple_%05i.png" rate="50" frames="20"/>
- <Clip name="Catch" files="Penguin/Penguin-Catch-Purple/Penguin-Catch-Purple_%05i.png" rate="50" frames="34"/>
+ <Clip name="Clap" files="Penguin2/Clap-Purple2/Penguin-Clap-Purple2_%05i.png" rate="50" frames="30"/>
+ <Clip name="Catch" files="Penguin2/Catch-Purple2/Catch-Purple2_%05i.png" rate="50" frames="34"/>
<Clip name="Happy" files="Penguin/Penguin-Happy-Purple/Penguin-Happy-Purple_%05i.png" rate="50" frames="100"/>
<Clip name="Jump" files="Penguin/Penguin-Jump-Purple/Penguin-Jump-Purple_%05i.png" rate="50" frames="49"/>
- <Clip name="Shudder" files="Penguin/Penguin-Shudder-Purple/Penguin-Shudder-Purple_%05i.png" rate="50" frames="30"/>
+ <Clip name="Shudder" files="Penguin2/Shudder-Purple2/Shudder-Purple2_%05i.png" rate="50" frames="30"/>
<Clip name="Shuffle" files="Penguin/Penguin-ShuffleShort-Purple/Penguin-ShuffleShort-Purple_%05i.png" rate="50" frames="101"/>
<Clip name="Walk_start" files="Penguin/Penguin-WalkingStart-Purple/Penguin-WalkingStart-Purple_%05i.png" rate="50" frames="11"/>
<Clip name="Walking" files="Penguin/Penguin-WalkingLoop-Purple/Penguin-WalkLoop-Purple_%05i.png" rate="50" frames="35"/>
diff --git a/vfg/bin/data/Raccoon-Blue.xml b/vfg/bin/data/Raccoon-Blue.xml index 1c53b4a..98366d8 100755 --- a/vfg/bin/data/Raccoon-Blue.xml +++ b/vfg/bin/data/Raccoon-Blue.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ISO-8859-1"?>
<VFxmas> <Clip name="base" files="Raccoon/Raccoon-Blue.png" frames="1"/>
- <Clip name="Clap" files="Raccoon/Raccoon-Clap-Blue/Raccoon-Clap-Blue_%05i.png" rate="50" frames="20"/>
- <Clip name="Catch" files="Raccoon/Raccoon-Catch-Blue/Raccoon-Catch-Blue_%05i.png" rate="50" frames="34"/>
+ <Clip name="Clap" files="Raccoon2/Clap-Blue2/Raccoon-Clap2_%05i.png" rate="50" frames="20"/>
+ <Clip name="Catch" files="Raccoon2/Catch-Blue2/Raccoon-Catch-Blue2_%05i.png" rate="50" frames="34"/>
<Clip name="Happy" files="Raccoon/Raccoon-Happy-Blue/Raccoon-Happy-Blue_%05i.png" rate="50" frames="100"/>
<Clip name="Jump" files="Raccoon/Raccoon-Jump-Blue/Raccoon-Jump-Blue_%05i.png" rate="50" frames="49"/>
- <Clip name="Shudder" files="Raccoon/Raccoon-Shudder-Blue/Raccoon-Shudder_Blue_%05i.png" rate="50" frames="30"/>
+ <Clip name="Shudder" files="Raccoon2/Shudder-Blue2/Raccoon-Shudder-Blue2_%05i.png" rate="50" frames="30"/>
<Clip name="Shuffle" files="Raccoon/Raccoon-Shuffle-Blue/Raccoon-Shuffle-Blue_%05i.png" rate="50" frames="101"/>
<Clip name="Walk_start" files="Raccoon/Raccoon-StandDown-Blue/Raccoon-StandDown-Blue_%05i.png" rate="50" frames="20"/>
<Clip name="Walking" files="Raccoon/Raccoon-WalkLoop-Blue/Raccoon-WalkLoop-Blue_%05i.png" rate="50" start="20" frames="39"/>
diff --git a/vfg/bin/data/Raccoon-Green.xml b/vfg/bin/data/Raccoon-Green.xml index cbc8775..7c4961b 100755 --- a/vfg/bin/data/Raccoon-Green.xml +++ b/vfg/bin/data/Raccoon-Green.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ISO-8859-1"?>
<VFxmas> <Clip name="base" files="Raccoon/Raccoon-Green.png" frames="1"/>
- <Clip name="Clap" files="Raccoon/Raccoon-Clap-Green/Raccoon-Clap-Green_%05i.png" rate="50" frames="20"/>
- <Clip name="Catch" files="Raccoon/Raccoon-Catch-Green/Raccoon-Catch-Green_%05i.png" rate="50" frames="34"/>
+ <Clip name="Clap" files="Raccoon2/Clap-Green2/Raccoon-Clap-Purple2_%05i.png" rate="50" frames="20"/>
+ <Clip name="Catch" files="Raccoon2/Catch-Green2/Raccoon-Catch-Green2_%05i.png" rate="50" frames="34"/>
<Clip name="Happy" files="Raccoon/Raccoon-Happy-Green/Raccoon-Happy-Green_%05i.png" rate="50" frames="100"/>
<Clip name="Jump" files="Raccoon/Raccoon-Jump-Green/Raccoon-Jump-Green_%05i.png" rate="50" frames="49"/>
- <Clip name="Shudder" files="Raccoon/Raccoon-Shudder-Green/Raccoon-Shudder-Green_%05i.png" rate="50" frames="30"/>
+ <Clip name="Shudder" files="Raccoon2/Shudder-Green2/Raccoon-Shudder-Green2_%05i.png" rate="50" frames="30"/>
<Clip name="Shuffle" files="Raccoon/Raccoon-Shuffle-Green/Raccoon-Shuffle-Green_%05i.png" rate="50" frames="101"/>
<Clip name="Walk_start" files="Raccoon/Raccoon-StandDown-Green/Raccoon-StandDown-Green_%05i.png" rate="50" frames="20"/>
<Clip name="Walking" files="Raccoon/Raccoon-WalkLoop-Green/Raccoon-WalkLoop-Green_%05i.png" rate="50" start="20" frames="39"/>
diff --git a/vfg/bin/data/Raccoon-Purple.xml b/vfg/bin/data/Raccoon-Purple.xml index 6dde4cc..7887a16 100755 --- a/vfg/bin/data/Raccoon-Purple.xml +++ b/vfg/bin/data/Raccoon-Purple.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ISO-8859-1"?>
<VFxmas> <Clip name="base" files="Raccoon/Raccoon-Purple.png" frames="1"/>
- <Clip name="Clap" files="Raccoon/Raccoon-Clap-Purple/Raccoon-Clap-Purple_%05i.png" rate="50" frames="20"/>
- <Clip name="Catch" files="Raccoon/Raccoon-Catch-Purple/Raccoon-Catch-Purple_%05i.png" rate="50" frames="34"/>
+ <Clip name="Clap" files="Raccoon2/Clap-Purple2/Raccoon-Clap-Purple2_%05i.png" rate="50" frames="20"/>
+ <Clip name="Catch" files="Raccoon2/Catch-Purple2/Raccoon-Catch-Purple2_%05i.png" rate="50" frames="34"/>
<Clip name="Happy" files="Raccoon/Raccoon-Happy-Purple/Raccoon-Happy-Purple_%05i.png" rate="50" frames="100"/>
<Clip name="Jump" files="Raccoon/Raccoon-Jump-Purple/Raccoon-Jump-Purple_%05i.png" rate="50" frames="49"/>
- <Clip name="Shudder" files="Raccoon/Raccoon-Shudder-Purple/Raccoon-Shudder-Purple_%05i.png" rate="50" frames="30"/>
+ <Clip name="Shudder" files="Raccoon2/Shudder-Purple2/Raccoon-Shudder-Purple2_%05i.png" rate="50" frames="30"/>
<Clip name="Shuffle" files="Raccoon/Raccoon-Shuffle-Purple/Raccoon-Shuffle-Purple_%05i.png" rate="50" frames="101"/>
<Clip name="Walk_start" files="Raccoon/Raccoon-StandDown-Purple/Raccoon-StandDown-Purple_%05i.png" rate="50" frames="20"/>
<Clip name="Walking" files="Raccoon/Raccoon-WalkLoop-Purple/Raccoon-WalkLoop-Purple_%05i.png" rate="50" start="20" frames="39"/>
diff --git a/vfg/src/Asterisk.cpp b/vfg/src/Asterisk.cpp index 3f845f0..12b3d92 100755 --- a/vfg/src/Asterisk.cpp +++ b/vfg/src/Asterisk.cpp @@ -4,64 +4,104 @@ //there is no notification that there is someone in the queue
//but there is a status message you can check periodically...
+std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
+ std::stringstream ss(s);
+ std::string item;
+ while(std::getline(ss, item, delim)) {
+ elems.push_back(item);
+ }
+ return elems;
+}
+
+
Asterisk::Asterisk()
{
+}
+
+void Asterisk::setup(string passcode){
udpConnection.Create();
udpConnection.Bind(5000);
udpConnection.SetNonBlocking(true);
- cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME passcode 1122\"'");
- state=WAITING;
- printf("Asterisk: created socket and connected to server\n");
+ cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME passcode "+passcode+"\"'");
+ state=WAITING; //for acknowledge
+ isPlaying=false;
}
-
void Asterisk::startGame(){
- if (state!=PLAYING) {
+ if (!isPlaying&&queued) {
cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"devstate change Custom:GAME NOT_INUSE\"'");
printf("Asterisk: attempting to dequeue\n");
- state=STARTING;
+ state=WAITING;
}
}
void Asterisk::endGame(string score){
- if (state==PLAYING) {
+ printf("Asterisk: request hangup %s\n",playerCode.c_str());
+ if (isPlaying) {
cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME statuscode "+score+"\"'");
string emsg="ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"hangup request "+playerCode+"\"'";
- printf("%s\n",emsg.c_str());
cmd(emsg);
printf("Asterisk: hanging up %s\n",playerCode.c_str());
state=WAITING;
+ isPlaying=false;
}
}
void Asterisk::cmd(string s) {
- file = popen(s.c_str(), "r");
- int filenum=fileno(file);
- //fcntl(filenum, F_SETFL, O_NONBLOCK); //doesn't seem to work, still pauses
- //pclose(file); //discard the pipe THIS IS BLOCKING
+ file = popen(s.c_str(), "re");
+ filenum=fileno(file);
+ fcntl(filenum, F_SETFL, O_NONBLOCK);
}
+/*
+gameQ has 1 calls (max unlimited) in 'rrmemory' strategy (8s holdtime, 50s talktime), W:0, C:38, A:26, SL:36.8% within 0s
+ Members:
+ Game AGI (Local/9999@default) with penalty 1 (In use) has taken 31 calls (last was 5333 secs ago)
+ Callers:
+ 1. SIP/sip_proxy-00000045 (wait: 0:06, prio: 0)
+*/
+
+void Asterisk::requestStatus(){
+ cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"queue show gameQ\"'");
+ state=WAITING;
+}
+
+
int Asterisk::update(){
- //how to capture stdin response from popen
- /*
- if (state==WAITING||state==STARTING) {
- char buf[100];
- ssize_t r = read(filenum, buf, 100);
+ //capture stdin response from popen
+ if (state==WAITING||state==STARTING||state==IDLE) {
+ char buf[1000];
+ ssize_t r = read(filenum, buf, 1000);
//if (r == -1 && errno == EAGAIN)
//no data yet
- //else
- if (r > 0)
- //received data
- printf("%s\n",buf);
+ //else
+ if (r > 0) {
pclose(file);
+ string msg=string(buf);
state=IDLE;
- ///else
- //pipe closed
+ //received data is always a command ACKNOWLEDGEMENT
+ if (msg.compare(0,8,"Changing")==0) {
+ printf("player dequeued\n");
+ isPlaying=true;
+ }
+ else if (msg.compare(0,5,"gameQ")==0) {
+ vector<std::string> lines;
+ split(msg,'\n',lines);
+ queued=0;
+ for (int i=4;i<lines.size();i++) {
+ if (lines[i].compare(0,6," ")==0&&lines[i].compare(7,1,".")==0) queued++;
+ }
+ }
+ else {
+ printf("stdin says: %s\n",buf);
+
+ }
+ }
}
- */
- //check messages and pipes, returns new keypresses
+
+ //check udp messages, return new keypresses
char udpMessage[10000];
udpConnection.Receive(udpMessage,10000);
string msg=udpMessage;
if(msg!=""){
- printf("Asterisk: %s\n",msg.c_str());
+ //printf("Asterisk: %s\n",msg.c_str());
if (msg.length()>3) {
//printf("status msg: %s\n",msg.c_str());
if (msg.substr(0,5)=="Local") {
diff --git a/vfg/src/Asterisk.h b/vfg/src/Asterisk.h index c9ce864..0640c4b 100755 --- a/vfg/src/Asterisk.h +++ b/vfg/src/Asterisk.h @@ -9,56 +9,30 @@ #define STARTING 2
#define PLAYING 3
-// http://stackoverflow.com/questions/1735781/non-blocking-pipe-using-popen
-
-/*
-
-Commands for game to control PBX
-
-Game ready
-
-ssh 10.10.10.1 'sudo /usr/sbin/asterisk -rx "devstate change Custom:GAME NOT_INUSE"'
-
-change daily access 4 digit code
-
-ssh 10.10.10.1 'sudo /usr/sbin/asterisk -rx "database put GAME passcode 1234"'
-
-
-
-Set status code for current game
-
-ssh 10.10.10.1 'sudo /usr/sbin/asterisk -rx "database put GAME statuscode 1234"'
-
-Gameover Hangup Call
-
-ssh 10.10.10.1 'sudo /usr/sbin/asterisk -rx "hangup request Local/9999@default-00000039;2"
-
-Local/9999@default-00000039;2 is a channel identifier and will be send to game when AGI script connects to game controller. The channel ID is unique for each call
-
-
-can we have a message that someone has joined the queue?
-can we have a message if someone hangs up?
-*/
class Asterisk
{
public:
Asterisk();
+ void setup(string passcode="1111");
virtual ~Asterisk();
void startGame();
void endGame(string score);
int update();
- void cmd(string s);
-
+ void requestStatus();
int state;
-
+ bool isPlaying;
+
+ int queued;
protected:
+ void cmd(string s);
private:
int startTime;
FILE *file;
int filenum;
ofxUDPManager udpConnection;
string playerCode;
+
};
#endif // ASTERISK_H
diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index 30af87b..8f3b767 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -132,6 +132,15 @@ void musicscore::printNotes() { printf("%i: %i, %i for %i\n",iter->first,iter->second->num,iter->second->velocity,iter->second->duration);
}
}
+void musicscore::makeRandomNotes(int length,int startFreq,int endFreq){
+ notes.clear();
+ int time=startFreq;
+ while (time<length) {
+ notes[time]=new note(ofRandom(16)+70,128,100);
+ float frac=(float)time/(float)length;
+ time+=(frac*endFreq)+((1.0f-frac)*startFreq);
+ }
+}
void musicscore::makeFlakes(int threshStart,int threshEnd,levelscore *levels){
flakes.clear();
//decimate notes to generate flakes that can be interacted with
@@ -233,7 +242,6 @@ void musicscore::drawFlakes(float hOffs,levelscore *levels,float scale) { } else missedNote=-1; - ofDisableAlphaBlending();
}
void musicscore::playerControl(int key){
map<int,flake*>::iterator iter;
@@ -246,6 +254,13 @@ void musicscore::playerControl(int key){ }
}
//---------------------------------------------------------------------------------------------------------------------------------------------
+song::song(){
+ isPractice=true;
+}
+song::~song(){
+ backing.unloadSound();
+ melody.unloadSound();
+}
song::song(string backfile,string melfile,string musfile,string lyricfile,string levelfile) {
backing.loadSound(backfile);
melody.loadSound(melfile);
@@ -253,6 +268,7 @@ song::song(string backfile,string melfile,string musfile,string lyricfile,string lyrics.load(lyricfile);
levels.load(levelfile);
isPlaying=false;
+ isPractice=false;
}
void song::setTimeframe(int millis) {notes.setTimeframe(millis);}
void song::setKeyThresh(int millis) {notes.keyThresh=millis;}
@@ -264,13 +280,7 @@ int song::getCurrentTime(){ return ofGetElapsedTimeMillis()-startTime;
}
void song::play() {
- backing.play();
- melody.play();
- startTime=ofGetElapsedTimeMillis();
- notes.start(); - lyrics.start();
- isPlaying=true;
- notes.makeFlakes(fThreshStart,fThreshEnd,&levels);
+ preRoll(0);
}
void song::stop() {
backing.stop();
@@ -279,25 +289,36 @@ void song::stop() { }
void song::preRoll(long preroll) {
startTime=ofGetElapsedTimeMillis()+preroll;
- notes.start(startTime); - lyrics.start(startTime);
+ if (isPractice) {
+ notes.makeRandomNotes(20000,4000,1000);
+ levels.makePractice(20000);
+ }
+ else {
+ lyrics.start(startTime);
+ }
+ notes.makeFlakes(fThreshStart,fThreshEnd,&levels);
+ notes.start(startTime);
isPreroll=true;
isPlaying=true;
- notes.makeFlakes(fThreshStart,fThreshEnd,&levels);
}
void song::drawNotes(float hOffs){
notes.drawNotes(hOffs,&levels);
}
+string song::getScoreString(){
+ int songTime=ofGetElapsedTimeMillis()-startTime;
+ return ofToString((float)songTime/1000.0f,1)+" "+ofToString(levels.getLevel(songTime))+" "+ofToString(notes.missedFlakes)+" of "+ofToString(levels.getLives(songTime));
+}
void song::draw(float hOffs,float scale){
int songTime=ofGetElapsedTimeMillis()-startTime;
if (isPlaying) {
- if (isPreroll) {
+ if (isPreroll&&(!isPractice)) {
if (startTime<ofGetElapsedTimeMillis()) {
backing.play();
melody.play();
isPreroll=false;
}
}
+ notes.drawFlakes(hOffs,&levels,scale);
if (notes.missedLast) {
melody.setVolume(0.0f);
if (levels.getLives(songTime)) {
@@ -307,16 +328,13 @@ void song::draw(float hOffs,float scale){ }
}
}
- else melody.setVolume(1.0f);
- notes.drawFlakes(hOffs,&levels,scale); - lyrics.draw(hOffs);
+ else melody.setVolume(1.0f); + if (!isPractice) lyrics.draw(hOffs);
if (songTime>levels.length) {
printf("stopping: %i (%i)\n",songTime,levels.length);
stop();
}
}
-
- ofDrawBitmapString(ofToString((float)songTime/1000.0f,1)+" "+ofToString(levels.getLevel(songTime))+" "+ofToString(notes.missedFlakes)+" of "+ofToString(levels.getLives(songTime)),hOffs+10,(ofGetHeight()*gridY[1])-3);
}
void song::playerControl(int key){
notes.playerControl(key);
diff --git a/vfg/src/music.h b/vfg/src/music.h index 8733bb1..e4e8601 100755 --- a/vfg/src/music.h +++ b/vfg/src/music.h @@ -34,6 +34,11 @@ class levelscore { printf("time %i: level %i, nextleveltime %i\n",i,getLevel(i), nextLevelTime(i));
}
}
+ void makePractice(int l){
+ levels[0]=0;
+ levels[l]=0;
+ length=l;
+ }
int getLives(int time) {
map<int,int>::iterator iter;
int lives=0;
@@ -160,6 +165,7 @@ class musicscore: public score { void drawNotes(float hOffs,levelscore *levels);
void drawFlakes(float hOffs,levelscore *levels,float scale);
void playerControl(int key);
+ void makeRandomNotes(int length,int startFreq,int endFreq);
void makeFlakes(int threshStart,int threshEnd,levelscore *levels);
void printNotes();
int missedFlakes; @@ -182,6 +188,8 @@ class musicscore: public score { //---------------------------------------------------------------------------------------------------------------------------------------------
class song {
public:
+ song();
+ virtual ~song();
song(string backfile,string melfile,string musfile,string lyricfile,string levelfile);
void play();
void stop();
@@ -197,8 +205,9 @@ class song { void playerControl(int key);
int getLevel(long time);
int getCurrentTime();
+ string getScoreString();
- musicscore notes;
+ musicscore notes;
private:
ofSoundPlayer backing;
ofSoundPlayer melody;
@@ -206,7 +215,7 @@ class song { levelscore levels;
long startTime;
- bool isPreroll;
+ bool isPreroll,isPractice;
int fThreshStart,fThreshEnd;
};
diff --git a/vfg/src/testApp.cpp b/vfg/src/testApp.cpp index 6001da4..7c596d0 100755 --- a/vfg/src/testApp.cpp +++ b/vfg/src/testApp.cpp @@ -5,13 +5,22 @@ guiWindow::~guiWindow(){ cout << "gui window destroyed" << endl; } -void guiWindow::setup(){} +void guiWindow::setup(){ +} void guiWindow::setParent(testApp *p){ parent=p; } void guiWindow::draw(){ + ofDisableAlphaBlending(); parent->gui.draw(); + ofSetColor(255,255,255); + ofDrawBitmapString(ofToString(parent->game.queued)+" in queue", 10,ofGetHeight()-15); + char buf[8]; + sprintf(buf,"%.1f",ofGetFrameRate()); + ofDrawBitmapString(buf, ofGetWidth()-43,ofGetHeight()-15); + ofDrawBitmapString(levelnames[parent->gamestate-1], 10,ofGetHeight()-35); + if (parent->gamestate==GAME_PLAYING) ofDrawBitmapString(parent->songs[parent->currentsong]->getScoreString(),10,ofGetHeight()-55); } void guiWindow::dragEvent(ofDragInfo dragInfo, ofxFenster* win){ @@ -23,6 +32,9 @@ void guiWindow::windowMoved(int x,int y){ //---------------------------------------------------------------------- void testApp::setup(){ + + game.setup("1122"); + gamepoll=0; songs.push_back(new song("WeWishYouAMerryChistmas_v.2.1/VODA_MUS_WEWISHU_Backing_v.2.1.mp3","WeWishYouAMerryChistmas_v.2.1/VODA_MUS_WEWISHU_Lead_v.2.1.mp3","VODA_MUS_WEWISHU_Midi_v.2.2.xml","Lyrics_WeWishYou.2.1.xml","Levels_WeWishYou.2.1.xml")); songs.push_back(new song("DeckTheHalls_v.4.0/VODA_MUS_DeckTheHalls-Backing_v.4.0.mp3","DeckTheHalls_v.4.0/VODA_MUS_DeckTheHalls-Lead_v.4.0.mp3","VODA_MIDI_DeckTheHalls-v.4.0.xml","Lyrics_DeckTheHalls.4.0.xml","Levels_DeckTheHalls.4.0.xml")); @@ -40,6 +52,7 @@ void testApp::setup(){ penguins[1].load("Penguin-Purple.xml"); penguins[2].load("Penguin-Green.xml"); + // temp save time for (int i=0;i<3;i++) raccoons.push_back(Animal()); raccoons[0].load("Raccoon-Blue.xml"); @@ -52,16 +65,25 @@ void testApp::setup(){ tags.push_back(new Tag("Tags/TAG_Level-2.png",3000,0.5,0)); tags.push_back(new Tag("Tags/TAG_Level-3.png",3000,0.5,0)); tags.push_back(new Tag("Tags/TAG_Level-4.png",3000,0.5,0)); + tags.push_back(new Tag("Tags/PreGame-Practice.png",3000,0.5,0)); + tags.push_back(new Tag("Tags/Game-Over.png",3000,0.5,0)); + tags.push_back(new Tag("Tags/Thanks-NEW.png",3000,0.5,0)); + logos.push_back(new Billboard("Logo-VF.png",0.5,0.0)); logos.push_back(new Billboard("Logo-DCC.png",0.36,0.855)); lyricspanel=new Billboard("Lyrics-panel.png",0.5,0.703); - banner.load("Ribbon/Dublin/Ribbon_%05i.png",500); + banner.load("Ribbon/Dublin/Ribbon-Dublin_%05i.png",500); banner.setAnchorPercent(0.5,0.0); banner.setFrameRate(50); banner.play(); + + wirebirds.load("Birds-with-Wire/Birds-with-Wire_%05i.png",125); + wirebirds.setAnchorPercent(0.5,0.5); + wirebirds.setFrameRate(50); + wirebirds.play(); //loadanimals("Raccoons"); playanimal =&penguins; @@ -72,23 +94,34 @@ void testApp::setup(){ //release: commented out: 436m 256m //508fr 1.4s load in use: 836m 443m + + //cd /home/tim/workspace/VFxmas/vfg/bin/data + //mount -t tmpfs -o size=64M tmpfs /RAM + //cp *.m* RAM - intro.loadMovie("Game-Demo_v3.mp4"); + intro.loadMovie("RAM/Game-Demo_v5.mp4"); intro.setLoopState(OF_LOOP_NONE); + intro.setVolume(0.0); - advert.loadMovie("GW2003761_GRY-VFBR055-060_MPEG_hi.mpg"); + advert.loadMovie("RAM/GW2003761_GRY-VFBR055-060_MPEG_hi.mov"); advert.setLoopState(OF_LOOP_NONE); + advert.setVolume(1.0); - background.loadMovie("Background_v3.mp4"); + background.loadMovie("RAM/Background_v3.mp4"); background.setLoopState(OF_LOOP_NORMAL); background.play(); + + backgroundmusic.loadSound("VODA_MUS_Pre-Game-Music_v.1.1.mp3"); + backgroundmusic.setLoop(true); + backgroundmusic.play(); + backgroundmusic.setVolume(1.0); vignette.loadImage("Vignette.png"); showFPS=true; - showVis=true; + showVis=false; fullscreenoutput=false; - fadelength=1000; + fadelength=3000; segmentStartTime=0; currentsong=0; nextsong=0; @@ -137,26 +170,29 @@ void testApp::loadanimals(string which) { void testApp::exit(){ delete lyricspanel; + backgroundmusic.unloadSound(); } //-------------------------------------------------------------- void testApp::update(){ int ret=game.update(); + if (ofGetElapsedTimeMillis()-gamepoll>5000) { + game.requestStatus(); + gamepoll=ofGetElapsedTimeMillis(); + } if (ret==1000) { - currentlevel=0; - currentsong=nextsong; - songs[currentsong]->setTimeframe(timescale); - songs[currentsong]->setFlakeThresh(threshStart,threshEnd); - songs[currentsong]->setKeyThresh(keyThresh); - songs[currentsong]->preRoll(5000); - tags[0]->play(); - nextsong=(nextsong+1)%songs.size(); - gamestate=GAME_PRACTICE; + activatePractice(); } else if (ret>48&&ret<52) { songs[currentsong]->playerControl(ret-49); + practiceSong.playerControl(ret-49); (*playanimal)[ret-49].playNow("Clap"); } + else if (ret>51&&ret<55) { + songs[currentsong]->playerControl(ret-52); + practiceSong.playerControl(ret-52); + (*playanimal)[ret-52].playNow("Clap"); + } if (songs[currentsong]->isPlaying&&songs[currentsong]->getLevel(ofGetElapsedTimeMillis()+4000)>currentlevel) { int anim=ofRandom(1.9999); //this gives a binary random number for (int i=0;i<3;i++) { @@ -177,21 +213,23 @@ void testApp::update(){ case GAME_PLAYING: case GAME_ENDPLAYING: case GAME_ENDINGINTRO: - case GAME_ENDINGADVERT: case GAME_PRACTICE: - background.update(); - banner.update(); + background.update(); + banner.update(); + wirebirds.update(); break; case GAME_STARTINGINTRO: background.update(); case GAME_INTRO: - intro.update(); - break; + intro.update(); + break; case GAME_STARTINGADVERT: - background.update(); + case GAME_ENDINGADVERT: + background.update(); + banner.update(); case GAME_ADVERT: - advert.update(); - break; + advert.update(); + break; } } @@ -210,8 +248,8 @@ void testApp::update(){ */ //-------------------------------------------------------------- void testApp::drawBackgroundLayers(){ + float hOffs=(ofGetWidth()-ofGetHeight())/2; background.draw(hOffs,0,ofGetHeight(),ofGetHeight()); - scale=ofGetHeight()/1080.0f; ofEnableAlphaBlending(); vignette.draw(hOffs,0,ofGetHeight(),ofGetHeight()); ofDisableAlphaBlending(); @@ -221,13 +259,110 @@ void testApp::draw(){ ofDisableAlphaBlending(); ofSetColor(255,255,255); float hOffs=(ofGetWidth()-ofGetHeight())/2; - float bannerscale,scale; //this old chestnut + float scale=ofGetHeight()/1080.0f; + float bannerscale,aspect,wOffs; //this old chestnut + float segamt=((float)(ofGetElapsedTimeMillis()-segmentStartTime)*2.0f)/fadelength; //same variable used in all segments + switch(gamestate) { - + case GAME_STARTINGINTRO: + case GAME_INTRO: + case GAME_ENDINGINTRO: case GAME_READY: + case GAME_STARTINGADVERT: + case GAME_ADVERT: + case GAME_ENDINGADVERT: + case GAME_STARTPLAYING: + case GAME_PRACTICE: case GAME_PLAYING: + case GAME_ENDPLAYING: + break; + } + //draw backgrounds + switch(gamestate) { + case GAME_STARTINGINTRO: + case GAME_INTRO: + case GAME_ENDINGINTRO: + intro.draw(hOffs,0,ofGetHeight(),ofGetHeight()); + if (intro.getCurrentFrame()==intro.getTotalNumFrames()) { + gamestate=GAME_READY; + } + break; + case GAME_READY: + case GAME_STARTPLAYING: + case GAME_PRACTICE: + case GAME_PLAYING: + case GAME_ENDPLAYING: drawBackgroundLayers(); - + break; + case GAME_STARTINGADVERT: + if (segamt<0.5) { + ofEnableAlphaBlending(); + ofSetColor(255,255,255,255-(segamt*510)); + drawBackgroundLayers(); + break; + } + else if (segamt>1.0) { + gamestate=GAME_ADVERT; + } + else { + //if (!advert.isPlaying()) advert.play(); + ofEnableAlphaBlending(); + ofSetColor(255,255,255,((segamt-0.5)*510)); + } + case GAME_ADVERT: + case GAME_ENDINGADVERT: + if (gamestate==GAME_ENDINGADVERT) { + if (segamt<0.5) { + ofEnableAlphaBlending(); + segamt=((float)(ofGetElapsedTimeMillis()-segmentStartTime))/fadelength; + ofSetColor(255,255,255,255-(segamt*510)); + } + else if (segamt>1.0) { + gamestate=GAME_READY; + ofSetColor(255,255,255); + ofDisableAlphaBlending(); + drawBackgroundLayers(); + break; + } + else { + ofDisableAlphaBlending(); + ofSetColor(((segamt-0.5)*510),((segamt-0.5)*510),((segamt-0.5)*510)); + drawBackgroundLayers(); + break; + } + } + aspect=advert.getHeight()/advert.getWidth(); + wOffs=(ofGetHeight()-(ofGetWidth()*aspect))*0.5; + advert.draw(0,wOffs,ofGetWidth(),ofGetWidth()*aspect); + ofDisableAlphaBlending(); //may have been turned on during intro + + break; + + } + + //draw game action + switch(gamestate) { + case GAME_STARTINGADVERT: + if (segamt<0.5) { + ofEnableAlphaBlending(); + ofSetColor(255,255,255,255-(segamt*510)); + } + else break; + case GAME_ENDINGADVERT: + if (segamt>0.5) { + ofEnableAlphaBlending(); + ofSetColor(255,255,255,((segamt-0.5)*510)); + } + else break; + case GAME_READY: + for (int i=0;i<3;i++) { + //break up standing around movement + if (ofRandom(1.0)<.002) (*playanimal)[i].play("Shuffle"); + } + case GAME_PLAYING: + case GAME_PRACTICE: + case GAME_ENDPLAYING: + ofEnableAlphaBlending(); if (songs[currentsong]->isPlaying) { ofSetColor(255,255,255); if (showVis) songs[currentsong]->drawNotes(hOffs); @@ -236,78 +371,138 @@ void testApp::draw(){ int hit=songs[currentsong]->hitNote(); if (hit>-1) (*playanimal)[hit].play("Catch"); } - else { - if (gamestate==GAME_PLAYING) { - game.endGame("GOOD!"); - gamestate=GAME_READY; + else if (gamestate==GAME_PRACTICE) { + int missed=practiceSong.missedNote(); + if (missed>-1) (*playanimal)[missed].playNow("Shudder"); + int hit=practiceSong.hitNote(); + if (hit>-1) (*playanimal)[hit].play("Catch"); + } - } - ofSetColor(255,255,255); for (int i=0;i<3;i++) (*playanimal)[i].draw(hOffs+(gridX[i+1]*ofGetHeight()),gridY[0]*ofGetHeight(),scale); if (songs[currentsong]->isPlaying) { - ofSetColor(255,255,255); lyricspanel->draw(ofGetWidth()*0.5,ofGetHeight()*gridY[1],scale); songs[currentsong]->draw(hOffs,scale); } - else { - ofDrawBitmapString("game over!", (ofGetWidth()/2)-25,(ofGetHeight()/2)-5); - logos[1]->draw((gridX[0]*ofGetHeight())+hOffs,gridY[1]*ofGetHeight(),scale); - } - ofSetColor(255,255,255); - for (int i=0;i<tags.size();i++) { - if (tags[i]->isPlaying) tags[i]->draw(0.5f*ofGetWidth(),0,scale); + else if (gamestate==GAME_PRACTICE) { + practiceSong.draw(hOffs,scale); } - logos[0]->draw((gridX[0]*ofGetHeight())+hOffs,0,scale); - bannerscale=songs[currentsong]->isPlaying?scale*(1.0f-(max(0.0,min(((float)songs[currentsong]->getCurrentTime())*.001,1.0))*0.325)):scale; + } + //draw characters + switch(gamestate) { + case GAME_STARTINGADVERT: + if (segamt<0.5) { + ofEnableAlphaBlending(); + ofSetColor(255,255,255,255-(segamt*510)); + } + else break; + case GAME_ENDINGADVERT: + if (segamt>0.5) { + ofEnableAlphaBlending(); + ofSetColor(255,255,255,((segamt-0.5)*510)); + } + else break; + case GAME_READY: + //DCC LOGO + logos[1]->draw((gridX[0]*ofGetHeight())+hOffs,gridY[1]*ofGetHeight(),scale); + case GAME_STARTPLAYING: + case GAME_PRACTICE: + case GAME_PLAYING: + case GAME_ENDPLAYING: + ofEnableAlphaBlending(); + if (gamestate!=GAME_STARTINGADVERT&&gamestate!=GAME_ENDINGADVERT) ofSetColor(255,255,255); + for (int i=0;i<tags.size();i++) { + if (tags[i]->isPlaying) tags[i]->draw(0.5f*ofGetWidth(),0,scale); + } + logos[0]->draw((gridX[0]*ofGetHeight())+hOffs,0,scale); + break; + } + //draw banner, DCC logo and wirebirds + bannerscale=scale; + ofSetColor(255,255,255); + switch(gamestate) { + case GAME_PRACTICE: + ofEnableAlphaBlending(); + bannerscale=scale*(1.0f-(max(0.0,min(((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.002,1.0))*0.325)); + wirebirds.draw(ofGetWidth()/2,ofGetHeight()*0.65,scale); + segamt=1.0; + ofEnableAlphaBlending(); banner.draw(ofGetWidth()*0.5,0,bannerscale); - char buf[30]; - sprintf(buf,"%.1f",ofGetFrameRate()); - if (showFPS) ofDrawBitmapString(buf, hOffs+ofGetHeight()-50,(ofGetHeight()*gridY[1])-3); - break; - case GAME_INTRO: - intro.draw(hOffs,0,ofGetHeight(),ofGetHeight()); - if (intro.getCurrentFrame()==intro.getTotalNumFrames()) { - gamestate=GAME_READY; - } break; case GAME_STARTINGADVERT: - float segamt=((float)(ofGetElapsedTimeMillis()-segmentStartTime))/fadelength; if (segamt<0.5) { ofEnableAlphaBlending(); - ofSetColor(255,255,255,255-(segamt*512)); - break; - } - else if (segamt>1.0) { - gamestate=GAME_ADVERT; - break; + ofSetColor(255,255,255,255-(segamt*510)); } - else { - if (!advert.isPlaying()) advert.play(); + else break; + case GAME_ENDINGADVERT: + if (segamt>0.5) { ofEnableAlphaBlending(); - ofSetColor(255,255,255,((segamt-0.5)*512)); + ofSetColor(255,255,255,((segamt-0.5)*510)); } + else break; + case GAME_READY: + ofEnableAlphaBlending(); + banner.draw(ofGetWidth()*0.5,0,bannerscale); + break; + case GAME_STARTPLAYING: + case GAME_PLAYING: + bannerscale=scale*0.675; + ofEnableAlphaBlending(); + banner.draw(ofGetWidth()*0.5,0,bannerscale); + break; + case GAME_ENDPLAYING: + bannerscale=scale*(0.675+(max(0.0,min(((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001,1.0))*0.325)); + ofEnableAlphaBlending(); + banner.draw(ofGetWidth()*0.5,0,bannerscale); + break; + } + //switch states: + switch(gamestate) { + case GAME_STARTINGINTRO: + case GAME_INTRO: + case GAME_ENDINGINTRO: + case GAME_READY: + break; + case GAME_STARTINGADVERT: + backgroundmusic.setVolume(max(0.0,1.0-(segamt*2.0))); case GAME_ADVERT: - case GAME_ENDINGADVERT: - if (gamestate==GAME_ENDINGADVERT) - float aspect=advert.getHeight()/advert.getWidth(); - float wOffs=(ofGetHeight()-(ofGetWidth()*aspect))*0.5; - advert.draw(0,wOffs,ofGetWidth(),ofGetWidth()*aspect); - ofDisableAlphaBlending(); //may have been turned on during intro - if (advert.getCurrentFrame()==advert.getTotalNumFrames()) { + if (advert.getCurrentFrame()==advert.getTotalNumFrames()&&gamestate==GAME_ADVERT) { gamestate=GAME_ENDINGADVERT; segmentStartTime=ofGetElapsedTimeMillis(); } break; + case GAME_ENDINGADVERT: + backgroundmusic.setVolume(max(0.0,(segamt-0.5)*2.0)); + case GAME_STARTPLAYING: + case GAME_PRACTICE: + break; + case GAME_PLAYING: + backgroundmusic.setVolume(max(0.0,1.0-(segamt*2.0))); + if (!songs[currentsong]->isPlaying) { + game.endGame("GOOD!"); + gamestate=GAME_ENDPLAYING; + tags[6]->play(); + segmentStartTime=ofGetElapsedTimeMillis(); + } + break; + case GAME_ENDPLAYING: + backgroundmusic.setVolume(max(0.0,(segamt-0.5)*2.0)); + if (segamt>1.0) { + gamestate=GAME_READY; + switchAnimals(); + } + break; } - } + + //-------------------------------------------------------------- void testApp::keyPressedEvent(ofKeyEventArgs &args) { //printf("window key pressed: %i (%c)\n",args.key,args.key); keyPressed(args.key); } void testApp::keyPressed(int key, ofxFenster* win){ - //printf("window sent %i\n",key); + //xprintf("window sent %i\n",key); if(key == '='){ fullscreenoutput=!fullscreenoutput; win->setFullscreen(fullscreenoutput); @@ -316,25 +511,50 @@ void testApp::keyPressed(int key, ofxFenster* win){ else keyPressed(key); } //-------------------------------------------------------------- +void testApp::activateGame(){ + segmentStartTime=ofGetElapsedTimeMillis(); + currentlevel=0; + currentsong=nextsong; + songs[currentsong]->setTimeframe(timescale); + songs[currentsong]->setFlakeThresh(threshStart,threshEnd); + songs[currentsong]->setKeyThresh(keyThresh); + songs[currentsong]->play(); + tags[0]->play(); + nextsong=(nextsong+1)%songs.size(); + gamestate=GAME_PLAYING; +} +void testApp::activatePractice(){ + segmentStartTime=ofGetElapsedTimeMillis(); + gamestate=GAME_PRACTICE; + currentlevel=0; + practiceSong.setTimeframe(timescale); + practiceSong.setFlakeThresh(threshStart,threshEnd); + practiceSong.setKeyThresh(keyThresh); + practiceSong.play(); + tags[5]->play(); +} +void testApp::switchAnimals(){ + if (playanimal==&raccoons) playanimal=&penguins; + else playanimal =&raccoons; +} +//-------------------------------------------------------------- void testApp::keyPressed(int key){ switch (key) { + case 'x': + if (gamestate==GAME_READY||gamestate==GAME_PRACTICE) { + activatePractice(); + } + break; case ' ': - if (gamestate==GAME_READY) { - currentlevel=0; - currentsong=nextsong; - songs[currentsong]->setTimeframe(timescale); - songs[currentsong]->setFlakeThresh(threshStart,threshEnd); - songs[currentsong]->setKeyThresh(keyThresh); - songs[currentsong]->preRoll(5000); - tags[0]->play(); - nextsong=(nextsong+1)%songs.size(); - gamestate=GAME_PRACTICE; + if (gamestate==GAME_PRACTICE) { + activateGame(); } break; case '1': case '2': case '3': songs[currentsong]->playerControl(key-'1'); + practiceSong.playerControl(key-'1'); (*playanimal)[key-'1'].playNow("Clap"); break; case 's': @@ -350,6 +570,7 @@ void testApp::keyPressed(int key){ break; case 'q': if (gamestate==GAME_READY) { + intro.firstFrame(); intro.play(); gamestate=GAME_INTRO; } @@ -358,6 +579,8 @@ void testApp::keyPressed(int key){ if (gamestate==GAME_READY) { segmentStartTime=ofGetElapsedTimeMillis(); gamestate=GAME_STARTINGADVERT; + advert.firstFrame(); + advert.play(); } break; case 'f': diff --git a/vfg/src/testApp.h b/vfg/src/testApp.h index c287fb1..4852073 100755 --- a/vfg/src/testApp.h +++ b/vfg/src/testApp.h @@ -73,14 +73,19 @@ class testApp : public ofxFensterListener{ void gotMessage(ofMessage msg); void drawBackgroundLayers(); + void activateGame(); + void activatePractice(); + void switchAnimals(); ofVideoPlayer intro; ofVideoPlayer advert; + ofSoundPlayer backgroundmusic; ofVideoPlayer background; ofImage vignette; vector<song*> songs; + song practiceSong; vector<Animal> penguins; @@ -96,6 +101,7 @@ class testApp : public ofxFensterListener{ vector<Billboard*> logos; puppetSprite banner; + puppetSprite wirebirds; Billboard* lyricspanel; @@ -103,12 +109,15 @@ class testApp : public ofxFensterListener{ int currentlevel; Asterisk game; + int gamepoll; bool showFPS; bool showVis; bool fullscreenoutput; - int currentsong,nextsong,gamestate,segmentStartTime,fadelength; + int currentsong,nextsong,gamestate,segmentStartTime; + + float fadelength; guiWindow *guiWin; ofxPanel gui; @@ -132,6 +141,19 @@ public: void draw(); void dragEvent(ofDragInfo dragInfo,ofxFenster* win); void windowMoved(int x, int y); + string levelnames[11]={ + "STARTINGINTRO", + "INTRO", + "ENDINGINTRO", + "READY", + "STARTINGADVERT", + "ADVERT", + "ENDINGADVERT", + "STARTPLAYING", + "PRACTICE", + "PLAYING", + "ENDPLAYING" + }; }; diff --git a/vfg/vfg.layout b/vfg/vfg.layout index 2381d4d..e3ee66d 100644 --- a/vfg/vfg.layout +++ b/vfg/vfg.layout @@ -1,37 +1,37 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_layout_file> <ActiveTarget name="Debug" /> - <File name="addons.make" open="1" top="0" tabpos="6"> + <File name="addons.make" open="1" top="0" tabpos="2"> <Cursor position="80" topLine="0" /> </File> - <File name="src/Asterisk.cpp" open="1" top="0" tabpos="1"> - <Cursor position="48" topLine="3" /> + <File name="src/Asterisk.cpp" open="1" top="0" tabpos="5"> + <Cursor position="487" topLine="27" /> </File> <File name="src/Asterisk.h" open="0" top="0" tabpos="3"> <Cursor position="106" topLine="23" /> </File> - <File name="src/Puppet.cpp" open="1" top="0" tabpos="3"> - <Cursor position="502" topLine="23" /> + <File name="src/Puppet.cpp" open="1" top="0" tabpos="1"> + <Cursor position="502" topLine="0" /> </File> - <File name="src/Puppet.h" open="1" top="0" tabpos="2"> + <File name="src/Puppet.h" open="0" top="0" tabpos="2"> <Cursor position="312" topLine="0" /> </File> - <File name="src/Tag.h" open="1" top="0" tabpos="5"> + <File name="src/Tag.h" open="0" top="0" tabpos="5"> <Cursor position="551" topLine="0" /> </File> <File name="src/main.cpp" open="0" top="0" tabpos="1"> <Cursor position="219" topLine="0" /> </File> - <File name="src/music.cpp" open="0" top="0" tabpos="8"> - <Cursor position="11476" topLine="290" /> + <File name="src/music.cpp" open="0" top="0" tabpos="5"> + <Cursor position="10158" topLine="241" /> </File> <File name="src/music.h" open="0" top="0" tabpos="6"> <Cursor position="4738" topLine="125" /> </File> <File name="src/testApp.cpp" open="1" top="1" tabpos="4"> - <Cursor position="4721" topLine="105" /> + <Cursor position="16084" topLine="505" /> </File> - <File name="src/testApp.h" open="1" top="0" tabpos="7"> - <Cursor position="2881" topLine="86" /> + <File name="src/testApp.h" open="1" top="0" tabpos="3"> + <Cursor position="2007" topLine="46" /> </File> </CodeBlocks_layout_file> |
