Skip to content
Merged
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
2 changes: 1 addition & 1 deletion client/game_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ constexpr std::string_view AWP_ITEM_PATH = "../assets/gfx/map/awp_d.bmp";
constexpr std::string_view M3_ITEM_PATH = "../assets/gfx/map/m3_d.bmp";
constexpr std::string_view AK_ITEM_PATH = "../assets/gfx/map/ak47_d.bmp";
constexpr std::string_view BOMB_ITEM_PATH = "../assets/gfx/guns/bomb.bmp";
constexpr std::string_view BOMB_PLANTED_ITEM_PATH = "../assets/gfx/map/bomb_b.bmp";
constexpr std::string_view BOMB_PLANTED_ITEM_PATH = "../assets/gfx/map/bomb_d.bmp";
} // namespace Paths

// --- Gun Type Offsets ---
Expand Down
27 changes: 25 additions & 2 deletions client/gui/controllers/keyboardhandler.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#include "keyboardhandler.h"

#include <iostream>
#include <utility>

#include <SDL2/SDL.h>


KeyboardHandler::KeyboardHandler(Queue<Message>& output_queue, shopDisplay& shopRef,
ScoreDisplay& score_displayRef, SoundManager& sound_managerRef,
SdlHud& hudDisplayRef):
SdlHud& hudDisplayRef, SdlWorld& wordRef):
output_queue(output_queue),
shopRef(shopRef),
score_displayRef(score_displayRef),
sound_manager(sound_managerRef),
hudDisplayRef(hudDisplayRef) {}
hudDisplayRef(hudDisplayRef),
worldRef(wordRef) {}

void KeyboardHandler::handleEvent(const SDL_Event& event) {
if (event.type != SDL_KEYDOWN) {
Expand All @@ -22,45 +24,66 @@ void KeyboardHandler::handleEvent(const SDL_Event& event) {
break;
case SDLK_b:
output_queue.push(Message(GetShopPricesCommand()));

break;
case SDLK_m:
sound_manager.toggle_mute();
hudDisplayRef.update_mute_icon();

break;
case SDLK_TAB:
if (!score_displayRef.isActive()) {
output_queue.push(Message(GetScoreboardCommand()));
} else {
score_displayRef.updateState();
}

break;
case SDLK_1:
std::cout << "Switching to primary item" << std::endl;
output_queue.push(Message(SwitchItemCommand(ItemSlot::Primary)));

break;
case SDLK_2:
std::cout << "Switching to 2 item" << std::endl;
output_queue.push(Message(SwitchItemCommand(ItemSlot::Secondary)));

break;
case SDLK_3:
std::cout << "Switching to 3 item" << std::endl;
output_queue.push(Message(SwitchItemCommand(ItemSlot::Melee)));

break;
case SDLK_4:
std::cout << "Switching to 4 item" << std::endl;
output_queue.push(Message(SwitchItemCommand(ItemSlot::Bomb)));

break;
case SDLK_r:
output_queue.push(Message(ReloadCommand()));
sound_manager.play("reload");

break;
case SDLK_g:
sound_manager.play("item_pick");
output_queue.push(Message(PickUpItemCommand()));
std::cout << "Picking up item" << std::endl;
break;
case SDLK_e:
std::optional<Message> maybe_message = worldRef.getStartBombMessage(sound_manager);
if (maybe_message.has_value()) {
output_queue.push(std::move(*maybe_message));
return;
}
return;
break;
}
}

std::optional<Message> maybe_message = worldRef.getStopBombMessage(sound_manager);
if (maybe_message.has_value()) {
output_queue.push(std::move(*maybe_message));
}
update_direction();
}

Expand Down
3 changes: 2 additions & 1 deletion client/gui/controllers/keyboardhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class KeyboardHandler {
public:
explicit KeyboardHandler(Queue<Message>& output_queue, shopDisplay& shopRef,
ScoreDisplay& score_displayRef, SoundManager& sound_manager,
SdlHud& hudDisplayRef);
SdlHud& hudDisplayRef, SdlWorld& wordRef);
void handleEvent(const SDL_Event& event);

private:
Expand All @@ -27,6 +27,7 @@ class KeyboardHandler {
ScoreDisplay& score_displayRef;
SoundManager& sound_manager;
SdlHud& hudDisplayRef;
SdlWorld& worldRef;
void update_direction();
};

Expand Down
2 changes: 2 additions & 0 deletions client/gui/map_view/sdl_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "common/utils/vector_2d.h"

class SdlItem {

static constexpr std::string_view AK47_PATH = "../assets/gfx/guns/ak47.xcf";
static constexpr std::string_view M3_PATH = "../assets/gfx/guns/m3.xcf";
static constexpr std::string_view GLOCK_PATH = "../assets/gfx/guns/glock.xcf";
Expand All @@ -26,6 +27,7 @@ class SdlItem {
std::unique_ptr<SdlTexture> knife_texture;
std::unique_ptr<SdlTexture> bomb_texture;


public:
explicit SdlItem(const SdlWindow& window);
void render_gun(GunType gun_type, Vector2D pos, float angle);
Expand Down
49 changes: 49 additions & 0 deletions client/gui/map_view/sdl_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,52 @@ void SdlWorld::render() {
field_of_view.render(window.getWidth(), window.getHeight(),
get_rotation(game_state.get_players().at(player_name)));
}

// enum class BombPhaseType { NotPlanted, Planted, Exploded, Defused, Planting, Defusing };
std::optional<Message> SdlWorld::getStartBombMessage(SoundManager& sound_manager) {
if (game_state.get_phase().get_type() != PhaseType::InRound &&
game_state.get_phase().get_type() != PhaseType::BombPlanted) {
std::cout << "Cannot start bomb action outside of InRound phase." << std::endl;
return std::nullopt;
}
std::cout << "getStartBombMessage called" << std::endl;
Team player_team = game_state.get_players().at(player_name).get_team();
if (player_team == Team::CT) {
/*if (game_state.get_bomb().value().item.get_bomb_phase() == BombPhaseType::Planted) {*/
std::cout << "Starting bomb defusing" << std::endl;
sound_manager.play("defuse_bomb");
return Message(StartDefusingBombCommand());
//}
} else if (player_team == Team::TT) {
// if (game_state.get_bomb().value().item.get_bomb_phase() == BombPhaseType::NotPlanted) {
sound_manager.play("plant_bomb");
std::cout << "Starting bomb planting" << std::endl;
return Message(StartPlantingBombCommand());
// }
}
return std::nullopt;
}

std::optional<Message> SdlWorld::getStopBombMessage(SoundManager& sound_manager) {
if (game_state.get_phase().get_type() != PhaseType::InRound) {
std::cout << "Cannot start bomb action outside of InRound phase." << std::endl;
return std::nullopt;
}
Team player_team = game_state.get_players().at(player_name).get_team();
if (player_team == Team::CT) {
// if (game_state.get_bomb().value().item.get_bomb_phase() == BombPhaseType::Defusing) {
std::cout << "Stop defusing bomb" << std::endl;
sound_manager.play("stop_defuse_bomb");
return Message(StopDefusingBombCommand());
//}

} else if (player_team == Team::TT) {
// if (game_state.get_bomb().value().item.get_bomb_phase() == BombPhaseType::Planting) {
std::cout << "Stop plant bomb" << std::endl;
sound_manager.play("stop_plant_bomb");
return Message(StopPlantingBombCommand());
// }
}

return std::nullopt;
}
5 changes: 5 additions & 0 deletions client/gui/map_view/sdl_world.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include "../window_elements/area.h"
#include "../window_elements/sdl_texture.h"
#include "../window_elements/sdl_window.h"
#include "client/sound_manager.h"
#include "common/map/map.h"
#include "common/message.h"
#include "common/responses.h"
#include "common/updates/game_update.h"

Expand Down Expand Up @@ -47,6 +50,8 @@ class SdlWorld {

void render();
void renderBackground();
std::optional<Message> getStartBombMessage(SoundManager& sound_manager);
std::optional<Message> getStopBombMessage(SoundManager& sound_manager);
void handle_hit(HitResponse&& hit);
float get_rotation(const PlayerUpdate& player_state);
};
17 changes: 15 additions & 2 deletions client/sdl_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ void SDLDisplay::run() {
quit_flag,
MouseHandler(output_queue, SCREEN_WIDTH, SCREEN_HEIGHT, list_teams, *shop_display,
hud_display, list_skins),
KeyboardHandler(output_queue, *shop_display, *score_display, sound_manager,
hud_display));
KeyboardHandler(output_queue, *shop_display, *score_display, sound_manager, hud_display,
*world));
end_round_display = std::make_unique<EndRoundDisplay>(window, state);
input_handler->start();

Expand Down Expand Up @@ -124,6 +124,9 @@ void SDLDisplay::run() {
world->render();
hud_display.render();
end_round_display->render();
} else if (state.get_phase().get_type() == PhaseType::BombPlanted) {
world->render();
hud_display.render();
}

if (score_display->isActive()) {
Expand Down Expand Up @@ -286,6 +289,16 @@ void SDLDisplay::update_state() {
sound_manager.play("error");
break;
}
case MessageType::BOMB_EXPLODED_RESP: {
std::cout << "Received BombExplodedResponse" << std::endl;
auto bomb_exploded_resp = msg.get_content<BombExplodedResponse>();
/*GameUpdate updates = game.get_full_update();
EXPECT_TRUE(bomb_exploded_resp.get_explosion_center() ==
updates.get_bomb().value().hitbox.get_center());
EXPECT_EQ(bomb_exploded_resp.get_explosion_radius(), BombConfig::max_range);*/
sound_manager.play("bomb_exploded");
break;
}
default: {
std::cerr << "SDLDisplay::update_state: Received unexpected message type: "
<< msg.get_type() << std::endl;
Expand Down
Loading