Advertisement
Guest User

Untitled

a guest
Apr 1st, 2024
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. // Here are the most important methods of Tile...
  2.  
  3. Tile::Tile() : sprite(), isInvisible(false), canBlock(false)
  4. {
  5.     tileColor = sf::Color();
  6. }
  7.  
  8. Tile::Tile(bool isInvisible, bool blocks, sf::Sprite sprite, sf::Color color)
  9.      : isInvisible(isInvisible), canBlock(blocks)
  10. {
  11.     this->SetTexture(sprite, color);
  12.     this->setSize(sf::Vector2f(C_TILE_IN_GAME_SIZE, C_TILE_IN_GAME_SIZE));
  13. }
  14.  
  15. Tile::Tile(bool blocks) : sprite(), isInvisible(true)
  16. {
  17.    
  18. }
  19.  
  20. Tile::Tile(bool isInvisible, bool blocks) : isInvisible(isInvisible), canBlock(blocks)
  21. {
  22.    
  23. }
  24.  
  25. #warning Default constructor for Tile
  26. Tile::Tile(const unsigned int tileSpriteIntVal, bool isInvisible, bool blocks, sf::Color color, const std::vector<sf::Sprite> spritesVector) : isInvisible(isInvisible), canBlock(blocks)
  27. {
  28.     // TODO: Use this constructor as a default
  29.     sf::Sprite sprite = spritesVector.at(tileSpriteIntVal);
  30.     this->SetTexture(sprite, color); // changes the tileSpriteIntVal
  31.     this->setSize(sf::Vector2f(C_TILE_IN_GAME_SIZE, C_TILE_IN_GAME_SIZE));
  32.     this->spriteEnumVal = static_cast<TileSprite>(tileSpriteIntVal);
  33. }
  34.  
  35. Tile::~Tile()
  36. {
  37. }
  38.  
  39. /* setTile sets a colored sprite to the tile and sets the alpha mask of it */
  40.  
  41. void Tile::SetTexture(sf::Sprite& _sprite, sf::Color color)
  42. {
  43.     if (this->isInvisible)
  44.     {
  45.         _sprite.setColor(sf::Color::Transparent);
  46.     } else
  47.     {
  48.         _sprite.setColor(color);
  49.     }
  50.     const sf::Texture* t = _sprite.getTexture();
  51.     this->setTexture(t);
  52.     this->setFillColor(color);
  53. }
  54.  
  55.  
  56. // Here are the most important methods from Entity:
  57. Entity::~Entity()
  58. {
  59.     delete this->tile;
  60. }
  61.  
  62. Entity* Entity::CreateNewEntityFromSprite(sf::Sprite entitySprite, std::string name, bool isInvisible, bool blocks, sf::Color entityColor, int x, int y)
  63. {
  64.     Tile* entityTile = new Tile{isInvisible, blocks, entitySprite, entityColor};
  65.     Entity* entity = new Entity{entityTile, name, x, y};
  66.     return entity;
  67. }
  68.  
  69. void Entity::SetActorComponent(Actor* acp)
  70. {
  71.     this->actorComponent = acp;
  72. }
  73.  
  74. Entity::Entity(const Entity& ec) : x(ec.x), y(ec.y), name(ec.name), blockingEntitiesVectorPos(ec.blockingEntitiesVectorPos)
  75. {
  76.     this->SetTile(ec.tile);
  77.     this->SetActorComponent(ec.actorComponent);
  78.     //this->tile->move(this->GetX(), this->GetY());
  79. }
  80.  
  81. // Here is the GetSpritesOfEntitiesCloseToPlayer method of Engine class.
  82.  
  83. std::vector<Tile*> Engine::GetSpritesOfEntitiesCloseToPlayer(const std::vector<Entity*>& entities, const Entity *cameraPointer) const
  84. {
  85.     std::vector<Tile*> vt;
  86.    
  87.     for (const Entity* bep: entities)
  88.     {
  89.         if (bep != nullptr)
  90.         {
  91.             if (DistanceBetweenTwoEntities(*bep, *cameraPointer) <= C_CAMERA_RANGE)
  92.             {
  93.                 vt.push_back(bep->GetTile());
  94.             }
  95.         }
  96.     }
  97.     return vt;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement