summaryrefslogtreecommitdiffstats
path: root/Room.h
blob: c2d96d9b65111285cf52040ffec9dd670ff04f2c (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef ROOM_H_
#define ROOM_H_

#include "Polygon.h"
#include "LevelObject.h"
#include "VertexProvider.h"
#include "LevelVertex.h"
#include <string>


class Room : public Polygon, public LevelObject, public VertexProvider {
  private:
    std::string name;
    float height;
    
  public:
    Room() {height = 10;}
    Room(std::string name) {this->name = name; height = 10;}
    
    std::string &getName() {return name;}
    const std::string &getName() const {return name;}
    void setName(const std::string &name) {this->name = name;}
    
    float getHeight() const {return height;}
    void setHeight(float height) {this->height = height;}
    
    virtual bool hit(const Vertex &v, float scale) const {return contains(v);}
    virtual int getPriority() const {return 0;}
    
    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;
    }
    
    virtual const char* getType() const {
      return "Room";
    }
    
    virtual void move(float x, float y) {
      Vertex m(x, y);
      
      for(iterator v = begin(); v != end(); v++)
        *v += m;
    }
    
    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();
    }
    
    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;
      }
    }
    
};

#endif /*ROOM_H_*/