Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.
Merged

Dev #19

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions Client/src/Display/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

#include "Display.hpp"
#include "Player/Player.hpp"
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/Sprite.hpp>
Expand All @@ -24,7 +25,6 @@

client::Display::Display()
{
std::cout << "Init display" << std::endl;
this->_window =
std::make_unique<sf::RenderWindow>(sf::VideoMode({1920, 1080}), "");
if (!this->_window)
Expand All @@ -34,7 +34,6 @@ client::Display::Display()

client::Display::~Display()
{
std::cout << "Destroy display" << std::endl;
if (this->_window)
this->_window->close();
}
Expand All @@ -52,7 +51,7 @@ void client::Display::deactivateWindow()
bool client::Display::handleEvent()
{
sf::Event sfmlEvent;
bool Event;
static bool Event = false;

while (this->_window->pollEvent(sfmlEvent)) {
switch (sfmlEvent.type) {
Expand All @@ -62,6 +61,10 @@ bool client::Display::handleEvent()
Event = true;
break;
}
case sf::Event::KeyReleased: {
Event = false;
break;
}
default:
break;
}
Expand All @@ -71,7 +74,6 @@ bool client::Display::handleEvent()

void client::Display::_loadAssets()
{
std::cout << "Loading assets" << std::endl;
this->_font = std::make_unique<sf::Font>();
this->_font->loadFromFile(
"./assets/fonts/JetBrainsMonoNerdFont-Medium.ttf");
Expand All @@ -82,7 +84,6 @@ void client::Display::_loadAssets()
this->_loadCoinAssets();
this->_loadPlayerAssets();
this->_loadLaserAssets();
std::cout << "Done loading assets" << std::endl;
}

void client::Display::_loadBackgroundAsset()
Expand Down Expand Up @@ -200,40 +201,46 @@ void client::Display::_loadPlayerDieAssets()
}

void client::Display::renderFrame(
const Player &player, const std::vector<std::string> &map)
const Player &player, const Player &player2, const std::vector<std::string> &map)
{
// this->_startX = player.getPosX();
this->_startX = player.getPosX() - (this->_endX - this->_startX) / 2.0;
this->_endX = this->_startX + 10;

this->_window->clear();
this->_drawBackground();
this->_drawProps(player, map);
this->_drawPlayer(player2, map);
this->_drawPlayer(player, map);
this->_drawAth(player);
this->_drawAth(player, player2);
this->_window->display();
}

void client::Display::renderEndGame(const Player &player)
void client::Display::renderEndGame(const Player &player, const Player &player2)
{
this->_window->clear();
this->_drawEnd(player);
this->_drawEnd(player, player2);
this->_window->display();
}

void client::Display::_drawEnd(const Player &player)
void client::Display::_drawEnd(const Player &player, const Player &player2)
{
sf::Text text;
text.setFont(*this->_font);
text.setCharacterSize(24);

std::stringstream stream;
if (player.getPlayerWin()) {
if (player.getPlayerWin() == WIN_STATE::WIN) {
stream << "WIN :)\n";
stream << "SCORE: " << player.getScore() << "\n";
} else {
stream << "Opponent player: " << player2.getScore() << '\n';
} else if (player.getPlayerWin() == WIN_STATE::LOSE ){
stream << "Lose (Skill Issue)\n";
stream << "FINAL SCORE: " << player.getScore() << "\n";
stream << "Opponent player: " << player2.getScore() << '\n';
} else {
stream << "Draw (please be better next time)\n";
stream << "FINAL SCORE: " << player.getScore() << "\n";
stream << "Opponent player: " << player2.getScore() << '\n';
}

text.setString(stream.str());
Expand All @@ -242,14 +249,15 @@ void client::Display::_drawEnd(const Player &player)
this->_window->draw(text);
}

void client::Display::_drawAth(const Player &player)
void client::Display::_drawAth(const Player &player, const Player &player2)
{
sf::Text text;
text.setFont(*this->_font);
text.setCharacterSize(24);

std::stringstream stream;
stream << "SCORE: " << player.getScore() << "\n";
stream << "SCORE: " << player.getScore() << '\n';
stream << "OPPONENT SCORE: " << player2.getScore() << '\n';

text.setString(stream.str());
text.setPosition(20, 20);
Expand Down Expand Up @@ -365,7 +373,10 @@ void client::Display::_drawPlayer(
}
playerSprite->setPosition(playerStartX - (tileWidth / 2),
(map.size() - 1 - player.getPosY()) * tileHeight);
if (player.getPlayerTransparency())
playerSprite->setColor(sf::Color(0,0,0, 120));
this->_window->draw(*playerSprite);
playerSprite->setColor(sf::Color(255, 255, 255, 255));

if (player.getPosY() > 0) {
this->_playerFlight[flightFrame] = std::move(playerSprite);
Expand Down
10 changes: 4 additions & 6 deletions Client/src/Display/Display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#pragma once

#include "Inputs/Inputs.hpp"
#include "Player/Player.hpp"
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/Sprite.hpp>
Expand Down Expand Up @@ -35,8 +34,8 @@ namespace client {
~Display();

void renderFrame(
const Player &player, const std::vector<std::string> &map);
void renderEndGame(const Player &player);
const Player &player, const Player &player2, const std::vector<std::string> &map);
void renderEndGame(const Player &player, const Player &player2);

bool handleEvent();

Expand All @@ -52,7 +51,6 @@ namespace client {

std::unique_ptr<sf::RenderWindow> _window = nullptr;
std::unique_ptr<sf::Font> _font = nullptr;
std::vector<client::Inputs> _events;

sf::Texture _coinTexture;
sf::Texture _laserTexture;
Expand Down Expand Up @@ -82,7 +80,7 @@ namespace client {
const Player &player, const std::vector<std::string> &map);
void _drawProps(
const Player &player, const std::vector<std::string> &map);
void _drawAth(const Player &player);
void _drawEnd(const Player &player);
void _drawAth(const Player &player, const Player &player2);
void _drawEnd(const Player &player, const Player &player2);
};
} // namespace client
72 changes: 0 additions & 72 deletions Client/src/Inputs/Inputs.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions Client/src/JetpackClient/JetpackClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <thread>

client::JetpackClient::JetpackClient(
const std::string &ip, const std::string &port)
: _ip(ip), _port(port), _running(true), _network(ip, port),
const std::string &ip, const std::string &port, bool debugMode)
: _ip(ip), _port(port), _debugMode(debugMode), _running(true), _network(ip, port),
_state(CLIENT_STATE::UNDEFIDED), _MapIsRetrieve(false)
{}

Expand Down
7 changes: 5 additions & 2 deletions Client/src/JetpackClient/JetpackClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ namespace client {
std::string _msg;
};

JetpackClient(const std::string &ip, const std::string &port);
JetpackClient(const std::string &ip, const std::string &port, bool debugMode);
~JetpackClient();

std::uint8_t runClient();

private:
std::string _ip;
std::string _port;
bool _debugMode;
bool _running;
CLIENT_STATE _state;
std::queue<std::string> _data;
Expand All @@ -50,6 +51,7 @@ namespace client {
client::Network _network;
client::Display _displayEngine;
Player _player;
Player _player2;
bool _MapIsRetrieve;
std::vector<std::string> _map;

Expand All @@ -65,7 +67,8 @@ namespace client {
void _startMap();
void _retrieveMap(const std::string &map);
void _endMap();
void _startGame();
void _startGamePlayerOne();
void _startGamePlayerTwo();
void _updatePlayerPosition(const std::string &pos);
void _retrieveCoin();
};
Expand Down
Loading