Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Tile.h"
- #include "SFMLApp.h"
- #include <cstdlib>
- const float Tile::TILE_SIZE = 48.0f;
- Tile::Tile(float x, float y, sf::Texture* texture) {
- this->cx = x;
- this->cy = y;
- this->shape = sf::RectangleShape(sf::Vector2f(Tile::TILE_SIZE, Tile::TILE_SIZE));
- this->shape.setPosition((x - (Tile::TILE_SIZE / 2)), (y - (Tile::TILE_SIZE / 2)));
- this->shape.setFillColor(sf::Color(0, 0, 0, 242));
- if(texture != NULL) {
- // Set the sprite's texture and information.
- this->sprite.setTexture(*texture);
- this->sprite.setPosition((this->cx - (Tile::TILE_SIZE / 2)), (this->cy - (Tile::TILE_SIZE / 2)));
- this->sprite.setScale((Tile::TILE_SIZE / texture->getSize().x), (Tile::TILE_SIZE / texture->getSize().y));
- }
- this->state = TileState::HIDDEN;
- // Load the overlay sprite.
- sf::Texture* overlayTexture = SFMLApp::textureManager->GetTexture("FogMesh");
- if(overlayTexture != NULL) {
- // Set the overlay sprite's texture and information.
- this->overlay.setTexture(*overlayTexture);
- this->overlay.setPosition(this->sprite.getPosition());
- this->overlay.setScale(this->sprite.getScale());
- }
- }
- Tile::~Tile() {
- }
- sf::Vector2f Tile::GetPosition() {
- return sf::Vector2f(this->cx, this->cy);
- }
- void Tile::ChangeState(TileState newState) {
- this->state = newState;
- }
- void Tile::Draw(sf::RenderWindow* window) {
- /*if(this->state != TileState::HIDDEN) {
- if(this->sprite.getTexture() != NULL) window->draw(sprite);
- if(this->state == TileState::REVEALED) window->draw(this->shape);
- }*/
- if(this->sprite.getTexture() != NULL) window->draw(this->sprite);
- if(this->state == TileState::REVEALED) {
- window->draw(this->overlay);
- } else if(this->state == TileState::HIDDEN) {
- window->draw(this->shape);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement