-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamePlayers.cpp
More file actions
69 lines (60 loc) · 2.29 KB
/
GamePlayers.cpp
File metadata and controls
69 lines (60 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "GamePlayers.h"
void GamePlayers::initTextures()
{
if (!this->textures["PLAYER_SHIP"].loadFromFile("Recources/Images/Sprites/Player/ship.png"))
throw "ERROR::GAMESTATE::COULD_NOT_LOAD_PLAYER_SHIP_TEXTURE";
if (!this->textures["PLAYER_SOCCER"].loadFromFile("Recources/Images/Sprites/Player/soccer.png"))
throw "ERROR::GAMESTATE::COULD_NOT_LOAD_PLAYER_SOCCER_TEXTURE";
if (!this->textures["PLAYER_DOG"].loadFromFile("Recources/Images/Sprites/Player/dog.png"))
throw "ERROR::GAMESTATE::COULD_NOT_LOAD_PLAYER_DOG_TEXTURE";
if (!this->textures["PLAYER_HAT"].loadFromFile("Recources/Images/Sprites/Player/hat.png"))
throw "ERROR::GAMESTATE::COULD_NOT_LOAD_PLAYER_HAT_TEXTURE";
}
void GamePlayers::initPlayers()
{
if (total_players == 2) {
this->players.push_back(new Player(1000, 920, this->textures["PLAYER_SHIP"]));
this->players.push_back(new Player(980, 1000, this->textures["PLAYER_SOCCER"]));
}
else if (total_players == 3) {
this->players.push_back(new Player(1000, 920, this->textures["PLAYER_SHIP"]));
this->players.push_back(new Player(980, 1000, this->textures["PLAYER_SOCCER"]));
this->players.push_back(new Player(960, 940, this->textures["PLAYER_DOG"]));
}
else if (total_players == 4) {
this->players.push_back(new Player(1000, 920, this->textures["PLAYER_SHIP"]));
this->players.push_back(new Player(980, 1000, this->textures["PLAYER_SOCCER"]));
this->players.push_back(new Player(960, 940, this->textures["PLAYER_DOG"]));
this->players.push_back(new Player(960, 1000, this->textures["PLAYER_HAT"]));
}
}
GamePlayers::GamePlayers(std::map<std::string, sf::Texture>& textures, int total_players)
{
this->total_players = total_players;
this->textures = textures;
this->initTextures();
this->initPlayers();
}
GamePlayers::~GamePlayers()
{
for (auto& player : this->players)
delete player;
}
std::vector<Player*>& GamePlayers::getPlayers()
{
return this->players;
}
Player* GamePlayers::getPlayer(int index)
{
return this->players[index];
}
void GamePlayers::update(const float& dt, sf::Vector2f mousePosView)
{
for (auto & player : this->players)
player->update(dt, mousePosView);
}
void GamePlayers::render(sf::RenderTarget* target)
{
for (auto& player : this->players)
player->render(target);
}