Skip to content

Commit

Permalink
START WORKING ON THE GAME'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Mannheimer authored and Gabriel Mannheimer committed Sep 25, 2023
1 parent 6697d81 commit 22b9451
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 74 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"files.associations": {
"iostream": "cpp",
"*.tcc": "cpp",
"random": "cpp"
"random": "cpp",
"vector": "cpp"
}
}
Binary file modified main
100644 → 100755
Binary file not shown.
30 changes: 14 additions & 16 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ using namespace std;

void renderTile(SDL_Renderer *renderer, Tile *tile, int windowWidth, int windowHeight, int tileLen)
{

int tileSize = std::min(windowWidth, windowHeight) / 11;
int gridWidth = 15 * tileSize; // Total width of the grid
int gridHeight = 9 * tileSize; // Total height of the grid
Expand All @@ -38,7 +37,6 @@ void renderTile(SDL_Renderer *renderer, Tile *tile, int windowWidth, int windowH
int tileY = tile->getY() * tileSize + middleY;
// This is going to calc where the exact tile will go on screen
// This might have to be just the pixels like 64 or something

tile->setCoords(tileX, tileY, tileSize, tileSize); // Set the color for the Tile
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_Rect tileRect = {tileX, tileY, tileSize, tileSize};
Expand Down Expand Up @@ -158,10 +156,14 @@ bool InitSDL()

PlayerManager PM(6);
GameManager GM(PM.getPlayerList());
for (Player &p : PM.getPlayerList())
{
cout << "After GM: " << p.getTeam() << endl;
}

// Window
int windowWidth, windowHeight;

vector<Tile>* tiles;

TileManager TM;
tiles = TM.getTileList();

if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
Expand Down Expand Up @@ -224,13 +226,8 @@ bool InitSDL()
{
printf("Failed to load image. Error: %s\n", IMG_GetError());
}
// Window
int windowWidth, windowHeight;

vector<Tile> tiles;

TileManager TM;
tiles = TM.getTileList();

random_device rd;
mt19937 eng(rd());
Expand All @@ -255,6 +252,7 @@ bool InitSDL()
bool clicked = false;
bool menu = false;
bool highlight = true;
bool players = true;
Player *clickedPlayer = nullptr;
while (!quit)
{
Expand All @@ -274,9 +272,9 @@ bool InitSDL()
GM.RenderScore(renderer, font, windowWidth, windowHeight);
// cout << "Before Render Shot" << endl;
// GM.RenderShotPercent(renderer, font, windowWidth, windowHeight, clickedPlayer);
for (Tile &tile : TM.getTileList())
for (Tile &tile : *tiles)
{
renderTile(renderer, &tile, windowWidth, windowHeight, TM.getTileList().size());
renderTile(renderer, &tile, windowWidth, windowHeight, tiles->size());
renderText(renderer, &tile, font, GM.check3(tile.getTileId()));
if (tile.getMouseCheck(mouseX, mouseY) && highlight && !menu)
{
Expand All @@ -285,9 +283,6 @@ bool InitSDL()
curTile = &tile;
}
}

PM.RenderPlayers(renderer, TM.getTileList());

// cout << curTile->getTileId() << endl;

if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
Expand All @@ -310,6 +305,7 @@ bool InitSDL()
}
}

PM.RenderPlayers(renderer,tiles);
if (menu)
{
highlight = false;
Expand Down Expand Up @@ -357,10 +353,12 @@ bool InitSDL()
clickedPlayer->SetTile(curTile->getTileId());
clickedPlayer->setClicked(false);
clicked = false;
players = false;
}
}

GM.RenderShotPercent(renderer, font, windowWidth, windowHeight, clickedPlayer);

SDL_RenderPresent(renderer);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/gameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ GameManager::GameManager(vector<Player> &pl)
{
Team1.emplace_back(p);
p.setTeam("Team1");
cout << "Set on team1 : " << p.getTeam() << "\n";
team = false;
}
else
{
Team2.emplace_back(p);
p.setTeam("Team2");
cout << "Set on team2: " << p.getTeam() << "\n";
team = true;
}
}
Expand Down
77 changes: 31 additions & 46 deletions src/playerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ PlayerManager::PlayerManager()
PlayerManager::PlayerManager(int numPlayers)
{
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++)
{
Expand All @@ -42,50 +34,43 @@ vector<Player> &PlayerManager::getPlayerList()
return playerList;
}

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

void PlayerManager::RenderPlayers(SDL_Renderer *renderer, vector<Tile> tiles)

void PlayerManager::RenderPlayers(SDL_Renderer *renderer, vector<Tile>* tiles)
{
SDL_Surface *copy = getSurface();
cout << "COPY I TOOK YOUR BITCH AND BODY" << endl;
if (!getPlayerList().empty())
{
for (Player &p : getPlayerList())
{
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")
{
SDL_SetRenderDrawColor(renderer, 0, 0, 250, 250);
int sheetX = 124, sheetY = 30, sheetW = 59, sheetH = 85;
int row = 0;
SDL_Surface *copy2 = IMG_Load("./src/images/pngsheet.png");
if(copy2 ){
for(Player& p: getPlayerList()){
Tile curTile = (*tiles)[p.GetTile()];
int padding = curTile.getTileData().tileH * 0.05;
int posX = curTile.getTileData().tileX + padding;
int posY = curTile.getTileData().tileY + padding;
int W = curTile.getTileData().tileW - 2 * padding;
int H = curTile.getTileData().tileH - 2 * padding;

sheetX += 60;
if(row == 4){
row = 0;
sheetX = 124;
sheetY +=85;
}
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
row++;
SDL_Rect pngSheetRect = {sheetX, sheetY, sheetW, sheetH};
SDL_Rect destplayerRect = {posX,posY, W, H};
SDL_Texture* curText = SDL_CreateTextureFromSurface(renderer, copy2);
if(curText){
SDL_RenderCopy(renderer,curText,&pngSheetRect,&destplayerRect);
}
else
{
cout << "Well well well texture IS null" << endl;
}
SDL_DestroyTexture(t);
}
}
SDL_FreeSurface(copy);
}

SDL_FreeSurface(copy2);


}

4 changes: 2 additions & 2 deletions src/playerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class PlayerManager

// void addPlayer(Player );
// void removePlayer(Player);
void RenderPlayers(SDL_Renderer *, vector<Tile>);
void RenderPlayers(SDL_Renderer *, vector<Tile>*);
vector<Player> &getPlayerList();
SDL_Surface *getSurface();
//SDL_Surface& getSurface();
};

#endif
17 changes: 12 additions & 5 deletions src/tileManager.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
#include <iostream>
#include <vector>
#include "tileManager.h"
#include "tile.h"


TileManager::TileManager()
{
tileList = new vector<Tile>;
int r = 15;
int c = 9;

for (int col = 0; col < c; ++col)
{
for (int row = 0; row < r; ++row)
{
tileList.emplace_back(row, col, tileList.size());
tileList->emplace_back(row, col, tileList->size());
}
}
cout << "Done Placing" << endl;
}

TileManager::~TileManager(){
delete tileList;
}

void TileManager::addTile(Tile &t)
{
tileList.emplace_back(t);
tileList->emplace_back(t);
}

vector<Tile> TileManager::getTileList()
{
vector<Tile>* TileManager::getTileList(){
return tileList;
}
5 changes: 3 additions & 2 deletions src/tileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

class TileManager{
private:
vector<Tile> tileList;
vector<Tile>* tileList;
int tileLen;

public:
TileManager();
~TileManager();
void addTile(Tile&);
void removeTile(Tile*);

vector<Tile> getTileList();
vector<Tile>* getTileList();


};
Expand Down

0 comments on commit 22b9451

Please sign in to comment.