1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#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<ofVec3f>& 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);
}
|