summaryrefslogtreecommitdiff
path: root/gaunt01
diff options
context:
space:
mode:
Diffstat (limited to 'gaunt01')
-rw-r--r--gaunt01/gaunt01.cbp6
-rw-r--r--gaunt01/src/bird.cpp2
-rw-r--r--gaunt01/src/bird.h4
-rw-r--r--gaunt01/src/player.cpp41
-rw-r--r--gaunt01/src/player.h20
-rw-r--r--gaunt01/src/testApp.cpp52
-rw-r--r--gaunt01/src/testApp.h2
-rw-r--r--gaunt01/src/trapdoor.cpp108
-rw-r--r--gaunt01/src/trapdoor.h10
9 files changed, 208 insertions, 37 deletions
diff --git a/gaunt01/gaunt01.cbp b/gaunt01/gaunt01.cbp
index c474946..88aa223 100644
--- a/gaunt01/gaunt01.cbp
+++ b/gaunt01/gaunt01.cbp
@@ -111,6 +111,12 @@
<Unit filename="src/normBindTexture.h">
<Option virtualFolder="src/" />
</Unit>
+ <Unit filename="src/player.cpp">
+ <Option virtualFolder="src/" />
+ </Unit>
+ <Unit filename="src/player.h">
+ <Option virtualFolder="src/" />
+ </Unit>
<Unit filename="src/testApp.cpp">
<Option virtualFolder="src/" />
</Unit>
diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp
index d557d82..69549e0 100644
--- a/gaunt01/src/bird.cpp
+++ b/gaunt01/src/bird.cpp
@@ -68,7 +68,7 @@ void bird::drawShadow(){
ofRotate(90,0,0,1);
ofRotate(90,-1,0,0);
ofRotate(heading+90,0,1,0);
- ofSetHexColor(0x000000);
+ ofSetHexColor(0x303030);
ofTranslate(0,(-ofGetHeight()/4)+5,0);
ofScale(.15,0,.15);
model.drawAnimated();
diff --git a/gaunt01/src/bird.h b/gaunt01/src/bird.h
index a4ad1f4..abcd66f 100644
--- a/gaunt01/src/bird.h
+++ b/gaunt01/src/bird.h
@@ -22,6 +22,10 @@
-build basic of time/speed/heading update/draw
-basic anim cycle
+
+
+
+ MAKING THE BIRD CHASE THE PLAYERS
*/
diff --git a/gaunt01/src/player.cpp b/gaunt01/src/player.cpp
index 39c91ac..0ffdcda 100644
--- a/gaunt01/src/player.cpp
+++ b/gaunt01/src/player.cpp
@@ -2,7 +2,7 @@
player::player()
{
- //ctor
+ isCaught=false;
}
player::~player()
@@ -10,12 +10,22 @@ player::~player()
//dtor
}
-void player::setPosition(ofVec3f _pos) {
- position.set(_pos);
+void player::setWorldPosition(ofVec3f _pos) {
+ worldPosition.set(_pos);
}
+void player::setScreenPosition(ofVec2f _pos) {
+ screenPosition.set(_pos);
+}
+
-ofVec3f player::getPosition() {
- return position;
+ofVec3f player::getWorldPosition() {
+ return worldPosition;
+}
+ofVec2f player::getScreenPosition() {
+ return screenPosition;
+}
+ofVec3f player::getCaughtPos(){
+ return caughtPos;
}
void player::update(ofxCvBlob blob) {
@@ -28,5 +38,24 @@ void player::update(ofxCvBlob blob) {
}
void player::draw(){
- billboard.draw();
+ ofPushMatrix();
+ if (isCaught) {
+ ofTranslate(caughtPos-screenPosition);
+ ofTranslate(catchPos);
+ ofTranslate(screenPosition);
+ ofScale(catchScale.x,catchScale.y,catchScale.z);
+ ofTranslate(-screenPosition);
+ }
+ billboard.draw();
+ ofPopMatrix();
+}
+
+void player::caught(){
+ isCaught=true;
+ caughtPos=screenPosition;
+}
+
+void player::setCatchTransform(ofVec3f _catchPos,ofVec3f _catchScale){
+ catchPos=_catchPos;
+ catchScale=_catchScale;
} \ No newline at end of file
diff --git a/gaunt01/src/player.h b/gaunt01/src/player.h
index e89c5b8..9167237 100644
--- a/gaunt01/src/player.h
+++ b/gaunt01/src/player.h
@@ -9,16 +9,28 @@ class player : public ofTessellator
public:
player();
virtual ~player();
- void setPosition(ofVec3f _pos);
- ofVec3f getPosition();
+ void setScreenPosition(ofVec2f _pos);
+ void setWorldPosition(ofVec3f _pos);
+ ofVec3f getWorldPosition();
+ ofVec2f getScreenPosition();
+ ofVec3f getCaughtPos();
void update(ofxCvBlob blob);
void draw();
+ void caught();
+ bool isCaught;
+ void carried(ofVec3f _posOffset);
+ void setCatchTransform(ofVec3f _catchPos,ofVec3f _catchScale);
protected:
private:
ofMesh billboard;
ofPolyline outline;
- ofVec3f position;
-
+ ofVec3f worldPosition;
+ ofVec2f screenPosition;
+ ofVec2f caughtPos;
+ ofVec3f catchPos;
+ ofVec3f catchScale;
+ ofVec2f posOffset;
+
};
#endif // PLAYER_H
diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp
index 5f531a6..9e2a574 100644
--- a/gaunt01/src/testApp.cpp
+++ b/gaunt01/src/testApp.cpp
@@ -91,6 +91,9 @@ void testApp::setup(){
bgnum=1000;
firstframe=true;
+
+ light.setPosition(ofGetWidth(),0,ofGetHeight());
+ light.enable();
}
@@ -254,11 +257,13 @@ void testApp::update(){
ray=projector.castPixel(blobBase.x,blobBase.y);
bool hit = plane.intersect(ray,pp);
rp=pp.getRotated(cam_angle,ofVec3f(-1,0,0));
- players[blobsManager.blobs.at(i).id].setPosition(rp);
+ players[blobsManager.blobs.at(i).id].setScreenPosition(blobBase);
+ players[blobsManager.blobs.at(i).id].setWorldPosition(ofVec3f(rp.x,rp.y,0));
players[blobsManager.blobs.at(i).id].update(blob); //create model
}
}
if (trapDoor.checkUpdate(players)) updatePlane();
+ Bird.update(players);
}
//--------------------------------------------------------------
@@ -280,13 +285,22 @@ void testApp::draw(){
bindTexture(bgImg);
ground.draw();
unbindTexture(bgImg);
-
- Bird.update(players);
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);
@@ -324,12 +338,14 @@ void testApp::draw(){
-
+ glEnable(GL_LIGHTING);
ofPushMatrix();
ofRotate(cam_angle,1,0,0);
Bird.draw();
ofPopMatrix();
+
+ glDisable(GL_LIGHTING);
break;
@@ -364,6 +380,7 @@ void testApp::draw(){
ofPushMatrix();
ofRotate(cam_angle,1,0,0);
trapDoor.draw();
+ trapDoor.drawDebug();
ofPopMatrix();
@@ -378,7 +395,7 @@ void testApp::draw(){
ofDrawBitmapString(numStr, blob.boundingRect.x, blob.boundingRect.y);
ofPushMatrix();
ofRotate(cam_angle,1,0,0);
- ofTranslate(players[blobsManager.blobs.at(i).id].getPosition());
+ ofTranslate(players[blobsManager.blobs.at(i).id].getWorldPosition());
ofBox(0,-10,0,20);
//TODO get this into plane axis
ofPopMatrix();
@@ -480,6 +497,31 @@ void testApp::keyPressed(int key){
Bird.currentseq="attack";
}
break;
+
+ case 'y':
+ light.setPosition(light.getX(),light.getY()-100,light.getZ());
+ printf("light at %f,%f,%f\n",light.getX(),light.getY(),light.getZ());
+ break;
+ case 'n':
+ light.setPosition(light.getX(),light.getY()+100,light.getZ());
+ printf("light at %f,%f,%f\n",light.getX(),light.getY(),light.getZ());
+ break;
+ case 'g':
+ light.setPosition(light.getX()-100,light.getY(),light.getZ());
+ printf("light at %f,%f,%f\n",light.getX(),light.getY(),light.getZ());
+ break;
+ case 'j':
+ light.setPosition(light.getX()+100,light.getY(),light.getZ());
+ printf("light at %f,%f,%f\n",light.getX(),light.getY(),light.getZ());
+ break;
+ case 'u':
+ light.setPosition(light.getX(),light.getY(),light.getZ()+100);
+ printf("light at %f,%f,%f\n",light.getX(),light.getY(),light.getZ());
+ break;
+ case 'b':
+ light.setPosition(light.getX(),light.getY(),light.getZ()-100);
+ printf("light at %f,%f,%f\n",light.getX(),light.getY(),light.getZ());
+ break;
}
}
diff --git a/gaunt01/src/testApp.h b/gaunt01/src/testApp.h
index 7ef1e3a..f2a35c0 100644
--- a/gaunt01/src/testApp.h
+++ b/gaunt01/src/testApp.h
@@ -91,6 +91,8 @@ class testApp : public ofBaseApp{
bool firstframe; //for background removal
float bgnum;
+
+ ofLight light;
};
diff --git a/gaunt01/src/trapdoor.cpp b/gaunt01/src/trapdoor.cpp
index 29b6147..46151c1 100644
--- a/gaunt01/src/trapdoor.cpp
+++ b/gaunt01/src/trapdoor.cpp
@@ -13,11 +13,21 @@ trapdoor::trapdoor(ofVec2f _boundTR,ofVec2f _boundBR,ofVec2f _doorSize)
sounds[1].loadSound("creeky door short2.wav");
sounds[2].loadSound("creeky door short3.wav");
sounds[3].loadSound("voice falling down hole.wav");
+
+ splashFrames=new ofImage[3];
+ splashFrames[0].loadImage("Drops_1.tga");
+ splashFrames[1].loadImage("Drops_2.tga");
+ splashFrames[2].loadImage("Drops_3.tga");
+
+ for (int i=0;i<3;i++) {
+ splashFrames[i].setAnchorPercent(0.5,0.5);
+ }
boundTR=_boundTR;
boundBR=_boundBR;
- size=_doorSize; start();
+ size=_doorSize;
+ start();
}
trapdoor::~trapdoor() {
@@ -37,7 +47,10 @@ void trapdoor::start(){
}
void trapdoor::startPos(ofVec2f pos){
+ caught.clear();
+ caughtTime.clear();
position=pos;
+ setBoundingRect(pos.x, pos.y,size.x,size.y);
startTime=ofGetElapsedTimef();
doorAngle=0;
doorSpeed=0;
@@ -63,7 +76,8 @@ ofRectangle trapdoor::getBoundingRect(){
return boundingRect;
}
ofRectangle trapdoor::getInnerRect() {
- return ofRectangle(boundingRect.x+(boundingRect.width/4),boundingRect.y+(boundingRect.height/4),boundingRect.width/2,boundingRect.height/2);
+ //return ofRectangle(boundingRect.x-(boundingRect.width/4),boundingRect.y-(boundingRect.height/4),boundingRect.width/2,boundingRect.height/2);
+ return ofRectangle(position.x-(size.x/3),position.y-(size.y/3),(2*size.x)/3,(2*size.y)/3);
}
void trapdoor::trigger() {
triggeredTime=ofGetElapsedTimef();
@@ -79,11 +93,30 @@ ofVec2f trapdoor::bounds2UV(ofVec2f point){
}
float trapdoor::getFalldist(){
- if (triggerTime>0) return ((ofGetElapsedTimef()-triggeredTime)*.01);
+ if (triggeredTime>0) return ((ofGetElapsedTimef()-triggeredTime)*.01);
else return 0;
}
-bool trapdoor::checkUpdate(const map<int,player>& players) {
+bool trapdoor::checkUpdate(map<int,player>& players) {
+ map<int,player>::iterator it;
+ for (it=players.begin();it!=players.end();it++) {
+ ofVec3f p=it->second.getWorldPosition();
+ ofRectangle r=getInnerRect();
+ if (getInnerRect().inside(p.x,p.y)&&!it->second.isCaught) {
+ trigger();
+ it->second.caught();
+ printf("caught!\n");
+ caught.push_back(&(it->second));
+ caughtTime.push_back(ofGetElapsedTimef());
+ sounds[3].play(); //falling down hole
+ }
+ }
+ for (int i=0;i<caught.size();i++) {
+ float sc=pow(0.2,ofGetElapsedTimef()-caughtTime[i]);
+ caught[i]->setCatchTransform(ofVec3f(0,0,0),ofVec3f(sc,sc,sc));
+ }
+
+
float segTime=(ofGetElapsedTimef()-startTime);
if (segTime>10) {
doorSpeed=(doorSpeed+((cos(doorAngle*0.0174532925)/ofGetFrameRate())*50))*0.95;
@@ -102,30 +135,67 @@ bool trapdoor::checkUpdate(const map<int,player>& players) {
else return false;
}
+void trapdoor::drawDebug() {
+ ofSetHexColor(0xff0000);
+ glBegin(GL_LINES);
+ glVertex3f(getInnerRect().x,getInnerRect().y,0);
+ glVertex3f(getInnerRect().x+(getInnerRect().width),getInnerRect().y,0);
+ glVertex3f(getInnerRect().x+(getInnerRect().width),getInnerRect().y,0);
+ glVertex3f(getInnerRect().x+(getInnerRect().width),getInnerRect().y+(getInnerRect().height),0);
+ glVertex3f(getInnerRect().x+(getInnerRect().width),getInnerRect().y+(getInnerRect().height),0);
+ glVertex3f(getInnerRect().x,getInnerRect().y+(getInnerRect().height),0);
+ glVertex3f(getInnerRect().x,getInnerRect().y+(getInnerRect().height),0);
+ glVertex3f(getInnerRect().x,getInnerRect().y,0);
+
+ glEnd();
+ ofSetHexColor(0x0000ff);
+ glBegin(GL_LINES);
+ for (int i=0;i<caught.size();i++) {
+ glVertex3f(caught[i]->getCaughtPos().x,caught[i]->getCaughtPos().y,0);
+ glVertex3f(caught[i]->getScreenPosition().x,caught[i]->getScreenPosition().y,0);
+ }
+ glEnd();
+}
+
void trapdoor::draw() {
glEnable(GL_DEPTH_TEST);
ofSetHexColor(0xffffff);
bindTexture(texture);
ofPushMatrix();
- //ofRotate(90,-1,0,0);
ofTranslate(ofVec3f(position.x,position.y,0));
- //ofRotate(180,-1,0,0);
- //for now size =40x40
- ofRotate(90,-1,0,0);
- ofScale(.15,.15,.15);
- surround.draw();
- ofPushMatrix();
- ofTranslate(90,0,0);
- ofRotate(doorAngle,0,0,-1);
- lid.draw();
- ofPopMatrix();
ofPushMatrix();
- ofTranslate(-90,0,0);
- ofRotate(180,0,1,0);
- ofRotate(doorAngle,0,0,-1);
- lid.draw();
+ ofRotate(90,-1,0,0);
+ ofScale(.15,.15,.15);
+ surround.draw();
+ ofPushMatrix();
+ ofTranslate(90,0,0);
+ ofRotate(doorAngle,0,0,-1);
+ lid.draw();
+ ofPopMatrix();
+ ofPushMatrix();
+ ofTranslate(-90,0,0);
+ ofRotate(180,0,1,0);
+ ofRotate(doorAngle,0,0,-1);
+ lid.draw();
+ ofPopMatrix();
ofPopMatrix();
ofPopMatrix();
unbindTexture(texture);
glDisable(GL_DEPTH_TEST);
}
+void trapdoor::drawSplash(float angle) {
+ for (int i=0;i<caught.size();i++) {
+ float splashTime = (ofGetElapsedTimef()-caughtTime[i]);
+ if (splashTime>0.3) {
+ ofPushMatrix();
+ ofTranslate(ofVec3f(position.x,position.y,0));
+ ofRotate(angle,-1,0,0);
+ ofScale(0.3,0.3,0.3);
+ if (splashTime<0.5) splashFrames[0].draw(0,0,0);
+ else if (splashTime<0.7) splashFrames[1].draw(0,0,0);
+ else if (splashTime<0.9) splashFrames[2].draw(0,0,0);
+ ofPopMatrix();
+ }
+ }
+
+} \ No newline at end of file
diff --git a/gaunt01/src/trapdoor.h b/gaunt01/src/trapdoor.h
index d307c2d..6f8b509 100644
--- a/gaunt01/src/trapdoor.h
+++ b/gaunt01/src/trapdoor.h
@@ -21,8 +21,10 @@ class trapdoor
trapdoor(ofVec2f _boundTR=ofVec2f(0,0),ofVec2f _boundBR=ofVec2f(0,0),ofVec2f _doorSize=ofVec2f(10,10));
virtual ~trapdoor();
- bool checkUpdate(const map<int,player>& players);
+ bool checkUpdate(map<int,player>& players);
void draw();
+ void drawSplash(float angle);
+ void drawDebug();
void start();
void startPos(ofVec2f pos);
@@ -36,7 +38,8 @@ class trapdoor
float getoffset();
float getFalldist();
-
+
+ ofImage* splashFrames; //temp public
protected:
private:
morphmesh surround;
@@ -59,10 +62,13 @@ class trapdoor
ofImage texture;
ofSoundPlayer* sounds;
+
bool opening;
float triggeredTime;
+ vector<player*> caught;
+ vector<float> caughtTime;
};