Loading

Paste #pxhdgoyax

  1. //header
  2.  
  3. #pragma once
  4.  
  5.  
  6. #include <SFML/Graphics.hpp>
  7. #include <string>
  8. #include <SFML/Audio.hpp>
  9.  
  10. class GameScene {
  11. public:
  12.     sf::Sprite bgSprite;
  13.     sf::Texture bgTex;
  14.     std::string bgPath;
  15.  
  16.     struct entity {
  17.         int id;
  18.         sf::Sprite Sprite;
  19.         sf::Texture Tex;
  20.         std::string texPath;
  21.         float x;
  22.         float y;
  23.     };
  24.  
  25.     struct entity bla;
  26.  
  27.     std::vector< struct entity > currentEntities;
  28.  
  29.     std::string Name;
  30.     sf::Music AmbientSound;
  31.  
  32. public:
  33.     GameScene();
  34.  
  35.     void setName(const std::string &Name);
  36.  
  37.     void setBgPath(const std::string &bgPath);
  38.  
  39.     void addEnt(int id, std::string texPath, float x, float y);
  40.  
  41.     void delEnt(int id);
  42. };
  43.  
  44. //CPP
  45. #include "gamescene.h"
  46.  
  47.  
  48. GameScene::GameScene()
  49. {
  50.  
  51.  
  52. }
  53.  
  54. void GameScene::setName(const std::string &Name) {
  55.     GameScene::Name = Name;
  56. }
  57.  
  58. void GameScene::setBgPath(const std::string &bgPath) {
  59.     GameScene::bgPath = bgPath;
  60.  
  61.     if (bgTex.loadFromFile(bgPath)) {
  62.         bgSprite.setTexture(bgTex);
  63.     }
  64.  
  65. }
  66.  
  67. void GameScene::addEnt(int id, std::string texPath, float x, float y) {
  68.  
  69.  
  70.     bla = {id, sf::Sprite(), sf::Texture(), texPath, 200.0f, 200.0f};
  71.  
  72.     if (bla.Tex.loadFromFile(std::string("entTex/") + texPath)) {
  73.         bla.Sprite.setTexture(bla.Tex);
  74.         bla.Sprite.setPosition(x, y);
  75.     }
  76.  
  77.     currentEntities.push_back(bla);
  78.     currentEntities.back().id = id;
  79.  
  80.  
  81. }
  82.  
  83. void GameScene::delEnt(int id) {
  84.     currentEntities.erase(std::remove_if(currentEntities.begin(), currentEntities.end(), [=](auto& entity) { return entity.id == id; }), currentEntities.end());
  85. }