YAPOG  0.0.1
Yet Another Pokemon Online Game
Tile.cpp
Go to the documentation of this file.
3 
4 namespace yap
5 {
6  const UInt32 Tile::DEFAULT_SIZE = 32;
7  const bool Tile::DEFAULT_VISIBLE_STATE = true;
8  const sf::Color Tile::DEFAULT_COLOR = sf::Color ();
9 
10  Tile::Tile (const ID& id)
11  : id_ (id)
12  , sprite_ (nullptr)
13  , family_ (nullptr)
15  , isVisible_ (DEFAULT_VISIBLE_STATE)
16  , color_ (DEFAULT_COLOR)
17  {
18  }
19 
21  {
22  delete sprite_;
23  sprite_ = nullptr;
24  }
25 
26  Tile::Tile (const Tile& copy)
27  : id_ (copy.id_)
28  , sprite_ (copy.sprite_->Clone ())
29  , family_ (copy.family_)
30  , spatialInfo_ (copy.spatialInfo_)
31  , isVisible_ (copy.isVisible_)
32  , color_ (copy.color_)
33  {
34  }
35 
36  Tile* Tile::Clone () const
37  {
38  return new Tile (*this);
39  }
40 
41  const ID& Tile::GetID () const
42  {
43  return id_;
44  }
45 
46  void Tile::SetID (const ID& id)
47  {
48  id_ = id;
49  }
50 
51  void Tile::SetSprite (ISprite* sprite)
52  {
53  sprite_ = sprite;
54  }
55 
56  void Tile::SetFamily (const TileFamily* family)
57  {
58  family_ = family;
59  }
60 
61  bool Tile::BelongsTo (const TileFamily& family) const
62  {
63  return family_ == &family;
64  }
65 
66  const Vector2& Tile::GetPosition () const
67  {
68  return spatialInfo_.GetPosition ();
69  }
70 
71  const Vector2& Tile::GetSize () const
72  {
73  return spatialInfo_.GetSize ();
74  }
75 
76  const Vector2& Tile::GetTopLeft () const
77  {
78  return spatialInfo_.GetTopLeft ();
79  }
80 
81  const Vector2& Tile::GetBottomRight () const
82  {
83  return spatialInfo_.GetBottomRight ();
84  }
85 
86  const Vector2& Tile::GetCenter () const
87  {
88  return spatialInfo_.GetCenter ();
89  }
90 
92  {
93  return spatialInfo_.GetRectangle ();
94  }
95 
96  void Tile::Move (const Vector2& offset)
97  {
98  spatialInfo_.SetPosition (GetPosition () + offset);
99 
100  sprite_->Move (offset);
101  }
102 
103  void Tile::Scale (const Vector2& factor)
104  {
106  Vector2 (
107  GetSize ().x * factor.x,
108  GetSize ().y * factor.y));
109 
110  sprite_->Scale (factor);
111  }
112 
113  void Tile::SetPosition (const Vector2& position)
114  {
115  Move (position - GetPosition ());
116  }
117 
118  void Tile::SetSize (const Vector2& size)
119  {
120  Scale (
121  Vector2 (
122  size.x / GetSize ().x,
123  size.y / GetSize ().y));
124  }
125 
126  void Tile::Draw (IDrawingContext& context)
127  {
128  if (!isVisible_)
129  return;
130 
131  sprite_->Draw (context);
132  }
133 
134  bool Tile::IsVisible () const
135  {
136  return isVisible_;
137  }
138 
139  void Tile::Show (bool isVisible)
140  {
141  isVisible_ = isVisible;
142  }
143 
144  void Tile::ChangeColor (const sf::Color& color)
145  {
146  color_ = color;
147  }
148 
149  void Tile::Update (const Time& dt)
150  {
151  sprite_->Update (dt);
152  }
153 } // namespace yap