Skip to content

Commit

Permalink
Fixing PlayerManager
Browse files Browse the repository at this point in the history
  • Loading branch information
101itsGabe committed Sep 25, 2023
1 parent 3d039dc commit 6697d81
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 26 deletions.
Binary file modified main.exe
Binary file not shown.
80 changes: 54 additions & 26 deletions src/playerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,30 @@ PlayerManager::PlayerManager()

PlayerManager::PlayerManager(int numPlayers)
{
playerSheet = IMG_Load("images/pngsheet.png");
SDL_FreeSurface(playerSheet);
playerSheet = IMG_Load("src/images/pngsheet.png");
if (playerSheet == NULL)
{
cout << "player sheet is null :(" << endl;
}
else
{
cout << "Player sheet IS NOT NULL" << endl;
}

for (int i = 0; i < numPlayers; i++)
{
Player p;
playerList.emplace_back(p);
}
}
PlayerManager::~PlayerManager()
{
if (playerSheet != nullptr)
{
SDL_FreeSurface(playerSheet);
playerSheet = nullptr; // Optional: Set to nullptr to avoid potential issues with double freeing
}
}

vector<Player> &PlayerManager::getPlayerList()
{
Expand All @@ -28,36 +44,48 @@ vector<Player> &PlayerManager::getPlayerList()

SDL_Surface *PlayerManager::getSurface()
{
SDL_Surface *copy = playerSheet;
SDL_FreeSurface(copy);
return copy;
return playerSheet;
}

void PlayerManager::RenderPlayers(SDL_Renderer *renderer, vector<Tile> tiles)
{
for (Player &p : playerList)
SDL_Surface *copy = getSurface();
cout << "COPY I TOOK YOUR BITCH AND BODY" << endl;
if (!getPlayerList().empty())
{
Tile tile = tiles[p.GetTile()];
int padding = tile.getTileData().tileH * 0.05;
int posX = tile.getTileData().tileX + padding;
int posY = tile.getTileData().tileY + padding;
int W = tile.getTileData().tileW - 2 * padding;
int H = tile.getTileData().tileH - 2 * padding;

SDL_Rect pngSheetRect = {125, 25, 58, 94};
SDL_Rect destplayerRect = {posX, posY, W, H};

if (p.getTeam() == "Team1")
SDL_SetRenderDrawColor(renderer, 250, 0, 0, 250);
else if (p.getTeam() == "Team2")
for (Player &p : getPlayerList())
{
SDL_SetRenderDrawColor(renderer, 0, 0, 250, 250);
// cout << getTeam();
}
Tile tile = tiles[p.GetTile()];
int padding = tile.getTileData().tileH * 0.05;
int posX = tile.getTileData().tileX + padding;
int posY = tile.getTileData().tileY + padding;
int W = tile.getTileData().tileW - 2 * padding;
int H = tile.getTileData().tileH - 2 * padding;

SDL_Rect pngSheetRect = {125, 25, 58, 94};
SDL_Rect destplayerRect = {posX, posY, W, H};

SDL_Texture *t = SDL_CreateTextureFromSurface(renderer, getSurface());
if (t != NULL)
SDL_RenderCopy(renderer, t, &pngSheetRect, &destplayerRect);
SDL_DestroyTexture(t);
if (p.getTeam() == "Team1")
SDL_SetRenderDrawColor(renderer, 250, 0, 0, 250);
else if (p.getTeam() == "Team2")
{
SDL_SetRenderDrawColor(renderer, 0, 0, 250, 250);
}
if (copy != nullptr)
{
SDL_Texture *t = SDL_CreateTextureFromSurface(renderer, copy);
if (t != nullptr)
{
cout << "inside before render copy" << endl;
SDL_RenderCopy(renderer, t, &pngSheetRect, &destplayerRect);
}
else
{
cout << "Well well well texture IS null" << endl;
}
SDL_DestroyTexture(t);
}
}
SDL_FreeSurface(copy);
}
}
1 change: 1 addition & 0 deletions src/playerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PlayerManager

public:
PlayerManager();
~PlayerManager();
PlayerManager(int);

// void addPlayer(Player );
Expand Down

0 comments on commit 6697d81

Please sign in to comment.