#include "trapdoor.h" trapdoor::trapdoor(ofRectangle _boundingRect,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"); boundingRect=_boundingRect; doorSize=_doorSize; start(); } trapdoor::~trapdoor() {} void trapdoor::start(){ position=ofVec2f(boundingRect.x+ofRandom(boundingRect.width),boundingRect.y+ofRandom(boundingRect.height)); startTime=ofGetElapsedTimef(); doorAngle=0; doorSpeed=0; } void trapdoor::checkUpdate(const vector& players) { float segTime=(ofGetElapsedTimef()-startTime); if (segTime>5) start(); if (segTime>3) { doorSpeed=(doorSpeed+((cos(doorAngle*0.0174532925)/ofGetFrameRate())*100))*0.95; doorAngle+=doorSpeed; } } void trapdoor::draw() { glEnable(GL_DEPTH_TEST); bindTexture(texture); ofPushMatrix(); ofRotate(90,-1,0,0); ofTranslate(position.x,0,position.y); ofRotate(180,-1,0,0); //for now size =40x40 ofScale(.1,.1,.1); 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(); unbindTexture(texture); glDisable(GL_DEPTH_TEST); }