Advertisement
Guest User

Tile.cpp

a guest
Nov 25th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include "Tile.h"
  2. #include "SFMLApp.h"
  3. #include <cstdlib>
  4.  
  5. const float Tile::TILE_SIZE = 48.0f;
  6.  
  7. Tile::Tile(float x, float y, sf::Texture* texture) {
  8.     this->cx = x;
  9.     this->cy = y;
  10.  
  11.     this->shape = sf::RectangleShape(sf::Vector2f(Tile::TILE_SIZE, Tile::TILE_SIZE));
  12.     this->shape.setPosition((x - (Tile::TILE_SIZE / 2)), (y - (Tile::TILE_SIZE / 2)));
  13.     this->shape.setFillColor(sf::Color(0, 0, 0, 242));
  14.  
  15.     if(texture != NULL) {
  16.         // Set the sprite's texture and information.
  17.         this->sprite.setTexture(*texture);
  18.         this->sprite.setPosition((this->cx - (Tile::TILE_SIZE / 2)), (this->cy - (Tile::TILE_SIZE / 2)));
  19.         this->sprite.setScale((Tile::TILE_SIZE / texture->getSize().x), (Tile::TILE_SIZE / texture->getSize().y));
  20.     }
  21.  
  22.     this->state = TileState::HIDDEN;
  23.  
  24.     // Load the overlay sprite.
  25.     sf::Texture* overlayTexture = SFMLApp::textureManager->GetTexture("FogMesh");
  26.     if(overlayTexture != NULL) {
  27.         // Set the overlay sprite's texture and information.
  28.         this->overlay.setTexture(*overlayTexture);
  29.         this->overlay.setPosition(this->sprite.getPosition());
  30.         this->overlay.setScale(this->sprite.getScale());
  31.     }
  32. }
  33.  
  34. Tile::~Tile() {
  35.    
  36. }
  37.  
  38. sf::Vector2f Tile::GetPosition() {
  39.     return sf::Vector2f(this->cx, this->cy);
  40. }
  41.  
  42. void Tile::ChangeState(TileState newState) {
  43.     this->state = newState;
  44. }
  45.  
  46. void Tile::Draw(sf::RenderWindow* window) {
  47.     /*if(this->state != TileState::HIDDEN) {
  48.         if(this->sprite.getTexture() != NULL) window->draw(sprite);
  49.         if(this->state == TileState::REVEALED) window->draw(this->shape);
  50.     }*/
  51.     if(this->sprite.getTexture() != NULL) window->draw(this->sprite);
  52.     if(this->state == TileState::REVEALED) {
  53.         window->draw(this->overlay);
  54.     } else if(this->state == TileState::HIDDEN) {
  55.         window->draw(this->shape);
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement