Skip to content

Commit 2b20566

Browse files
committed
Lvl display and classes for menus
1 parent 7b1195d commit 2b20566

15 files changed

+307
-185
lines changed

CMakeLists.txt

+11-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,17 @@ set(PROJECT_FILES
9999
"src/game/entities/Error.cpp"
100100
"src/game/entities/Error.h"
101101
"src/game/weapons/projectile/WeaponSniper.cpp"
102-
"src/game/weapons/projectile/WeaponSniper.h")
102+
"src/game/weapons/projectile/WeaponSniper.h"
103+
"src/game/interface/MainMenu.cpp"
104+
"src/game/interface/MainMenu.h"
105+
"src/game/interface/GameSelectMenu.cpp"
106+
"src/game/interface/GameSelectMenu.h"
107+
"src/game/interface/PauseMenu.cpp"
108+
"src/game/interface/PauseMenu.h"
109+
"src/game/interface/SettingsMenu.cpp"
110+
"src/game/interface/SettingsMenu.h"
111+
112+
)
103113

104114
# Add executable
105115
add_executable(${PROJECT_NAME} ${PROJECT_FILES})

src/game/GameWorld.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,18 @@ Entity *GameWorld::AddEntity(Entity *entity)
179179
m_Last = entity;
180180
}
181181

182-
if (entity->GetType() == ENTTYPE_CHARACTER || entity->GetType() == ENTTYPE_CRATE) {
183-
if (!m_FirstShootable) {
184-
m_FirstShootable = entity;
185-
m_LastShootable = entity;
186-
entity->m_PrevShootable = nullptr;
187-
entity->m_NextShootable = nullptr;
188-
} else {
189-
m_LastShootable->m_NextShootable = entity;
190-
entity->m_PrevShootable = m_LastShootable;
191-
m_LastShootable = entity;
192-
}
193-
}
182+
// if (entity->GetType() == ENTTYPE_CHARACTER || entity->GetType() == ENTTYPE_CRATE) {
183+
// if (!m_FirstShootable) {
184+
// m_FirstShootable = entity;
185+
// m_LastShootable = entity;
186+
// entity->m_PrevShootable = nullptr;
187+
// entity->m_NextShootable = nullptr;
188+
// } else {
189+
// m_LastShootable->m_NextShootable = entity;
190+
// entity->m_PrevShootable = m_LastShootable;
191+
// m_LastShootable = entity;
192+
// }
193+
// }
194194

195195
return entity;
196196
}

src/game/GameWorld.h

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class GameWorld {
5454
[[nodiscard]] double GetWidth() const { return m_Width; }
5555
[[nodiscard]] double GetHeight() const { return m_Height; }
5656
[[nodiscard]] double GetNamesShown() const { return m_ShowNamesVisibility < 0.1 ? 0.0 : m_ShowNamesVisibility; }
57-
[[nodiscard]] bool GetPaused() const { return m_Paused; }
5857
[[nodiscard]] bool GameOver() const { return m_GameOver; }
5958
[[nodiscard]] unsigned long long GetTick() const { return m_CurrentTick; }
6059
[[nodiscard]] unsigned int GetNextPlayerIndex() const;

src/game/entities/Crate.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ void Crate::Tick() {
7676
}
7777

7878
void Crate::Draw() {
79+
7980
Drawing* Render = m_World->GameWindow()->Render();
8081

8182
SDL_FRect DrawRect = { float(m_Core.Pos.x) - float(m_Core.Size.x / 2.0),
8283
float(m_Core.Pos.y) - float(m_Core.Size.y / 2.0),
8384
float(m_Core.Size.x),
8485
float(m_Core.Size.y) };
8586

87+
std::cout << "render crates" << std::endl;
8688
Render->RenderTextureFCamera((*m_Texture)->SDLTexture(), nullptr, DrawRect);
8789
}

src/game/entities/characters/CharacterNPC.h

+1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ class CharacterNPC : public Character {
3333
bool is_boss);
3434
~CharacterNPC();
3535
void UpdateAttacker(Player* attacker);
36+
void GetBoss();
3637
};

src/game/entities/characters/character/Character.cpp

+19-7
Original file line numberDiff line numberDiff line change
@@ -1058,27 +1058,26 @@ void Character::DrawHook()
10581058
}
10591059

10601060
void Character::DrawHealthbar()
1061-
{
1061+
{
10621062
if (m_NPC)
10631063
return;
10641064

10651065
Drawing *Render = m_World->GameWindow()->Render();
10661066

10671067
// Render health bar
1068-
if (m_Health != m_MaxHealth)
1069-
{
10701068
m_HealthBar.SetColor(m_HealthbarColor.r, m_HealthbarColor.g, m_HealthbarColor.b, m_HealthbarColor.a);
10711069
Texture *HealthPlate = ConfusingHP ? m_HealthBar.GetTexture() : m_HealthBar.UpdateTexture();
10721070

1073-
int HealthBarW = HealthPlate->GetWidth();
1071+
int HealthBarW = HealthPlate->GetWidth() - 20; // Make the health bar slightly smaller
10741072
int HealthBarH = HealthPlate->GetHeight();
1075-
SDL_Rect HealthplateRect = {int(m_Core.Pos.x - HealthBarW / 2.0),
1073+
SDL_Rect HealthplateRect = {int(m_Core.Pos.x - HealthBarW / 2.0) + 10, // Adjust position to the right
10761074
int(m_Core.Pos.y + m_Core.Size.y / 2.0),
10771075
HealthBarW, HealthBarH};
10781076

10791077
if (m_HealthInt->GetFlaggedForUpdate())
10801078
{
10811079
std::string HealthText;
1080+
10821081
if (!ConfusingHP)
10831082
HealthText = FString("%i/%i", int(m_Health), int(m_MaxHealth));
10841083
else
@@ -1090,14 +1089,26 @@ void Character::DrawHealthbar()
10901089
Texture *HealthTexture = m_HealthInt->RequestUpdate();
10911090
double HealthTextureW = HealthTexture->GetWidth();
10921091
double HealthTextureH = HealthTexture->GetHeight();
1093-
SDL_Rect HealthIntRect = {int(m_Core.Pos.x - HealthTextureW / 4.0),
1092+
SDL_Rect HealthIntRect = {int(m_Core.Pos.x - HealthTextureW / 4.0) + 10, // Adjust position to the right
10941093
int(m_Core.Pos.y + m_Core.Size.y / 2.0 + HealthTextureH / 4.0),
10951094
int(HealthTextureW / 2.0),
10961095
int(HealthTextureH / 2.0)};
10971096

10981097
Render->RenderTextureCamera(HealthPlate->SDLTexture(), nullptr, HealthplateRect);
10991098
Render->RenderTextureCamera(HealthTexture->SDLTexture(), nullptr, HealthIntRect);
1100-
}
1099+
1100+
// Draw level indicator
1101+
TTF_Font* SmallFont = m_World->GameWindow()->Assets()->TextHandler()->LoadFont("assets/fonts/Minecraft.ttf", 10); // Load a smaller font
1102+
std::string LevelText = FString("LVL %i", m_Player->GetLevel()); // Use the level value directly
1103+
TextSurface LevelSurface(m_World->GameWindow()->Assets(), SmallFont, LevelText, {255, 255, 255});
1104+
Texture *LevelTexture = LevelSurface.RequestUpdate();
1105+
int LevelTextureW = LevelTexture->GetWidth();
1106+
int LevelTextureH = LevelTexture->GetHeight();
1107+
SDL_Rect LevelRect = {int(m_Core.Pos.x - HealthBarW / 2.0) - LevelTextureW +5, // Position to the left of the health bar
1108+
int(m_Core.Pos.y + m_Core.Size.y / 2.0) +3,
1109+
LevelTextureW, LevelTextureH};
1110+
1111+
Render->RenderTextureCamera(LevelTexture->SDLTexture(), nullptr, LevelRect);
11011112
}
11021113

11031114
void Character::DrawHands()
@@ -1185,6 +1196,7 @@ void Character::DrawNameplate()
11851196
SDL_SetTextureAlphaMod(NamePlateTexture->SDLTexture(), Opacity);
11861197
Render->RenderTextureCamera(NamePlateTexture->SDLTexture(), nullptr, NamePlateRect);
11871198

1199+
11881200
auto CoordinateText = FString("%ix, %iy", int(m_Core.Pos.x), int(m_Core.Pos.y));
11891201
m_CoordinatePlate->SetText(CoordinateText);
11901202
m_CoordinatePlate->SetColor(m_NameplateColor);

src/game/interface/GameSelectMenu.cpp

Whitespace-only changes.

src/game/interface/GameSelectMenu.h

Whitespace-only changes.

src/game/interface/MainMenu.cpp

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// src/game/interface/MainMenu.cpp
2+
3+
#include "MainMenu.h"
4+
5+
MainMenu::MainMenu(GameReference* gameWindow)
6+
: m_GameWindow(gameWindow) {
7+
AssetsManager* assetsHandler = m_GameWindow->Assets();
8+
ImageManager* imageHandler = assetsHandler->ImageHandler();
9+
10+
m_MenuTexture = imageHandler->LoadTexture("assets/images/interface/Menu.png", true);
11+
m_TexturePlay = imageHandler->LoadTexture("assets/images/interface/PlayButton.png", true);
12+
m_TextureExit = imageHandler->LoadTexture("assets/images/interface/Exit.png", true);
13+
14+
m_PlayButtonRect = {int(m_GameWindow->GetWidth2()) - 180, int(m_GameWindow->GetHeight2()) - 40, 360, 80};
15+
m_ExitButtonRect = {int(m_GameWindow->GetWidth2()) - 180, int(m_GameWindow->GetHeight2()) + 121, 360, 80};
16+
}
17+
18+
MainMenu::~MainMenu() {
19+
// Clean up textures if necessary
20+
}
21+
22+
void MainMenu::Show() {
23+
bool running = true;
24+
bool menuOpen = true;
25+
26+
while (menuOpen) {
27+
Render();
28+
SDL_ShowCursor(1);
29+
SDL_Event currentEvent;
30+
while (SDL_PollEvent(&currentEvent)) {
31+
m_GameWindow->Event(currentEvent);
32+
HandleEvent(currentEvent, running, menuOpen);
33+
}
34+
m_GameWindow->Render()->UpdateWindow();
35+
}
36+
}
37+
38+
void MainMenu::HandleEvent(const SDL_Event& event, bool& running, bool& menuOpen) {
39+
SoundManager* soundHandler = m_GameWindow->Assets()->SoundHandler();
40+
Sound* quitSound = soundHandler->LoadSound("assets/sounds/Quit.wav", true);
41+
Sound* lowUISound = soundHandler->LoadSound("assets/sounds/LowUI.wav", true);
42+
43+
switch (event.type) {
44+
case SDL_QUIT:
45+
menuOpen = false;
46+
running = false;
47+
m_GameWindow->Deinitialize(true);
48+
break;
49+
case SDL_MOUSEBUTTONDOWN:
50+
if (event.button.button == SDL_BUTTON_LEFT) {
51+
int x = event.button.x;
52+
int y = event.button.y;
53+
if (x >= m_PlayButtonRect.x && x < m_PlayButtonRect.x + m_PlayButtonRect.w &&
54+
y >= m_PlayButtonRect.y && y < m_PlayButtonRect.y + m_PlayButtonRect.h) {
55+
menuOpen = false;
56+
soundHandler->PlaySound(lowUISound);
57+
}
58+
if (x >= m_ExitButtonRect.x && x < m_ExitButtonRect.x + m_ExitButtonRect.w &&
59+
y >= m_ExitButtonRect.y && y < m_ExitButtonRect.y + m_ExitButtonRect.h) {
60+
soundHandler->PlaySound(quitSound);
61+
m_GameWindow->Deinitialize(true);
62+
running = false;
63+
menuOpen = false;
64+
}
65+
}
66+
break;
67+
case SDL_WINDOWEVENT:
68+
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
69+
m_PlayButtonRect = {int(m_GameWindow->GetWidth2()) - 180, int(m_GameWindow->GetHeight2()) - 40, 360, 80};
70+
m_ExitButtonRect = {int(m_GameWindow->GetWidth2()) - 180, int(m_GameWindow->GetHeight2()) + 121, 360, 80};
71+
}
72+
break;
73+
}
74+
}
75+
76+
void MainMenu::Render() {
77+
Drawing* render = m_GameWindow->Render();
78+
render->RenderTextureFullscreen(m_MenuTexture->SDLTexture(), nullptr);
79+
render->RenderTexture(m_TexturePlay->SDLTexture(), nullptr, m_PlayButtonRect);
80+
render->RenderTexture(m_TextureExit->SDLTexture(), nullptr, m_ExitButtonRect);
81+
}

src/game/interface/MainMenu.h

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// src/game/interface/MainMenu.h
2+
3+
#pragma once
4+
5+
#include "../../GameReference.h"
6+
#include <SDL.h>
7+
8+
class MainMenu {
9+
private:
10+
GameReference* m_GameWindow;
11+
Texture* m_MenuTexture;
12+
Texture* m_TexturePlay;
13+
Texture* m_TextureExit;
14+
SDL_Rect m_PlayButtonRect;
15+
SDL_Rect m_ExitButtonRect;
16+
17+
public:
18+
MainMenu(GameReference* gameWindow);
19+
~MainMenu();
20+
21+
void Show();
22+
void HandleEvent(const SDL_Event& event, bool& running, bool& menuOpen);
23+
void Render();
24+
};

src/game/interface/PauseMenu.cpp

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// src/game/interface/PauseMenu.cpp
2+
3+
#include "PauseMenu.h"
4+
5+
PauseMenu::PauseMenu(GameReference *gameWindow, MainMenu *mainMenu)
6+
: m_GameWindow(gameWindow), m_MainMenu(mainMenu)
7+
{
8+
AssetsManager *assetsHandler = m_GameWindow->Assets();
9+
ImageManager *imageHandler = assetsHandler->ImageHandler();
10+
11+
m_TextureResume = imageHandler->LoadTexture("assets/images/interface/Resume.png", true);
12+
m_TextureBack = imageHandler->LoadTexture("assets/images/interface/Back.png", true);
13+
14+
m_ResumeButtonRect = {int(m_GameWindow->GetWidth2()) - 100, int(m_GameWindow->GetHeight2()) - 150, 200, 70};
15+
m_BackToMenuButtonRect = {int(m_GameWindow->GetWidth2()) - 100, int(m_GameWindow->GetHeight2()) + 50, 200, 70};
16+
}
17+
18+
PauseMenu::~PauseMenu()
19+
{
20+
// Clean up textures if necessary
21+
}
22+
23+
void PauseMenu::Show()
24+
{
25+
bool running = true;
26+
bool pauseMenu = true;
27+
28+
while (pauseMenu)
29+
{
30+
Render();
31+
SDL_ShowCursor(1);
32+
SDL_Event currentEvent;
33+
while (SDL_PollEvent(&currentEvent))
34+
{
35+
m_GameWindow->Event(currentEvent);
36+
HandleEvent(currentEvent, running, pauseMenu);
37+
}
38+
m_GameWindow->Render()->UpdateWindow();
39+
}
40+
}
41+
42+
void PauseMenu::HandleEvent(const SDL_Event &event, bool &running, bool &pauseMenu)
43+
{
44+
SoundManager *soundHandler = m_GameWindow->Assets()->SoundHandler();
45+
Sound *lowUISound = soundHandler->LoadSound("assets/sounds/LowUI.wav", true);
46+
Sound *midUISound = soundHandler->LoadSound("assets/sounds/MidUI.wav", true);
47+
48+
switch (event.type)
49+
{
50+
case SDL_QUIT:
51+
pauseMenu = false;
52+
running = false;
53+
m_GameWindow->Deinitialize(true);
54+
break;
55+
case SDL_MOUSEBUTTONDOWN:
56+
if (event.button.button == SDL_BUTTON_LEFT)
57+
{
58+
int x = event.button.x;
59+
int y = event.button.y;
60+
if (x >= m_ResumeButtonRect.x && x < m_ResumeButtonRect.x + m_ResumeButtonRect.w &&
61+
y >= m_ResumeButtonRect.y && y < m_ResumeButtonRect.y + m_ResumeButtonRect.h)
62+
{
63+
soundHandler->PlaySound(lowUISound);
64+
pauseMenu = false;
65+
}
66+
else if (x >= m_BackToMenuButtonRect.x && x < m_BackToMenuButtonRect.x + m_BackToMenuButtonRect.w &&
67+
y >= m_BackToMenuButtonRect.y && y < m_BackToMenuButtonRect.y + m_BackToMenuButtonRect.h)
68+
{
69+
soundHandler->PlaySound(midUISound);
70+
pauseMenu = false;
71+
running = false;
72+
m_MainMenu->Show(); // Open the main menu
73+
}
74+
}
75+
break;
76+
case SDL_WINDOWEVENT:
77+
if (event.window.event == SDL_WINDOWEVENT_RESIZED)
78+
{
79+
m_ResumeButtonRect = {int(m_GameWindow->GetWidth2()) - 100, int(m_GameWindow->GetHeight2()) - 150, 200, 70};
80+
m_BackToMenuButtonRect = {int(m_GameWindow->GetWidth2()) - 100, int(m_GameWindow->GetHeight2()) + 50, 200, 70};
81+
}
82+
break;
83+
case SDL_KEYDOWN:
84+
SDL_Scancode ScancodeKey = event.key.keysym.scancode;
85+
if (ScancodeKey == SDL_SCANCODE_ESCAPE)
86+
{
87+
soundHandler->PlaySound(lowUISound);
88+
pauseMenu = false;
89+
}
90+
break;
91+
}
92+
}
93+
94+
void PauseMenu::Render()
95+
{
96+
Drawing *render = m_GameWindow->Render();
97+
98+
render->RenderTexture(m_TextureResume->SDLTexture(), nullptr, m_ResumeButtonRect);
99+
render->RenderTexture(m_TextureBack->SDLTexture(), nullptr, m_BackToMenuButtonRect);
100+
}

src/game/interface/PauseMenu.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// src/game/interface/PauseMenu.h
2+
3+
#pragma once
4+
5+
#include "../../GameReference.h"
6+
#include "MainMenu.h"
7+
#include <SDL.h>
8+
9+
class PauseMenu {
10+
private:
11+
GameReference* m_GameWindow;
12+
MainMenu* m_MainMenu;
13+
Texture* m_TextureResume;
14+
Texture* m_TextureBack;
15+
SDL_Rect m_ResumeButtonRect;
16+
SDL_Rect m_BackToMenuButtonRect;
17+
18+
public:
19+
PauseMenu(GameReference* gameWindow, MainMenu* mainMenu);
20+
~PauseMenu();
21+
22+
void Show();
23+
void HandleEvent(const SDL_Event& event, bool& running, bool& menuOpen);
24+
void Render();
25+
};

src/game/interface/SettingsMenu.cpp

Whitespace-only changes.

src/game/interface/SettingsMenu.h

Whitespace-only changes.

0 commit comments

Comments
 (0)