diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-04-19 12:01:48 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-04-19 12:01:48 +0100 |
| commit | e64e431b123da3afd0658375f91f50ed00910f67 (patch) | |
| tree | 2f00cb9b788d709f6c319ee43d336fe1a75d2357 /gaunt01/src/testApp.cpp | |
| parent | 98437cad0a3a59245e5fe772d4e310de4228757a (diff) | |
billboards etc
Diffstat (limited to 'gaunt01/src/testApp.cpp')
| -rw-r--r-- | gaunt01/src/testApp.cpp | 198 |
1 files changed, 132 insertions, 66 deletions
diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index a78a690..58505b6 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -8,10 +8,6 @@ Can use a floating point image or array to accumulate the screen and generate av Is this too much work for every frame? Should it be put in a seperate thread? - - - - */ void testApp::setup(){ @@ -35,15 +31,7 @@ void testApp::setup(){ useCamera=false; vidPlayer.play(); } -
-/* - colorImg.allocate(640,480); - colorImg.setUseTexture(true); - grayImage.allocate(640,480); - grayBg.allocate(640,480); - grayDiff.allocate(640,480);
- */ - + accumImg.allocate(640,480); bgImg.allocate(640,480); @@ -54,11 +42,7 @@ void testApp::setup(){ grayImage.allocate(640,480); grayBg.allocate(640,480); - grayDiff.allocate(ofGetWidth(),ofGetHeight());
-
-
- - + blobsManager.normalizePercentage = 0.7; blobsManager.giveLowestPossibleIDs = false; blobsManager.maxUndetectedTime = 500; @@ -90,16 +74,36 @@ void testApp::setup(){ mode=PLAY; - drawStats=false; - - bgnum=1000; - firstframe=true; - - light.setPosition(ofGetWidth(),0,ofGetHeight()); - light.enable(); - - drawingborder=false; + drawStats=false; + + bgnum=1000; + firstframe=true; + + light.setPosition(ofGetWidth(),0,ofGetHeight()); + light.enable(); + + drawingborder=false; + billboards=new ofImage[4]; + billboards[0].loadImage("GUI_title.png"); + billboards[1].loadImage("GUI_nzsLogo.png"); + billboards[2].loadImage("GUI_objective.png"); + billboards[3].loadImage("GUI_gotya.png"); + + for (int i=0;i<4;i++) { + billboards[i].setAnchorPercent(0.5,0.5); + } + scaleFactor=ofVec2f(ofGetWidth()/1280.0f,ofGetHeight()/768.0f); + + gameState=TITLES; + + segTimes[TITLES]=5.0; + segTimes[CREDIT]=3.0; + segTimes[EXPLAIN]=6.0; + segTimes[PLAYING]=60.0; + segTimes[GOTCHA]=2.0; + + gameStart=ofGetElapsedTimef(); } ofVec2f testApp::screen2plane(ofVec2f screenpos){ @@ -261,6 +265,8 @@ void testApp::update(){ bLearnBakground = false; } */ + grayDiff.clear(); + grayDiff.allocate(640,480); // take the abs value of the difference between background and incoming and then threshold: grayDiff.absDiff(bgImg, grayImage); @@ -310,55 +316,115 @@ void testApp::update(){ //-------------------------------------------------------------- void testApp::draw(){ + glDisable(GL_LIGHTING); ofBackground(0,0,0); - cam.begin(); - + cam.begin(); glDisable(GL_DEPTH_TEST); - ofSetHexColor(0xffffff); - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - trapDoor.draw(); - ofPopMatrix(); + glDisable(GL_BLEND); - ofSetHexColor(0xffffff); - bindTexture(bgImg); - ground.draw(); - unbindTexture(bgImg); + if (gameState<PLAYING) colorImg.draw(0,0,ofGetWidth(),ofGetHeight()); + + else { + ofSetHexColor(0xffffff); + ofPushMatrix(); + ofRotate(cam_angle,1,0,0); + trapDoor.draw(); + ofPopMatrix(); + + ofSetHexColor(0xffffff); + bindTexture(bgImg); + ground.draw(); + unbindTexture(bgImg); - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - Bird.drawShadow(); - ofPopMatrix(); + ofPushMatrix(); + ofRotate(cam_angle,1,0,0); + Bird.drawShadow(); + ofPopMatrix(); - glDisable(GL_DEPTH_TEST); - ofSetHexColor(0xffffff); - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - trapDoor.drawSplash(cam_angle); - //trapDoor.splashFrames[0].draw(ofGetWidth()/2,ofGetHeight()/2); - glDisable(GL_BLEND); - ofPopMatrix(); + glDisable(GL_DEPTH_TEST); + ofSetHexColor(0xffffff); + ofPushMatrix(); + ofRotate(cam_angle,1,0,0); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + trapDoor.drawSplash(cam_angle); + //trapDoor.splashFrames[0].draw(ofGetWidth()/2,ofGetHeight()/2); + glDisable(GL_BLEND); + ofPopMatrix(); + + glDisable(GL_DEPTH_TEST); + ofSetHexColor(0xffffff); + colorImg.getTextureReference().bind(); + map<int,player>::iterator it; + for(int i=0;i<blobsManager.blobs.size();i++){ + if(players[blobsManager.blobs.at(i).id].active) players[blobsManager.blobs.at(i).id].draw(); + } + colorImg.getTextureReference().unbind(); - glDisable(GL_DEPTH_TEST); - ofSetHexColor(0xffffff); - colorImg.getTextureReference().bind(); - map<int,player>::iterator it; - for(int i=0;i<blobsManager.blobs.size();i++){ - if(players[blobsManager.blobs.at(i).id].active) players[blobsManager.blobs.at(i).id].draw(); - } - colorImg.getTextureReference().unbind(); + glEnable(GL_LIGHTING); - glEnable(GL_LIGHTING); + ofPushMatrix(); + ofRotate(cam_angle,1,0,0); + Bird.draw(); + ofPopMatrix(); + + glDisable(GL_LIGHTING); + } - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - Bird.draw(); - ofPopMatrix(); + float gameTime=ofGetElapsedTimef()-gameStart; + + switch(gameState) { + case TITLES: + case CREDIT: + case EXPLAIN: + if (gameTime>segTimes[gameState]) { + gameState++; + gameStart=ofGetElapsedTimef(); + } + break; + case PLAYING: + if (gameTime>segTimes[gameState]) { + gameState=TITLES; + gameStart=ofGetElapsedTimef(); + } + break; + } + + float segElapsed=gameTime/segTimes[gameState]; + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + switch(gameState) { + case TITLES: + billboards[0].draw(ofGetWidth()/6 + ,scaleFactor.y*((-billboards[0].height/2)+(billboards[0].height*sin(segElapsed*PI))) + ,billboards[0].width*scaleFactor.x + ,billboards[0].height*scaleFactor.y); + break; + case CREDIT: + billboards[1].draw(ofGetWidth()/6 + ,ofGetHeight()+(scaleFactor.y*((billboards[1].height/2)-(billboards[1].height*sin(segElapsed*PI)))) + ,billboards[1].width*scaleFactor.x + ,billboards[1].height*scaleFactor.y); + break; + case EXPLAIN: + billboards[2].draw(ofGetWidth()/2 + ,scaleFactor.y*((-billboards[2].height/2)+(billboards[2].height*sin(segElapsed*PI))) + ,billboards[2].width*scaleFactor.x + ,billboards[2].height*scaleFactor.y); + break; + case PLAYING: + break; + case GOTCHA: + billboards[3].draw(ofGetWidth()/2 + ,scaleFactor.y*((-billboards[2].height/2)+(billboards[3].height*sin(segElapsed*PI))) + ,billboards[3].width*scaleFactor.x + ,billboards[3].height*scaleFactor.y); + break; + } + glDisable(GL_BLEND); - glDisable(GL_LIGHTING); switch(mode) { case PLAY: |
