summaryrefslogtreecommitdiffstats
path: root/Room.h
blob: 1cac5d9a6acfcccfb355cef85cbaf371b8c087d8 (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
#ifndef ROOM_H_
#define ROOM_H_

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


class Room : public Polygon, public LevelObject {
  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) const {return contains(v);}
    virtual int getPriority() const {return 0;}
    
    virtual const char* getType() const {
      return "Room";
    }
    
    virtual void move(float x, float y) {
      for(iterator v = begin(); v != end(); v++) {
        v->setX(v->getX()+x);
        v->setY(v->getY()+y);
      }
    }
    
    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();
    }
};

#endif /*ROOM_H_*/