diff options
Diffstat (limited to 'Portal.h')
-rw-r--r-- | Portal.h | 141 |
1 files changed, 0 insertions, 141 deletions
diff --git a/Portal.h b/Portal.h deleted file mode 100644 index 2208946..0000000 --- a/Portal.h +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef PORTAL_H_ -#define PORTAL_H_ - -#include "LevelObject.h" -#include "Polygon.h" -#include "VertexProvider.h" -#include "LevelVertex.h" -#include <math.h> - - -class Portal : public LevelObject, public VertexProvider { - private: - float width, height, thickness; - Vertex pos; - float orient; - - Vertex vertices[4]; - float s, c; - bool connected[4]; - - - void updateVertices() { - float x = width/2*c; - float y = width/2*s; - float ts = thickness/2*s; - float tc = thickness/2*c; - - vertices[0].setLocation(pos.getX()-x-ts, pos.getY()-y+tc); - vertices[1].setLocation(pos.getX()-x+ts, pos.getY()-y-tc); - vertices[2].setLocation(pos.getX()+x+ts, pos.getY()+y-tc); - vertices[3].setLocation(pos.getX()+x-ts, pos.getY()+y+tc); - } - - void updateOrient() { - s = sinf(orient); - c = cosf(orient); - - updateVertices(); - } - - Polygon createPolygon() const { - Polygon p; - - for(int i = 0; i < 4; i++) - p.push_back(vertices[i]); - - return p; - } - - public: - Portal(float width, float height, float thickness) { - this->width = width; - this->height = height; - this->thickness = thickness; - - orient = 0; - - for(int i = 0; i < 4; i++) { - connected[i] = false; - } - - updateOrient(); - } - - 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; updateVertices();} - - float getOrientation() const {return orient;} - void setOrientation(float orient) {this->orient = orient; updateOrient();} - - virtual std::vector<SharedPtr<LevelObject> > getChildren() { - std::vector<SharedPtr<LevelObject> > children; - - for(size_t i = 0; i < 4; i++) - children.push_back(SharedPtr<LevelObject>(new LevelVertex(this, i, this))); - - return children; - } - - 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); - updateVertices(); - } - - virtual void rotate(Vertex m, float a) { - orient = fmodf(orient+a, 2*M_PI); - - s = sinf(a); - c = cosf(a); - - pos -= m; - pos.setLocation(c*pos.getX() - s*pos.getY(), c*pos.getY() + s*pos.getX()); - pos += m; - - updateOrient(); - } - - virtual const Vertex* getVertex(size_t id) const { - return &vertices[id]; - } - - virtual size_t getVertexCount() const { - return 1; - } - - virtual bool canMove() const {return true;} - - virtual void moveVertex(size_t id, float x, float y) { - move(x, y); - } - - virtual bool canRotate() const {return true;} - - virtual void rotateVertex(size_t id, Vertex m, float a) { - rotate(m, a); - } - - virtual bool canConnectVertex(size_t id) const { - return !connected[id]; - } - - virtual size_t connectVertex(size_t id) { - connected[id] = true; - connected[(7-id)%4] = true; - - return (7-id)%4; - } -}; - -#endif /*PORTAL_H_*/ |