summaryrefslogtreecommitdiff
path: root/vfg/src
diff options
context:
space:
mode:
authorTim Redfern <tim@gray.(none)>2012-11-22 11:00:03 +0000
committerTim Redfern <tim@gray.(none)>2012-11-22 11:00:03 +0000
commit9dc429df9dbd1a5ae0f93d553ccfde7ab37a53a2 (patch)
treec0891b8554cf6973aae12ade27bd85be2a1f6a09 /vfg/src
parentb4d89c0a9029739d2af1705b371dc28f27b6d2dc (diff)
gameplay good: up against memory limit
Diffstat (limited to 'vfg/src')
-rwxr-xr-xvfg/src/Puppet.cpp10
-rwxr-xr-xvfg/src/Puppet.h11
-rwxr-xr-xvfg/src/music.cpp23
-rwxr-xr-xvfg/src/music.h10
-rwxr-xr-xvfg/src/testApp.cpp77
-rwxr-xr-xvfg/src/testApp.h12
6 files changed, 105 insertions, 38 deletions
diff --git a/vfg/src/Puppet.cpp b/vfg/src/Puppet.cpp
index 0fd07a6..90ba137 100755
--- a/vfg/src/Puppet.cpp
+++ b/vfg/src/Puppet.cpp
@@ -21,8 +21,8 @@ void Puppet::load(string filename) {
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]=puppetSprite();
+ clips[name].load(XML.getAttribute("Clip", "files","",i),XML.getAttribute("Clip", "frames",0,i),XML.getAttribute("Clip", "start",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);
@@ -34,7 +34,7 @@ void Puppet::load(string filename) {
}
}
-void Puppet::draw(float x, float y) {
+void Puppet::draw(float x, float y, float scale) {
if (playlist.size()>0) {
if (!clips[playlist[0]].getIsPlaying()) {
playlist.erase(playlist.begin());
@@ -44,11 +44,11 @@ void Puppet::draw(float x, float y) {
}
}
if (playlist.size()==0) {
- if (clips.find("base") != clips.end()) clips["base"].draw(x,y);
+ if (clips.find("base") != clips.end()) clips["base"].draw(x,y,scale);
}
else {
clips[playlist[0]].update();
- clips[playlist[0]].draw(x,y);
+ clips[playlist[0]].draw(x,y,scale);
}
}
diff --git a/vfg/src/Puppet.h b/vfg/src/Puppet.h
index e0df87a..7ee80ee 100755
--- a/vfg/src/Puppet.h
+++ b/vfg/src/Puppet.h
@@ -11,6 +11,13 @@
TODO: make resolution independent
*/
+class puppetSprite: public ofxSprite {
+ public:
+ void draw(float x, float y, float scale) {
+ getCurrentImage().draw(x-(anchorPoint.x*scale),y-(anchorPoint.y*scale),getWidth()*scale,getHeight()*scale);
+ }
+};
+
class Puppet
{
public:
@@ -19,11 +26,11 @@ class Puppet
void load(string filename);
void play(string clip);
void playNow(string clip);
- void draw(float x, float y);
+ void draw(float x, float y, float scale=1.0f);
bool isPlaying();
protected:
private:
- map<string,ofxSprite> clips;
+ map<string,puppetSprite> clips;
deque<string> playlist;
};
diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp
index eda58be..359b21d 100755
--- a/vfg/src/music.cpp
+++ b/vfg/src/music.cpp
@@ -32,6 +32,7 @@ musicscore::musicscore() {
missedLast=false;
nowpoint=1.0f;
missedNote=-1;
+ hitNote=-1;
snowflakes.push_back(Puppet());
snowflakes.push_back(Puppet());
@@ -163,7 +164,7 @@ void musicscore::drawNotes(levelscore *levels) {
int thisnote=iter->second->num-firstnote;
int thisstart=iter->first-scoreStart;
int thislength=iter->second->duration;
- ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,100));
+ ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,100),120);
ofRect(thisnote*widthStep,ofGetHeight()-(thisstart*heightStep),widthStep,-(thislength*heightStep));
}
@@ -172,6 +173,7 @@ void musicscore::drawFlakes(levelscore *levels) {
ofEnableAlphaBlending();
int scoreStart=ofGetElapsedTimeMillis()-startTime-((1.0f-nowpoint)*timeframe);
int scoreEnd=scoreStart+timeframe;
+ float scale=ofGetHeight()/1080.0f;
//note drawing 46h - 52h
int numnotes=16;
int firstnote=70;
@@ -190,7 +192,7 @@ void musicscore::drawFlakes(levelscore *levels) {
//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));
+ iter->second->draw(gridX[notemap(iter->second->num)]*ofGetWidth(),ofGetHeight()-(thisstart*heightStep),scale);
//todo - make all drawing resolution independent
}
@@ -201,16 +203,17 @@ void musicscore::drawFlakes(levelscore *levels) {
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++){
+ for (iter = flakes.lower_bound(levels->getLowerBound(levels->getLevel(scoreStart))); iter != flakes.lower_bound(scoreStart); iter++){
if (!iter->second->activated) {
missedFlakes++;
missed=iter;
}
missedLast=!iter->second->activated;
- }
+ }
+ //at this point missed points to the latest unactivated flake in the level
if ((missed!=flakes.end())&&(missedFlake!=missed)) {
missedFlake=missed;
- missedNote=notemap(iter->second->num);
+ missedNote=notemap(missed->second->num);
}
else missedNote=-1;
@@ -220,7 +223,10 @@ void musicscore::playerControl(int key,int threshold){
map<int,flake*>::iterator iter;
int scoreTime=ofGetElapsedTimeMillis()-startTime;
for (iter = flakes.lower_bound(scoreTime-threshold); iter != flakes.upper_bound(scoreTime+threshold); iter++) {
- if (key==notemap(iter->second->num)) iter->second->activate();
+ if (key==notemap(iter->second->num)) {
+ iter->second->activate();
+ hitNote=key;
+ }
}
}
//---------------------------------------------------------------------------------------------------------------------------------------------
@@ -296,4 +302,9 @@ void song::playerControl(int key){
}
int song::missedNote(){
return notes.missedNote;
+}
+int song::hitNote(){
+ int n=notes.hitNote;
+ notes.hitNote=-1;
+ return n;
}
diff --git a/vfg/src/music.h b/vfg/src/music.h
index f9317de..7e54292 100755
--- a/vfg/src/music.h
+++ b/vfg/src/music.h
@@ -4,6 +4,10 @@
#include "ofxXmlSettings.h"
#include "Puppet.h"
+//Grid for drawing
+static float gridX[3]={0.3,0.5,0.7};
+static float gridY[1]={0.8};
+
//event times are absolute integer milliseconds
//---------------------------------------------------------------------------------------------------------------------------------------------
class levelscore {
@@ -73,8 +77,8 @@ class flake: public note, public Puppet {
activated=true;
puppet.play("shatter");
}
- void draw(float x, float y) {
- if (!activated||puppet.isPlaying()) puppet.draw(x,y);
+ void draw(float x, float y,float scale) {
+ if (!activated||puppet.isPlaying()) puppet.draw(x,y,scale);
}
};
//---------------------------------------------------------------------------------------------------------------------------------------------
@@ -144,6 +148,7 @@ class musicscore: public score {
int missedFlakes;
int missedNote;
+ int hitNote;
bool missedLast;
bool perfect;
@@ -170,6 +175,7 @@ class song {
void drawNotes();
void draw();
int missedNote();
+ int hitNote();
bool isPlaying;
void playerControl(int key);
private:
diff --git a/vfg/src/testApp.cpp b/vfg/src/testApp.cpp
index 8dd6110..bcef98e 100755
--- a/vfg/src/testApp.cpp
+++ b/vfg/src/testApp.cpp
@@ -3,8 +3,6 @@
//--------------------------------------------------------------
void testApp::setup(){
- //for (float i=0;i<1.2;i+=0.1) printf("%f in level %i bound %f\n",i,lives->getLevel(i),lives->getLowerBound(lives->getLevel(i)));
-
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->setFlakeThresh(1000,100);
@@ -12,28 +10,21 @@ void testApp::setup(){
ofSetBackgroundAuto(false);
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(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);
- penguins[0].setLoop(false);
- penguins[1].load("Penguin-Clap-Purple/Penguin-Clap-Purple_%05i.png",20);
- penguins[1].setAnchorPercent(0.5, 1.0);
- penguins[1].setFrameRate(50);
- penguins[1].setLoop(false);
- penguins[2].load("Penguin-Clap-Green/Penguin-Clap-Green_%05i.png",20);
- penguins[2].setAnchorPercent(0.5, 1.0);
- penguins[2].setFrameRate(50);
- penguins[2].setLoop(false);
+ 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");
*/
-
- //printf(ofSystem("ls -la").c_str());
+
+
+ loadanimals("Penguins");
+ playanimal =&playanimals;
//testpenguin.load("Penguin-Blue.xml");
//debug: commented out: 436m 257m
@@ -42,11 +33,34 @@ void testApp::setup(){
//release: commented out: 436m 256m
//508fr 1.4s load in use: 836m 443m
+ background.loadMovie("Background_v3.mp4");
+ background.setLoopState(OF_LOOP_NORMAL);
+ background.play();
+
+ vignette.loadImage("Vignette.png");
showFPS=false;
}
+void testApp::loadanimals(string which) {
+ playanimals.clear();
+
+ for (int i=0;i<3;i++) playanimals.push_back(Animal());
+
+ if (which=="Penguins") {
+ playanimals[0].load("Penguin-Blue.xml");
+ playanimals[1].load("Penguin-Purple.xml");
+ playanimals[2].load("Penguin-Green.xml");
+ }
+ else {
+ playanimals[0].load("Raccoon-Blue.xml");
+ playanimals[1].load("Raccoon-Purple.xml");
+ playanimals[2].load("Raccoon-Green.xml");
+ }
+
+}
+
void testApp::exit(){
delete testsong;
}
@@ -59,28 +73,39 @@ void testApp::update(){
}
else if (ret>0) {
testsong->playerControl(ret);
- penguins[ret-1].playNow("Clap");
+ (*playanimal)[ret-1].playNow("Clap");
}
for (int i=0;i<3;i++) {
- penguins[i].update();
+ (*playanimal)[i].update();
}
+ background.update();
}
//--------------------------------------------------------------
void testApp::draw(){
+ ofDisableAlphaBlending();
+ ofSetColor(255,255,255);
+ background.draw(0,0,ofGetWidth(),ofGetHeight());
+ float scale=ofGetHeight()/1080.0f;
+
ofEnableAlphaBlending();
+ vignette.draw(0,0,ofGetWidth(),ofGetHeight());
//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");
+ if (missed>-1) (*playanimal)[missed].playNow("Shudder");
+ int hit=testsong->hitNote();
+ if (hit>-1) (*playanimal)[hit].play("Catch");
}
ofSetColor(255,255,255);
- for (int i=0;i<3;i++) penguins[i].draw((i*300)+100,600);
+ for (int i=0;i<3;i++) (*playanimal)[i].draw(gridX[i]*ofGetWidth(),gridY[0]*ofGetHeight(),scale);
if (testsong->isPlaying) {
ofSetColor(255,255,255);
testsong->draw();
@@ -103,7 +128,7 @@ void testApp::keyPressed(int key){
case '2':
case '3':
testsong->playerControl(key-'1');
- penguins[key-'1'].playNow("Clap");
+ (*playanimal)[key-'1'].playNow("Clap");
break;
case 's':
game.startGame();
@@ -111,6 +136,12 @@ void testApp::keyPressed(int key){
case 'f':
showFPS=!showFPS;
break;
+ case 'r':
+ loadanimals("Raccoons");
+ break;
+ case 'p':
+ loadanimals("Penguins");
+ break;
}
}
diff --git a/vfg/src/testApp.h b/vfg/src/testApp.h
index f62c098..4ab807f 100755
--- a/vfg/src/testApp.h
+++ b/vfg/src/testApp.h
@@ -72,10 +72,22 @@ class testApp : public ofBaseApp{
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
+
+ void loadanimals(string which);
+
+ ofVideoPlayer background;
+ ofImage vignette;
song *testsong;
+ /*
vector<Animal> penguins;
+ vector<Animal> raccoons;
+ */
+
+ vector<Animal> playanimals;
+
+ vector<Animal>* playanimal;
Puppet testpenguin;