Skip to content

Commit

Permalink
Add Users world resource
Browse files Browse the repository at this point in the history
Linked: #92
  • Loading branch information
AndreasLrx committed Jun 7, 2022
1 parent 2df0310 commit e982dc2
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/game/User.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
** EPITECH PROJECT, 2022
** Bomberman
** File description:
** User
*/

#include "User.hpp"

namespace game
{
User::User(size_t id, int gamepadId) : _profile(id), _gamepadId(gamepadId) { setAvailable(false); }

void User::setKeyboard() { _gamepadId = -1; }

bool User::isKeyboard() const { return _gamepadId < 0; }

void User::setGamepadId(int id) { _gamepadId = id; }

int User::getGamepadId() const { return _gamepadId; }

void User::setId(size_t id) { _profile.load(id); }

size_t User::getId() const { return _profile.getId(); }

void User::setAvailable(bool available) { _available = available; }

bool User::isAvailable() const { return _available; }
} // namespace game
39 changes: 39 additions & 0 deletions src/game/User.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
** EPITECH PROJECT, 2022
** Bomberman
** File description:
** User
*/

#ifndef GAME_USER_HPP_
#define GAME_USER_HPP_

#include "settings/Profile.hpp"

namespace game
{
class User {
public:
User(size_t id = 0, int gamepadId = -1);
~User() = default;

void setKeyboard();
bool isKeyboard() const;

void setGamepadId(int id);
int getGamepadId() const;

void setId(size_t id);
size_t getId() const;

void setAvailable(bool available);
bool isAvailable() const;

private:
int _gamepadId;
bool _available;
settings::Profile _profile;
};
} // namespace game

#endif /* !GAME_USER_HPP_ */
22 changes: 22 additions & 0 deletions src/game/Users.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
** EPITECH PROJECT, 2022
** Bomberman
** File description:
** Users
*/

#include "Users.hpp"

namespace game
{
Users::Users()
{
for (size_t i = 0; i < UserId::PlayerCount; i++)
_users[i].setId(i);
}

User &Users::operator[](UserId id) { return _users[id]; }

const User &Users::operator[](UserId id) const { return _users[id]; }

} // namespace game
31 changes: 31 additions & 0 deletions src/game/Users.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
** EPITECH PROJECT, 2022
** Bomberman
** File description:
** Users
*/

#ifndef GAME_USERS_HPP_
#define GAME_USERS_HPP_

#include "User.hpp"
#include "ecs/resource/Resource.hpp"

namespace game
{
class Users : public ecs::Resource {
public:
enum UserId { Player1, Player2, Player3, Player4, PlayerCount };

Users();
~Users() = default;

const User &operator[](UserId id) const;
User &operator[](UserId id);

private:
User _users[UserId::PlayerCount];
};
} // namespace game

#endif /* !GAME_USERS_HPP_ */

0 comments on commit e982dc2

Please sign in to comment.