mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 07:53:43 +00:00
fix(PR) + cleaned up some dead code
This commit is contained in:
parent
6bf460d483
commit
2ef373dd2c
@ -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<MAX_GROUPS> getGroupBitSet();
|
||||
|
||||
//void setTeam(TeamLabel teamLabel);
|
||||
//TeamLabel getTeam();
|
||||
|
||||
Manager& getManager() { return manager; };
|
||||
|
||||
template <typename T> bool hasComponent() const
|
||||
@ -103,5 +92,4 @@ private:
|
||||
ComponentArray componentArray = {};
|
||||
ComponentBitSet componentBitSet;
|
||||
GroupBitSet groupBitSet;
|
||||
//TeamLabel teamLabel;
|
||||
};
|
||||
@ -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; \
|
||||
}();
|
||||
*/
|
||||
|
||||
@ -26,7 +26,6 @@ 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();
|
||||
@ -55,8 +54,6 @@ public:
|
||||
// end moved globals
|
||||
|
||||
void refreshPlayers();
|
||||
//Entity::TeamLabel getWinner() const;
|
||||
//void setWinner(Entity::TeamLabel winningTeam);
|
||||
|
||||
private:
|
||||
|
||||
@ -65,5 +62,4 @@ private:
|
||||
int counter = 0;
|
||||
bool running = true;
|
||||
SDL_Window* window;
|
||||
//Entity::TeamLabel winner;
|
||||
};
|
||||
|
||||
@ -96,7 +96,6 @@ public:
|
||||
void init() override;
|
||||
void update() override;
|
||||
|
||||
// void pollEvents();
|
||||
bool isKeyDown(Key key);
|
||||
|
||||
private:
|
||||
|
||||
@ -22,9 +22,6 @@ public:
|
||||
void addToGroup(Entity* mEntity, Group mGroup);
|
||||
std::vector<Entity*>& getGroup(Group mGroup);
|
||||
|
||||
//void addToTeam(Entity* mEntity, Team mTeam);
|
||||
//std::vector<Entity*>& getTeam(Team mTeam);
|
||||
|
||||
std::vector<Entity*> getAll();
|
||||
|
||||
Entity& addEntity();
|
||||
@ -35,5 +32,4 @@ private:
|
||||
GameInternal* game;
|
||||
std::vector<std::unique_ptr<Entity>> entities;
|
||||
std::array<std::vector<Entity*>, MAX_GROUPS> entitiesByGroup;
|
||||
//std::array<std::vector<Entity*>, MAX_TEAMS> entitiesByTeam;
|
||||
};
|
||||
@ -1,32 +0,0 @@
|
||||
#pragma once
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include <string>
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
*/
|
||||
@ -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;
|
||||
|
||||
@ -31,7 +31,6 @@ void ColliderComponent::init()
|
||||
}
|
||||
|
||||
transform = &entity->getComponent<TransformComponent>();
|
||||
//Game::collisionHandler->add(this);
|
||||
this->update();
|
||||
}
|
||||
|
||||
|
||||
@ -34,14 +34,3 @@ std::bitset<MAX_GROUPS> 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;
|
||||
//}
|
||||
|
||||
@ -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,13 +129,6 @@ 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();
|
||||
@ -151,102 +141,6 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he
|
||||
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<int, std::pair<const char*, const char*>> 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);
|
||||
@ -313,30 +207,4 @@ void GameInternal::stopGame()
|
||||
{
|
||||
this->running = false;
|
||||
}
|
||||
//void GameInternal::setWinner(Entity::TeamLabel winningTeam)
|
||||
//{
|
||||
// this->winner = winningTeam;
|
||||
// this->setRunning(false);
|
||||
//}
|
||||
//
|
||||
//Entity::TeamLabel GameInternal::getWinner() const
|
||||
//{
|
||||
// return this->winner;
|
||||
//}
|
||||
|
||||
//void Game::refreshPlayers() {
|
||||
//
|
||||
// for(auto& p : projectiles) {
|
||||
// p->destroy();
|
||||
// }
|
||||
//
|
||||
// player1.getComponent<TransformComponent>().position = Vector2D(80, 80);
|
||||
// player2.getComponent<TransformComponent>().position = Vector2D(600, 500);
|
||||
//
|
||||
// player1.getComponent<HealthComponent>().setHealth(5);
|
||||
// player2.getComponent<HealthComponent>().setHealth(5);
|
||||
//
|
||||
// isRunning = true;
|
||||
//
|
||||
// update();
|
||||
//}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -8,11 +8,7 @@ InputComponent::InputComponent()
|
||||
|
||||
InputComponent::~InputComponent() = default;
|
||||
|
||||
void InputComponent::init()
|
||||
{
|
||||
// m_keyStates = SDL_GetKeyboardState(NULL);
|
||||
// InitKeyMappings();
|
||||
}
|
||||
void InputComponent::init(){}
|
||||
|
||||
void InputComponent::update()
|
||||
{
|
||||
|
||||
@ -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<Entity>& mEntity)
|
||||
{
|
||||
@ -58,16 +47,6 @@ std::vector<Entity*>& Manager::getGroup(Group mGroup)
|
||||
return entitiesByGroup.at(mGroup);
|
||||
}
|
||||
|
||||
//void Manager::addToTeam(Entity* mEntity, Team mTeam)
|
||||
//{
|
||||
// entitiesByTeam.at(mTeam).emplace_back(mEntity); //
|
||||
//}
|
||||
//
|
||||
//std::vector<Entity*>& Manager::getTeam(Team mTeam)
|
||||
//{
|
||||
// return entitiesByTeam.at(mTeam);
|
||||
//}
|
||||
|
||||
std::vector<Entity*> Manager::getAll()
|
||||
{
|
||||
std::vector<Entity*> entity_vec;
|
||||
|
||||
@ -1,89 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <SDL_image.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
@ -32,10 +32,7 @@ SpriteComponent::SpriteComponent(
|
||||
this->texturePath = path;
|
||||
}
|
||||
|
||||
SpriteComponent::~SpriteComponent()
|
||||
{
|
||||
// SDL_DestroyTexture(this->texture);
|
||||
}
|
||||
SpriteComponent::~SpriteComponent() {}
|
||||
|
||||
void SpriteComponent::setTexture(const char* path)
|
||||
{
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
#include "Entity.h"
|
||||
#include "GameInternal.h"
|
||||
#include "Constants.h"
|
||||
#include "PopupWindow.h"
|
||||
|
||||
GameInternal* game = nullptr;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user