2007-09-16 22:24:02 +00:00
|
|
|
#ifndef ROOM_H_
|
|
|
|
#define ROOM_H_
|
|
|
|
|
|
|
|
#include "Polygon.h"
|
2007-12-14 02:47:03 +00:00
|
|
|
#include "LevelObject.h"
|
2008-02-13 21:06:01 +00:00
|
|
|
#include "VertexProvider.h"
|
|
|
|
#include "LevelVertex.h"
|
2007-09-16 22:24:02 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
2008-02-13 21:06:01 +00:00
|
|
|
class Room : public Polygon, public LevelObject, public VertexProvider {
|
2007-09-26 19:28:04 +00:00
|
|
|
private:
|
|
|
|
std::string name;
|
2007-10-30 20:07:00 +00:00
|
|
|
float height;
|
|
|
|
|
2007-09-26 19:28:04 +00:00
|
|
|
public:
|
2007-10-30 20:07:00 +00:00
|
|
|
Room() {height = 10;}
|
2007-12-05 22:02:03 +00:00
|
|
|
Room(std::string name) {this->name = name; height = 10;}
|
2007-09-26 19:28:04 +00:00
|
|
|
|
|
|
|
std::string &getName() {return name;}
|
|
|
|
const std::string &getName() const {return name;}
|
|
|
|
void setName(const std::string &name) {this->name = name;}
|
2007-10-30 20:07:00 +00:00
|
|
|
|
|
|
|
float getHeight() const {return height;}
|
|
|
|
void setHeight(float height) {this->height = height;}
|
2007-12-14 02:47:03 +00:00
|
|
|
|
2008-02-13 21:06:01 +00:00
|
|
|
virtual bool hit(const Vertex &v, float scale) const {return contains(v);}
|
2007-12-14 18:22:04 +00:00
|
|
|
virtual int getPriority() const {return 0;}
|
2007-12-14 02:47:03 +00:00
|
|
|
|
2008-02-13 21:06:01 +00:00
|
|
|
virtual std::vector<SharedPtr<LevelObject> > getChildren() {
|
|
|
|
std::vector<SharedPtr<LevelObject> > children;
|
|
|
|
|
|
|
|
for(size_t i = 0; i < size(); i++)
|
|
|
|
children.push_back(SharedPtr<LevelObject>(new LevelVertex(this, i)));
|
|
|
|
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
|
2007-12-14 02:47:03 +00:00
|
|
|
virtual const char* getType() const {
|
|
|
|
return "Room";
|
|
|
|
}
|
2008-01-13 16:41:01 +00:00
|
|
|
|
|
|
|
virtual void move(float x, float y) {
|
2008-02-09 12:21:00 +00:00
|
|
|
Vertex m(x, y);
|
|
|
|
|
|
|
|
for(iterator v = begin(); v != end(); v++)
|
|
|
|
*v += m;
|
2008-01-13 16:41:01 +00:00
|
|
|
}
|
2008-02-08 21:21:01 +00:00
|
|
|
|
|
|
|
virtual void rotate(float a) {
|
|
|
|
Vertex z = getCenter();
|
|
|
|
float s = sinf(a);
|
|
|
|
float c = cosf(a);
|
|
|
|
|
|
|
|
for(iterator v = begin(); v != end(); v++) {
|
|
|
|
*v -= z;
|
|
|
|
v->setLocation(c*v->getX() - s*v->getY(), c*v->getY() + s*v->getX());
|
|
|
|
*v += z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Vertex getCenter() const {
|
|
|
|
Vertex ret;
|
|
|
|
|
|
|
|
for(const_iterator v = begin(); v != end(); v++)
|
|
|
|
ret += *v;
|
|
|
|
|
|
|
|
return ret / size();
|
|
|
|
}
|
2008-02-13 21:06:01 +00:00
|
|
|
|
|
|
|
virtual const Vertex* getVertex(size_t id) const {
|
|
|
|
return &at(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual size_t getVertexCount() const {
|
|
|
|
return size();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void moveVertex(size_t id, float x, float y) {
|
|
|
|
at(id) += Vertex(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void rotateVertex(size_t id, float a) {
|
|
|
|
Vertex z = at(id);
|
|
|
|
float s = sinf(a);
|
|
|
|
float c = cosf(a);
|
|
|
|
|
|
|
|
for(iterator v = begin(); v != end(); v++) {
|
|
|
|
*v -= z;
|
|
|
|
v->setLocation(c*v->getX() - s*v->getY(), c*v->getY() + s*v->getX());
|
|
|
|
*v += z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 22:24:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /*ROOM_H_*/
|