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
|
#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();
}
void trapdoor::checkUpdate(const vector<ofVec3f>& players) {
if ((ofGetElapsedTimef()-startTime)>5) start();
}
void trapdoor::draw() {
bindTexture(texture);
ofPushMatrix();
ofTranslate(position.x,0,position.y);
//for now size =40x40
ofScale(.2,.2,.2);
surround.draw();
ofPushMatrix();
ofTranslate(-90,0,0);
ofRotate(doorAngle,1,0,0);
lid.draw();
ofPopMatrix();
ofPushMatrix();
ofTranslate(90,0,0);
ofRotate(180,0,1,0);
ofRotate(doorAngle,1,0,0);
lid.draw();
ofPopMatrix();
ofPopMatrix();
unbindTexture(texture);
}
|