summaryrefslogtreecommitdiff
path: root/gaunt01/src/trapdoor.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-04-18 17:40:55 +0100
committerTim Redfern <tim@eclectronics.org>2012-04-18 17:40:55 +0100
commitc4fc08cc7238dfa310ed56e65a24df22c6bbb625 (patch)
tree893cbeb6b5e135ae4e70b6754ba349bdf70021bc /gaunt01/src/trapdoor.cpp
parent3411448d999ce36b5fcb14ca4829435308cbd70a (diff)
trapdoor splashes etc
Diffstat (limited to 'gaunt01/src/trapdoor.cpp')
-rw-r--r--gaunt01/src/trapdoor.cpp108
1 files changed, 89 insertions, 19 deletions
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