diff --git a/include/AssetManager.h b/include/AssetManager.h index be44516..1d3c97a 100644 --- a/include/AssetManager.h +++ b/include/AssetManager.h @@ -24,7 +24,7 @@ public: AssetManager(Manager* manager); ~AssetManager(); - void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, Entity::TeamLabel teamLabel); + void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, Entity* owner); void createPowerup(Vector2D pos, std::function pickupFunc, std::string texturePath); Vector2D calculateSpawnPosition(); diff --git a/include/CollisionHandler.h b/include/CollisionHandler.h index 1fdba31..41993fb 100644 --- a/include/CollisionHandler.h +++ b/include/CollisionHandler.h @@ -44,16 +44,14 @@ public: // temporary function, remove once game.cpp cleaned up std::vector getColliders( std::initializer_list const& groupLabels, - std::initializer_list const& teamLabels = {}, - bool negateTeam = false); + std::initializer_list const& excludedEntities = {}); template T getAnyIntersection( Entity* entity, Vector2D posMod = {}, std::initializer_list const& groupLabels = {}, - std::initializer_list const& teamLabels = {}, - bool negateTeam = false); + std::initializer_list const& excludedEntities = {}); void update(); }; \ No newline at end of file diff --git a/include/Constants.h b/include/Constants.h index b54b4ce..713f1bd 100644 --- a/include/Constants.h +++ b/include/Constants.h @@ -3,7 +3,6 @@ #include using Group = std::size_t; -using Team = std::size_t; constexpr int CHARACTER_COUNT = 4; diff --git a/include/Entity.h b/include/Entity.h index 8f56b2f..073b65d 100644 --- a/include/Entity.h +++ b/include/Entity.h @@ -11,7 +11,6 @@ // TODO: remove here if possible // temporary fix: addComponent function template doesnt know TransformComponent -> error undefined type -// #include "KeyboardController.h" #include "InputComponent.h" #include "TransformComponent.h" #include "SpriteComponent.h" @@ -39,13 +38,6 @@ public: POWERUPS }; - enum class TeamLabel - { - NONE, //!< No team - BLUE, //!< Team blue - RED //!< Team red - }; - explicit Entity(Manager& mManager) : manager(mManager) { }; @@ -65,9 +57,6 @@ public: void delGroup(Group mGroup); std::bitset getGroupBitSet(); - void setTeam(TeamLabel teamLabel); - TeamLabel getTeam(); - Manager& getManager() { return manager; }; template bool hasComponent() const @@ -103,5 +92,4 @@ private: ComponentArray componentArray = {}; ComponentBitSet componentBitSet; GroupBitSet groupBitSet; - TeamLabel teamLabel; }; \ No newline at end of file diff --git a/include/GameFactory.h b/include/GameFactory.h index c10a0b0..b1e88ca 100644 --- a/include/GameFactory.h +++ b/include/GameFactory.h @@ -20,18 +20,6 @@ public: return factory; } - /*Game* get() { - assert(this->gameInstance != nullptr); - return this->gameInstance; - }*/ - - /*Game* create(GameInternal* gameInternal) { - Game* game = this->gameInstance == nullptr ? this->creator() : this->gameInstance; // TODO: error handling - game->gameInternal = gameInternal; - this->gameInstance = game; - return game; - }*/ - void registerClass(CreateFunc createFunc) { this->creatorFunc = createFunc; } @@ -49,11 +37,3 @@ public: private: CreateFunc creatorFunc = nullptr; }; - -/* -#define REGISTER_GAME(className) \ - static bool registered_##className = []() { \ - GameFactory::instance().registerClass(#className, []() -> Game* { return new className; }); \ - return true; \ - }(); -*/ diff --git a/include/GameInternal.h b/include/GameInternal.h index fc6957e..e300f2f 100644 --- a/include/GameInternal.h +++ b/include/GameInternal.h @@ -26,14 +26,14 @@ public: ~GameInternal(); void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen); - void selectCharacters(const char* &playerSprite, const char* &enemySprite); void handleEvents(); void update(); void render(); void clean(); bool isRunning() const; - void setRunning(bool running); + void setRunning(bool running); // TODO: should be private/not accesible for game dev + void stopGame(); /* static */ SDL_Renderer* renderer = nullptr; /* static */ SDL_Event event; @@ -54,15 +54,12 @@ public: // end moved globals void refreshPlayers(); - Entity::TeamLabel getWinner() const; - void setWinner(Entity::TeamLabel winningTeam); private: Game* gameInstance; int counter = 0; - bool running = false; + bool running = true; SDL_Window* window; - Entity::TeamLabel winner; }; diff --git a/include/HealthComponent.h b/include/HealthComponent.h index 1d57330..7f35905 100644 --- a/include/HealthComponent.h +++ b/include/HealthComponent.h @@ -1,6 +1,8 @@ #pragma once #include +#include + #include "Direction.h" #include "Component.h" @@ -28,4 +30,6 @@ private: int health; Direction side; std::string healthTexture; + + std::vector heartElements; }; \ No newline at end of file diff --git a/include/InputComponent.h b/include/InputComponent.h index f9c235a..9382cf1 100644 --- a/include/InputComponent.h +++ b/include/InputComponent.h @@ -96,7 +96,6 @@ public: void init() override; void update() override; - // void pollEvents(); bool isKeyDown(Key key); private: diff --git a/include/Manager.h b/include/Manager.h index ea549db..3282d9d 100644 --- a/include/Manager.h +++ b/include/Manager.h @@ -22,9 +22,6 @@ public: void addToGroup(Entity* mEntity, Group mGroup); std::vector& getGroup(Group mGroup); - void addToTeam(Entity* mEntity, Team mTeam); - std::vector& getTeam(Team mTeam); - std::vector getAll(); Entity& addEntity(); @@ -35,5 +32,4 @@ private: GameInternal* game; std::vector> entities; std::array, MAX_GROUPS> entitiesByGroup; - std::array, MAX_TEAMS> entitiesByTeam; }; \ No newline at end of file diff --git a/include/PopupWindow.h b/include/PopupWindow.h deleted file mode 100644 index 464ab28..0000000 --- a/include/PopupWindow.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include -#include -#include - -#include "Entity.h" - -class GameInternal; - -class PopupWindow { - -public: - PopupWindow(const char* title, const std::string& message); - ~PopupWindow(); - - void handleWinnerEvents(); - bool shouldContinue() const; - - bool interacted; - - void renderWinnerPopup(Entity::TeamLabel winner); - -private: - SDL_Renderer* renderer; - SDL_Window* window; - SDL_Texture* texture; - bool continueGame; -}; \ No newline at end of file diff --git a/include/ProjectileComponent.h b/include/ProjectileComponent.h index 0e57a69..4db0bfd 100644 --- a/include/ProjectileComponent.h +++ b/include/ProjectileComponent.h @@ -11,7 +11,8 @@ class ProjectileComponent : public Component //can maybe be split in separate .cpp file public: - ProjectileComponent(int range, int speed, Vector2D direction) : range(range), speed(speed), direction(direction) {} + ProjectileComponent(int range, int speed, Vector2D direction, Entity* owner) + : range(range), speed(speed), direction(direction), owner(owner) {} ~ProjectileComponent() {} void init() override; @@ -24,5 +25,7 @@ private: int speed = 0; int distance = 0; + Entity* owner = nullptr; + Vector2D direction; }; \ No newline at end of file diff --git a/include/TransformComponent.h b/include/TransformComponent.h index 14afe87..bfe3160 100644 --- a/include/TransformComponent.h +++ b/include/TransformComponent.h @@ -7,7 +7,7 @@ class TransformComponent : public Component { public: - Vector2D position; // TODO: change to int to safe CPU time -> possibly subpixel coordinates + Vector2D position; // TODO: change to int to save CPU time -> possibly subpixel coordinates Vector2D direction; int height = 32; diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index fb45af7..a772fe6 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -46,15 +46,14 @@ Mix_Music* AssetManager::getMusic(std::string id) return music.at(id); } -void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, Entity::TeamLabel teamLabel) { +void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, Entity* owner) { auto& projectile(man->addEntity()); projectile.addComponent(pos.x, pos.y, 32, 32, scale); //32x32 is standard size for objects projectile.addComponent(texturePath); - projectile.addComponent(range, speed, velocity); + projectile.addComponent(range, speed, velocity, owner); projectile.addComponent("projectile", 0.6f); projectile.addGroup((size_t)Entity::GroupLabel::PROJECTILE); - projectile.setTeam(teamLabel); } void AssetManager::createPowerup(Vector2D pos, std::function pickupFunc, std::string texturePath) { diff --git a/src/ColliderComponent.cpp b/src/ColliderComponent.cpp index aeca234..2275163 100644 --- a/src/ColliderComponent.cpp +++ b/src/ColliderComponent.cpp @@ -31,7 +31,6 @@ void ColliderComponent::init() } transform = &entity->getComponent(); - //Game::collisionHandler->add(this); this->update(); } diff --git a/src/CollisionHandler.cpp b/src/CollisionHandler.cpp index 2ca742a..3e0eaec 100644 --- a/src/CollisionHandler.cpp +++ b/src/CollisionHandler.cpp @@ -87,8 +87,7 @@ IntersectionBitSet CollisionHandler::getIntersectionWithBounds(Entity* entity, V std::vector CollisionHandler::getColliders( std::initializer_list const& groupLabels, - std::initializer_list const& teamLabels, - bool negateTeam) + std::initializer_list const& excludedEntities) { std::vector colliders; @@ -97,16 +96,11 @@ std::vector CollisionHandler::getColliders( groupBitSet.set((size_t) groupLabel); } - std::bitset teamBitSet; - for (auto& teamLabel : teamLabels) { - teamBitSet.set((size_t) teamLabel); - } - for (auto& entity : manager.getAll()) { if ((groupBitSet & entity->getGroupBitSet()).none()) continue; - if (teamBitSet.any() && negateTeam != (teamBitSet.test((size_t) entity->getTeam()))) - continue; + if (std::ranges::find(excludedEntities, entity) != excludedEntities.end()) + continue; if (!entity->hasComponent()) continue; colliders.emplace_back(&entity->getComponent()); @@ -120,11 +114,10 @@ IntersectionBitSet CollisionHandler::getAnyIntersection( Entity* entity, Vector2D posMod, std::initializer_list const& groupLabels, - std::initializer_list const& teamLabels, - bool negateTeam) + std::initializer_list const& excludedEntities) { IntersectionBitSet intersections; - for (auto& collider : getColliders(groupLabels, teamLabels)) { + for (auto& collider : getColliders(groupLabels, excludedEntities)) { intersections |= getIntersection(entity, collider->entity, posMod); } return intersections; @@ -135,10 +128,9 @@ Entity* CollisionHandler::getAnyIntersection( Entity* entity, Vector2D posMod, std::initializer_list const& groupLabels, - std::initializer_list const& teamLabels, - bool negateTeam) + std::initializer_list const& excludedEntities) { - for (auto& collider : getColliders(groupLabels, teamLabels)) { + for (auto& collider : getColliders(groupLabels, excludedEntities)) { SDL_Rect rect = entity->getComponent().collider + posMod; if (SDL_HasIntersection(&rect, &collider->collider)) { return collider->entity; diff --git a/src/Entity.cpp b/src/Entity.cpp index 2f2075f..4710983 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -34,14 +34,3 @@ std::bitset Entity::getGroupBitSet() { return groupBitSet; } - -void Entity::setTeam(Entity::TeamLabel teamLabel) -{ - this->teamLabel = teamLabel; - manager.addToTeam(this, (size_t) teamLabel); -} - -Entity::TeamLabel Entity::getTeam() -{ - return teamLabel; -} diff --git a/src/GameInternal.cpp b/src/GameInternal.cpp index d590eec..0e7587b 100644 --- a/src/GameInternal.cpp +++ b/src/GameInternal.cpp @@ -5,7 +5,6 @@ #include "CollisionHandler.h" #include "AssetManager.h" #include "SoundManager.h" -// #include "KeyboardController.h" #include "TileComponent.h" #include "Direction.h" #include "Entity.h" @@ -24,8 +23,6 @@ GameInternal::GameInternal() : projectiles(manager.getGroup((size_t)Entity::GroupLabel::PROJECTILE)), hearts(manager.getGroup((size_t)Entity::GroupLabel::HEARTS)), powerups(manager.getGroup((size_t)Entity::GroupLabel::POWERUPS)) - //player1(manager.addEntity()), - //player2(manager.addEntity()) {}; GameInternal::~GameInternal() = default; @@ -132,25 +129,10 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he return; } - // engine::init(); // temporarily moved down to access groups at engine init call - - // character selection - const char* player1Sprite; - const char* player2Sprite; - - selectCharacters(player1Sprite, player2Sprite); if (this->isRunning() == false) return; map = new Map(); - - //adding textures to the library in AssetManager - - /* - assets->addTexture("player1", "assets/chicken_neutral_knight.png"); - assets->addTexture("player2", "assets/chicken_neutral.png"); - assets->addTexture("egg", "assets/egg.png"); - */ // loading sounds // assets->addSoundEffect("throw_egg", "assets/sound/throw_egg.wav"); // assets->addSoundEffect("steps", "assets/sound/steps.wav"); @@ -158,127 +140,10 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he // loading music // assets->addMusic("background_music", "assets/sound/background_music.mp3"); - //ecs implementation - - // player1.setTeam(Entity::TeamLabel::BLUE); - // player1.addComponent(80,80,2); //posx, posy, scale - // player1.addComponent(player1Sprite, true); //adds sprite (32x32px), path needed - // player1.addComponent(SDL_SCANCODE_W, SDL_SCANCODE_S, SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_SCANCODE_E, Vector2D(2, 0));//custom keycontrols can be added - // player1.addComponent("player", 0.8f); //adds tag (for further use, reference tag) - // player1.addComponent(5, Direction::LEFT, "assets/heart.png"); - // player1.addComponent(); - // player1.addGroup((size_t) Entity::GroupLabel::PLAYERS); //tell programm what group it belongs to for rendering order - - - // player2.setTeam(Entity::TeamLabel::RED); - // player2.addComponent(600, 500, 2); - // player2.addComponent(player2Sprite, true); - // player2.addComponent(SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_RCTRL, Vector2D(-2, 0)); - // player2.addComponent("enemy", 0.8f); - // player2.addComponent(5, Direction::RIGHT, "assets/heart.png"); - // player2.addComponent(); - // player2.addGroup((size_t) Entity::GroupLabel::PLAYERS); - this->gameInstance = GameFactory::instance().create(this); this->gameInstance->init(); } -void GameInternal::selectCharacters(const char* &playerSprite, const char* &enemySprite) -{ - // TODO: move this whereever it makes sense (maybe game as a member) - std::map> characterSprites; - characterSprites[0] = std::make_pair("assets/chicken_neutral_knight.png", "assets/chicken_knight_spritesheet.png"); - characterSprites[1] = std::make_pair("assets/chicken_neutral.png", "assets/chicken_spritesheet.png"); - characterSprites[2] = std::make_pair("assets/chicken_neutral_wizard.png", "assets/chicken_wizard_spritesheet.png"); - characterSprites[3] = std::make_pair("assets/chicken_neutral_mlady.png", "assets/chicken_mlady_spritesheet.png"); - - SDL_Rect playerCharacterRects[CHARACTER_COUNT]; - SDL_Rect enemyCharacterRects[CHARACTER_COUNT]; - SDL_Texture* characterTextures[CHARACTER_COUNT]; - - int playerSelection = 0; - int enemySelection = 0; - - // load textures - for (int i = 0; i < CHARACTER_COUNT; ++i) - { - characterTextures[i] = IMG_LoadTexture(renderer, characterSprites.find(i)->second.first); - } - - // set up initial positions for character rects - for (int i = 0; i < CHARACTER_COUNT; ++i) - { - playerCharacterRects[i] = { 134 + (i % 2) * 118, 272 + ((i >= 2) ? 114 : 0), 64, 64 }; - enemyCharacterRects[i] = { 485 + (i % 2) * 118, 273 + ((i >= 2) ? 114 : 0), 64, 64 }; - } - - bool hasQuit = false; - - while (!hasQuit) - { - SDL_PollEvent(&event); - - if (event.type == SDL_QUIT) - { - hasQuit = true; - } - - if (event.type == SDL_KEYDOWN) - { - if (event.key.keysym.scancode == SDL_SCANCODE_RETURN) - { - break; - } - - switch (event.key.keysym.scancode) - { - case SDL_SCANCODE_A: - playerSelection = (playerSelection - 1 + CHARACTER_COUNT) % CHARACTER_COUNT; - break; - case SDL_SCANCODE_D: - playerSelection = (playerSelection + 1) % CHARACTER_COUNT; - break; - - case SDL_SCANCODE_LEFT: - enemySelection = (enemySelection - 1 + CHARACTER_COUNT) % CHARACTER_COUNT; - break; - case SDL_SCANCODE_RIGHT: - enemySelection = (enemySelection + 1) % CHARACTER_COUNT; - break; - - default: - break; - } - } - - SDL_Texture* backgroundTexture = GameInternal::textureManager->loadTexture("assets/characterSelection.png"); - SDL_RenderClear(renderer); - SDL_RenderCopy(renderer, backgroundTexture, NULL, NULL); - - for (int i = 0; i < CHARACTER_COUNT; ++i) - { - SDL_RenderCopy(renderer, characterTextures[i], nullptr, &playerCharacterRects[i]); - SDL_RenderCopy(renderer, characterTextures[i], nullptr, &enemyCharacterRects[i]); - } - - SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); - SDL_RenderDrawRect(renderer, &playerCharacterRects[playerSelection]); - SDL_RenderDrawRect(renderer, &enemyCharacterRects[enemySelection]); - - SDL_RenderPresent(renderer); - } - - if (hasQuit) - { - this->setRunning(false); - return; - } - - playerSprite = characterSprites.find(playerSelection)->second.second; - enemySprite = characterSprites.find(enemySelection)->second.second; - this->setRunning(true); -} - void GameInternal::handleEvents() { SDL_PollEvent(&event); @@ -336,35 +201,13 @@ bool GameInternal::isRunning() const return running; } -void GameInternal::setRunning(bool running) +void GameInternal::setRunning(bool running) //TODO: might be depracted { this->running = running; } -void GameInternal::setWinner(Entity::TeamLabel winningTeam) +void GameInternal::stopGame() { - this->winner = winningTeam; - this->setRunning(false); + this->running = false; } -Entity::TeamLabel GameInternal::getWinner() const -{ - return this->winner; -} - -//void Game::refreshPlayers() { -// -// for(auto& p : projectiles) { -// p->destroy(); -// } -// -// player1.getComponent().position = Vector2D(80, 80); -// player2.getComponent().position = Vector2D(600, 500); -// -// player1.getComponent().setHealth(5); -// player2.getComponent().setHealth(5); -// -// isRunning = true; -// -// update(); -//} diff --git a/src/GameObject.cpp b/src/GameObject.cpp index 2b065c2..24a4665 100644 --- a/src/GameObject.cpp +++ b/src/GameObject.cpp @@ -9,7 +9,6 @@ GameObject::GameObject(const char* texturesheet, int x, int y) // seems not to be used, and was using deprecated functionality SDL_SetError("GameObject not implemented"); - // this->objTexture = Game::textureManager->loadTexture(texturesheet); this->xPos = x; this->yPos = y; } diff --git a/src/HealthComponent.cpp b/src/HealthComponent.cpp index 6294e97..e672a1e 100644 --- a/src/HealthComponent.cpp +++ b/src/HealthComponent.cpp @@ -25,12 +25,12 @@ void HealthComponent::setHealth(int health) void HealthComponent::refreshHearts() { // clear hearts if exist - for (auto& heart : this->entity->getManager().getGroup((size_t) Entity::GroupLabel::HEARTS)) { - if (heart->getTeam() == this->entity->getTeam()) { - heart->destroy(); - } + for (auto& heart : this->heartElements) { + heart->destroy(); } + this->heartElements.clear(); + int x; //starting position for first health icon if(side == Direction::LEFT) { @@ -59,5 +59,5 @@ void HealthComponent::createHeartComponents(int x) heart.addComponent(x,5,2); heart.addComponent(this->healthTexture.data()); heart.addGroup((size_t)Entity::GroupLabel::HEARTS); - heart.setTeam(this->entity->getTeam()); + this->heartElements.emplace_back(&heart); } \ No newline at end of file diff --git a/src/InputComponent.cpp b/src/InputComponent.cpp index 538ad93..ac26b32 100644 --- a/src/InputComponent.cpp +++ b/src/InputComponent.cpp @@ -8,11 +8,7 @@ InputComponent::InputComponent() InputComponent::~InputComponent() = default; -void InputComponent::init() -{ - // m_keyStates = SDL_GetKeyboardState(NULL); - // InitKeyMappings(); -} +void InputComponent::init(){} void InputComponent::update() { diff --git a/src/Manager.cpp b/src/Manager.cpp index f98ebdc..50cb5ea 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -24,17 +24,6 @@ void Manager::refresh() }), std::end(v)); } - for (auto i(0u); i < MAX_TEAMS; i++) - { - auto& v(entitiesByTeam[i]); - v.erase( - std::remove_if(std::begin(v), std::end(v), - [i](Entity* mEntity) - { - return !mEntity->isActive() || (size_t)(mEntity->getTeam()) != i; - }), std::end(v)); - } - entities.erase(std::remove_if(std::begin(entities), std::end(entities), [](const std::unique_ptr& mEntity) { @@ -58,16 +47,6 @@ std::vector& Manager::getGroup(Group mGroup) return entitiesByGroup.at(mGroup); } -void Manager::addToTeam(Entity* mEntity, Team mTeam) -{ - entitiesByTeam.at(mTeam).emplace_back(mEntity); // -} - -std::vector& Manager::getTeam(Team mTeam) -{ - return entitiesByTeam.at(mTeam); -} - std::vector Manager::getAll() { std::vector entity_vec; diff --git a/src/PopupWindow.cpp b/src/PopupWindow.cpp deleted file mode 100644 index 39362a9..0000000 --- a/src/PopupWindow.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include - -#include "Entity.h" -#include "PopupWindow.h" -#include "TextureManager.h" -#include "GameInternal.h" - -PopupWindow::PopupWindow(const char* title, const std::string &message) : -continueGame(false), interacted(false) { - this->window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 250, 0); - //font = TTF_OpenFont("assets/Trajan.ttf", 24); // Change the path and size as needed - - this->renderer = SDL_CreateRenderer(window, -1, 0); - SDL_SetRenderDrawColor(this->renderer, 255, 255, 255, 255); - - //SDL_Surface* surface = TTF_RenderText_Blended(font, message.c_str(), {255, 255, 255}); - //texture = SDL_CreateTextureFromSurface(renderer, surface); - - //SDL_FreeSurface(surface); -} - -PopupWindow::~PopupWindow() { - SDL_DestroyTexture(this->texture); - SDL_DestroyRenderer(this->renderer); - SDL_DestroyWindow(this->window); -} - -void PopupWindow::handleWinnerEvents() { - - SDL_Event e; - - while (SDL_PollEvent(&e)) - { - if (e.type == SDL_QUIT) - { - continueGame = false; - interacted = true; - return; - } - - if(e.type != SDL_KEYDOWN) - continue; - - switch (e.key.keysym.sym) { - - case SDLK_q: { - continueGame = false; - interacted = true; - break; - } - case SDLK_c: { - continueGame = true; - interacted = true; - break; - } - } - } -} - -bool PopupWindow::shouldContinue() const { - return continueGame; -} - -void PopupWindow::renderWinnerPopup(Entity::TeamLabel winner) { - - SDL_RenderClear(this->renderer); - - //Maybe use texture manager (changes need to be made that it does not use game::renderer automatically, but receives one instead) - this->texture = winner == Entity::TeamLabel::BLUE ? - IMG_LoadTexture(this->renderer, "assets/Player1Victory.png") : - IMG_LoadTexture(this->renderer, "assets/Player2Victory.png"); - - SDL_RenderCopy(this->renderer, this->texture, NULL, NULL); - - SDL_RenderPresent(this->renderer); - - //Error handling for debugging - const char* sdlError = SDL_GetError(); - if (*sdlError != '\0') { - std::cerr << "SDL Error: " << sdlError << std::endl; - SDL_ClearError(); - } - -} diff --git a/src/PowerupComponent.cpp b/src/PowerupComponent.cpp index 7d4ce0a..5c1df71 100644 --- a/src/PowerupComponent.cpp +++ b/src/PowerupComponent.cpp @@ -18,9 +18,7 @@ void PowerupComponent::update() if ((player = this->entity->getManager().getGame()->collisionHandler->getAnyIntersection( entity, Vector2D(0, 0), - { Entity::GroupLabel::PLAYERS }, - {}, - true)) != nullptr) + { Entity::GroupLabel::PLAYERS })) != nullptr) { (this->pickupFunc)(player); this->entity->destroy(); diff --git a/src/ProjectileComponent.cpp b/src/ProjectileComponent.cpp index 5399b54..11599c8 100644 --- a/src/ProjectileComponent.cpp +++ b/src/ProjectileComponent.cpp @@ -36,8 +36,7 @@ void ProjectileComponent::update() entity, Vector2D(0,0), {Entity::GroupLabel::PLAYERS}, - {entity->getTeam()}, - true)) != nullptr) { + {this->owner})) != nullptr) { player->getComponent().modifyHealth(); this->entity->destroy(); } diff --git a/src/SpriteComponent.cpp b/src/SpriteComponent.cpp index 845dfd1..2c730cf 100644 --- a/src/SpriteComponent.cpp +++ b/src/SpriteComponent.cpp @@ -32,10 +32,7 @@ SpriteComponent::SpriteComponent( this->texturePath = path; } -SpriteComponent::~SpriteComponent() -{ - // SDL_DestroyTexture(this->texture); -} +SpriteComponent::~SpriteComponent() {} void SpriteComponent::setTexture(const char* path) { diff --git a/src/TransformComponent.cpp b/src/TransformComponent.cpp index 07db8f3..4baf67e 100644 --- a/src/TransformComponent.cpp +++ b/src/TransformComponent.cpp @@ -52,8 +52,6 @@ void TransformComponent::init() void TransformComponent::update() { - // if(velocity.x != 0 && velocity.y != 0) - float multiplier = direction.x != 0 && direction.y != 0 ? 0.707 : 1; // normalizes vector; only works if directions are in increments of 45° Vector2D positionChange( direction.x * this->getSpeed() * multiplier, diff --git a/src/main.cpp b/src/main.cpp index 3546600..cc8be77 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,6 @@ #include "Entity.h" #include "GameInternal.h" #include "Constants.h" -#include "PopupWindow.h" GameInternal* game = nullptr;