From 27b7b4c5ce0102c6089cd0b6cc58096b0c5ccf36 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 13 Nov 2012 00:16:01 +0000 Subject: penguin sprites --- vfg/addons.make | 3 +++ vfg/src/music.cpp | 37 ++++++++++++++++++++++++++++--------- vfg/src/music.h | 12 ++++++++---- vfg/src/testApp.cpp | 35 ++++++++++++++++++++++++++++++++--- vfg/src/testApp.h | 12 +++++++++--- vfg/vfg.cbp | 4 ++-- vfg/vfg.layout | 20 ++++++++++---------- 7 files changed, 92 insertions(+), 31 deletions(-) diff --git a/vfg/addons.make b/vfg/addons.make index a66eaad..c7d0bf4 100644 --- a/vfg/addons.make +++ b/vfg/addons.make @@ -1 +1,4 @@ ofxXmlSettings +ofxSpriteManager +ofxAssets +ofxExtras diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index ef43c11..4d62f6f 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -21,7 +21,8 @@ musicscore::musicscore() { timeframe=2000; flake.loadImage("flake.png"); flake.setAnchorPercent(0.5,0.5); - missedLast=false; + missedLast=false; + nowpoint=1.0f; } void musicscore::parseMidi(string filename){ // millis = 60000 / (BPM * PPQ) @@ -124,10 +125,10 @@ void musicscore::makeFlakes(int threshStart,int threshEnd){ lastTime=iter->first; } } -void musicscore::setTimeframe(int millis) {timeframe=millis;} -void musicscore::draw(levelscore *levels) { - ofEnableAlphaBlending(); - int scoreStart=ofGetElapsedTimeMillis()-startTime; +void musicscore::setTimeframe(int millis) {timeframe=millis;} +void musicscore::setNowpoint(float pct) {nowpoint=pct;} +void musicscore::drawNotes(levelscore *levels) { + int scoreStart=ofGetElapsedTimeMillis()-startTime-((1.0f-nowpoint)*timeframe); int scoreEnd=scoreStart+timeframe; //note drawing 46h - 52h int numnotes=16; @@ -144,6 +145,18 @@ void musicscore::draw(levelscore *levels) { ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,100)); ofRect(thisnote*widthStep,ofGetHeight()-(thisstart*heightStep),widthStep,-(thislength*heightStep)); } + +} +void musicscore::drawFlakes(levelscore *levels) { + ofEnableAlphaBlending(); + int scoreStart=ofGetElapsedTimeMillis()-startTime-((1.0f-nowpoint)*timeframe); + int scoreEnd=scoreStart+timeframe; + //note drawing 46h - 52h + int numnotes=16; + int firstnote=70; + float widthStep=((float)ofGetWidth())/numnotes; + float heightStep=((float)ofGetHeight())/timeframe; + map::iterator iter; //draw flakes for (iter = flakes.lower_bound(scoreStart-200); iter != flakes.upper_bound(scoreEnd); ++iter) { //extra 200ms for flake to leave screen int thisnote=iter->second->num-firstnote; @@ -151,7 +164,9 @@ void musicscore::draw(levelscore *levels) { 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((((thisnote/5)*5)+3.5f)*widthStep,ofGetHeight()-(thisstart*heightStep),flake.getWidth()/2,flake.getHeight()/2); + flake.draw(((thisnote/5)*300)+100,ofGetHeight()-(thisstart*heightStep),flake.getWidth()/2,flake.getHeight()/2); + + //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? @@ -180,7 +195,8 @@ song::song(string backfile,string melfile,string musfile,string lyricfile,string lyrics.load(lyricfile); levels.load(levelfile); isPlaying=false; - keyThresh=200; + keyThresh=200; + notes.setNowpoint(0.8f); } void song::setTimeframe(int millis) {notes.setTimeframe(millis);} void song::setKeythresh(int millis) {keyThresh=millis;} @@ -210,6 +226,9 @@ void song::preRoll(long preroll) { isPlaying=true; notes.makeFlakes(fThreshStart,fThreshEnd); } +void song::drawNotes(){ + notes.drawNotes(&levels); +} void song::draw(){ int songTime=ofGetElapsedTimeMillis()-startTime; if (isPlaying) { @@ -230,11 +249,11 @@ void song::draw(){ } } else melody.setVolume(1.0f); - notes.draw(&levels); + notes.drawFlakes(&levels); lyrics.draw(); } - ofDrawBitmapString(ofToString((float)songTime/1000.0f,3)+" "+ofToString(levels.getLevel(songTime))+" "+ofToString(notes.missedFlakes)+" of "+ofToString(levels.getLives(songTime)),10,ofGetHeight()-15); + ofDrawBitmapString(ofToString((float)songTime/1000.0f,1)+" "+ofToString(levels.getLevel(songTime))+" "+ofToString(notes.missedFlakes)+" of "+ofToString(levels.getLives(songTime)),10,ofGetHeight()-15); } void song::playerControl(int key){ notes.playerControl(key,keyThresh); diff --git a/vfg/src/music.h b/vfg/src/music.h index f20838f..aaec003 100755 --- a/vfg/src/music.h +++ b/vfg/src/music.h @@ -92,7 +92,7 @@ class lyricscore: public score { font.loadFont("verdana.ttf", 30, true, true); font.setLineHeight(34.0f); font.setLetterSpacing(1.035); - ypos=(int)(((float)ofGetHeight())*0.9f); //set lyric position + ypos=(int)(((float)ofGetHeight())*0.97f); //set lyric position fadeout=500; //ms } void load(string filename) { @@ -123,8 +123,10 @@ class musicscore: public score { public: musicscore(); void parseMidi(string filename); - void setTimeframe(int millis); - void draw(levelscore *levels); + void setTimeframe(int millis); + void setNowpoint(float pct); + void drawNotes(levelscore *levels); + void drawFlakes(levelscore *levels); void playerControl(int key,int threshold); void makeFlakes(int threshStart,int threshEnd); @@ -136,7 +138,8 @@ class musicscore: public score { map notes; map flakes; int timeframe; - ofImage flake; + ofImage flake; + float nowpoint; }; //--------------------------------------------------------------------------------------------------------------------------------------------- class song { @@ -148,6 +151,7 @@ class song { void setTimeframe(int millis); void setFlakeThresh(int tS,int tE); void setKeythresh(int millis); + void drawNotes(); void draw(); bool isPlaying; void playerControl(int key); diff --git a/vfg/src/testApp.cpp b/vfg/src/testApp.cpp index dc450a2..52f2a3a 100755 --- a/vfg/src/testApp.cpp +++ b/vfg/src/testApp.cpp @@ -2,9 +2,9 @@ //-------------------------------------------------------------- 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,6 +12,23 @@ 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(ofxSprite()); + 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); + + printf("blue clap: %i\n",penguins[0].getTotalFrames()); } void testApp::exit(){ @@ -20,18 +37,29 @@ void testApp::exit(){ //-------------------------------------------------------------- void testApp::update(){ + + for (int i=0;i<3;i++) { + penguins[i].update(); + } + + } //-------------------------------------------------------------- void testApp::draw(){ ofEnableAlphaBlending(); //ofBackground(0,0,0,0.1); - ofSetColor(0,0,0,50); + ofSetColor(0,0,0,100); ofRect(0,0,ofGetWidth(),ofGetHeight()); ofSetColor(255,255,255); + testsong->drawNotes(); + ofSetColor(255,255,255); + for (int i=0;i<3;i++) penguins[i].draw((i*300)+100,800); testsong->draw(); if (!testsong->isPlaying) ofDrawBitmapString("game over!", (ofGetWidth()/2)-25,(ofGetHeight()/2)-5); + + } //-------------------------------------------------------------- @@ -44,6 +72,7 @@ void testApp::keyPressed(int key){ case '2': case '3': testsong->playerControl(key-'0'); + penguins[key-'1'].play(); break; } diff --git a/vfg/src/testApp.h b/vfg/src/testApp.h index 0765b4f..8304e12 100755 --- a/vfg/src/testApp.h +++ b/vfg/src/testApp.h @@ -1,6 +1,7 @@ #pragma once #include "ofMain.h" +#include "ofxSprite.h" #include "music.h" /* @@ -36,7 +37,10 @@ keys - volume - control drawing of stars - game state changes 05112012 event suppression working? -overlap +overlap + + +character class- load sprites from xml- play behaviours- block animations when others are playing */ @@ -63,9 +67,11 @@ class testApp : public ofBaseApp{ void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); - + song *testsong; - + + vector penguins; + }; diff --git a/vfg/vfg.cbp b/vfg/vfg.cbp index ca92267..a0edd04 100755 --- a/vfg/vfg.cbp +++ b/vfg/vfg.cbp @@ -27,8 +27,8 @@