blob: 3df424703916c7ba6f83b4e49e9924c44a9b1992 (
plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#ifndef PORTAL_H_
#define PORTAL_H_
#include "LevelObject.h"
#include "Polygon.h"
#include <math.h>
class Portal : public LevelObject {
private:
float width, height, thickness;
Vertex pos;
float orient;
Polygon createPolygon() const {
Polygon p;
float s = sinf(orient);
float c = cosf(orient);
float x = width/2*c;
float y = width/2*s;
float ts = thickness/2*s;
float tc = thickness/2*c;
p.push_back(Vertex(pos.getX()-x-ts, pos.getY()-y+tc));
p.push_back(Vertex(pos.getX()-x+ts, pos.getY()-y-tc));
p.push_back(Vertex(pos.getX()+x+ts, pos.getY()+y-tc));
p.push_back(Vertex(pos.getX()+x-ts, pos.getY()+y+tc));
return p;
}
public:
Portal(float width, float height, float thickness) {
this->width = width;
this->height = height;
this->thickness = thickness;
orient = 0;
}
float getWidth() const {return width;}
float getHeight() const {return height;}
float getThickness() const {return thickness;}
const Vertex& getPosition() const {return pos;}
void setPosition(Vertex v) {pos = v;}
float getOrientation() const {return orient;}
void setOrientation(float orient) {this->orient = orient;}
virtual bool hit(const Vertex &v) const {return createPolygon().contains(v);}
virtual int getPriority() const {return 1;}
virtual const char* getType() const {
return "Portal";
}
virtual void move(float x, float y) {
pos += Vertex(x, y);
}
virtual void rotate(float a) {
orient = fmodf(orient+a, 2*M_PI);
}
virtual Vertex getCenter() const {
return pos;
}
};
#endif /*PORTAL_H_*/
|