Advertisement
Guest User

Tile.cpp

a guest
Nov 26th, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include "Tile.h"
  2. #include "SFML/System/Vector2.hpp"
  3. #include "SFML/Graphics/Color.hpp"
  4.  
  5. const float Tile::TILE_SIZE = 48.0f;
  6.  
  7. Tile::Tile(float cx, float cy, int type, bool traversable) {
  8.     this->cx = cx;
  9.     this->cy = cy;
  10.     this->type = type;
  11.     this->traversable = traversable;
  12.  
  13.     this->shape = sf::RectangleShape(sf::Vector2f(Tile::TILE_SIZE, Tile::TILE_SIZE));
  14.     this->shape.setPosition(sf::Vector2f((cx - (Tile::TILE_SIZE / 2)), (cy - (Tile::TILE_SIZE / 2))));
  15.     this->shape.setFillColor((type == 0)?(sf::Color::White):(sf::Color::Blue));
  16. }
  17.  
  18. Tile::~Tile() {
  19.  
  20. }
  21.  
  22. int Tile::GetType() {
  23.     return this->type;
  24. }
  25.  
  26. void Tile::SetType(int type) {
  27.     this->type = type;
  28.     if(type == 0) {
  29.         this->traversable = true;
  30.         this->shape.setFillColor(sf::Color::White);
  31.     } else {
  32.         this->traversable = false;
  33.         this->shape.setFillColor(sf::Color::Blue);
  34.     }
  35. }
  36.  
  37. bool Tile::IsTraversable() {
  38.     return this->traversable;
  39. }
  40.  
  41. void Tile::Draw(sf::RenderWindow* window) {
  42.     window->draw(this->shape);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement