summaryrefslogtreecommitdiff
path: root/gaunt01/src/trapdoor.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-04-03 23:06:21 +0100
committerTim Redfern <tim@eclectronics.org>2012-04-03 23:06:21 +0100
commit0c2a97dcc0fb370938dc0d2d3a27053c2c9cb31e (patch)
tree1678420c09caa3ef73b4c45195b7da35cf31a363 /gaunt01/src/trapdoor.cpp
parent0363ee4f188c735a43c6624a2b10a191f74c3029 (diff)
blobs tesselated into textured polys
Diffstat (limited to 'gaunt01/src/trapdoor.cpp')
-rw-r--r--gaunt01/src/trapdoor.cpp71
1 files changed, 50 insertions, 21 deletions
diff --git a/gaunt01/src/trapdoor.cpp b/gaunt01/src/trapdoor.cpp
index ce06b4a..d1f436e 100644
--- a/gaunt01/src/trapdoor.cpp
+++ b/gaunt01/src/trapdoor.cpp
@@ -5,46 +5,64 @@ trapdoor::trapdoor(ofVec2f _boundTR,ofVec2f _boundBR,ofVec2f _doorSize)
surround=morphmesh("trapdoor-surround.xml");
lid=morphmesh("trapdoor-lid.xml");
if (!surround.isLoaded()||!lid.isLoaded()) printf("problem loading trap door mesh.\n");
-
+
texture.loadImage("TextureTrapdoor.jpg");
-
+
+ sounds=new ofSoundPlayer[4];
+ sounds[0].loadSound("creeky door short1.wav");
+ sounds[1].loadSound("creeky door short2.wav");
+ sounds[2].loadSound("creeky door short3.wav");
+ sounds[3].loadSound("voice falling down hole.wav");
+
boundTR=_boundTR;
boundBR=_boundBR;
-
- printf("trapdoor bounds: %f,%f - %f,%f\n",boundTR.x,boundTR.y,boundBR.x,boundBR.y);
-
+
size=_doorSize;
start();
}
-trapdoor::~trapdoor() {}
-
+trapdoor::~trapdoor() {
+ }
+
void trapdoor::start(){
//place trapdoor within bounds
float u=ofRandom(-0.9,0.9); //(-1 to 1)
float v=ofRandom(0.05,0.95);
float mx=ofGetWidth()/2;
-
+
float x=mx+((boundTR.x-mx)*u*(1-v))+((boundBR.x-mx)*u*v);
float y=boundTR.y+((boundBR.y-boundTR.y)*v);
- printf("new trapdoor: %f,%f\n",x,y);
- position=ofVec2f(x,y);
+ startPos(ofVec2f(x,y));
+}
+
+void trapdoor::startPos(ofVec2f pos){
+ position=pos;
startTime=ofGetElapsedTimef();
doorAngle=0;
doorSpeed=0;
+ opening=false;
+ //for (int i=0;i<4;i++) sounds[i].stop();
+
}
vector<ofVec2f> trapdoor::getCorners(){
vector<ofVec2f> corners;
- corners.push_back(ofVec2f(-size.x/2,-size.y/2));
- corners.push_back(ofVec2f(size.x/2,-size.y/2));
- corners.push_back(ofVec2f(size.x/2,size.y/2));
- corners.push_back(ofVec2f(-size.x/2,size.y/2));
+ corners.push_back(ofVec2f(position.x-(size.x/2),position.y-(size.y/2)));
+ corners.push_back(ofVec2f(position.x+(size.x/2),position.y-(size.y/2)));
+ corners.push_back(ofVec2f(position.x+(size.x/2),position.y+(size.y/2)));
+ corners.push_back(ofVec2f(position.x-(size.x/2),position.y+(size.y/2)));
return corners;
}
+void trapdoor::setBoundingRect(float x,float y, float width,float height){
+ boundingRect=ofRectangle(x,y,width,height);
+}
+ofRectangle trapdoor::getBoundingRect(){
+ return boundingRect;
+}
+
ofVec2f trapdoor::bounds2UV(ofVec2f point){
//returns the 0-1 UV coords of a point on the ground plane relative to its bounds.
float v=(point.y-boundTR.y)/(boundBR.y-boundTR.y);
@@ -52,26 +70,37 @@ ofVec2f trapdoor::bounds2UV(ofVec2f point){
float u=((point.x-mx)/(((boundTR.x-mx)*(1-v))+((boundBR.x-mx)*v)))+0.5;
return ofVec2f(u,v);
}
-
-void trapdoor::checkUpdate(const vector<ofVec3f>& players) {
+
+bool trapdoor::checkUpdate(const vector<ofVec3f>& players) {
float segTime=(ofGetElapsedTimef()-startTime);
- if (segTime>5) start();
if (segTime>3) {
doorSpeed=(doorSpeed+((cos(doorAngle*0.0174532925)/ofGetFrameRate())*50))*0.95;
doorAngle-=doorSpeed;
+ if (!opening) {
+ int whichsound=(int)ofRandom(2.9999999);
+ sounds[whichsound].play();
+ //sound.play();
+ opening=true;
+ }
+ }
+ if (segTime>6) {
+ start();
+ return true;
}
+ else return false;
}
-
+
void trapdoor::draw() {
glEnable(GL_DEPTH_TEST);
ofSetHexColor(0xffffff);
bindTexture(texture);
ofPushMatrix();
- ofRotate(90,-1,0,0);
- ofTranslate(ofVec3f(position.x,0,position.y));
+ //ofRotate(90,-1,0,0);
+ ofTranslate(ofVec3f(position.x,position.y,0));
//ofRotate(180,-1,0,0);
//for now size =40x40
- ofScale(.1,.1,.1);
+ ofRotate(90,-1,0,0);
+ ofScale(.15,.15,.15);
surround.draw();
ofPushMatrix();
ofTranslate(90,0,0);