-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c74adf7
commit c4cdb03
Showing
9 changed files
with
326 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "entry.h" | ||
#include "ui.h" | ||
#include "renderer.h" | ||
#include "audio.h" | ||
#include "leaderboard.h" | ||
#include "style.h" | ||
|
||
namespace ltrm | ||
{ | ||
|
||
int EntryScene::s_Score = 0; | ||
|
||
EntryScene::EntryScene() | ||
{ | ||
|
||
} | ||
|
||
EntryScene::~EntryScene() | ||
{ | ||
|
||
} | ||
|
||
void EntryScene::Load() | ||
{ | ||
|
||
} | ||
|
||
void EntryScene::Unload() | ||
{ | ||
|
||
} | ||
|
||
void EntryScene::Update() | ||
{ | ||
Renderer::Clear(Color::Accent); | ||
|
||
UI::Text("Enter your name!", Renderer::GetWidth() / 2, Renderer::GetHeight() / 2 - 200, 1.2f); | ||
float width = UI::TiledTextWidth(m_Word.length() >= 3 ? m_Word.length() : 3); | ||
UI::TiledText(m_Word, (Renderer::GetWidth() - width) / 2, Renderer::GetHeight() / 2, 1, m_Word.length() >= 3 ? m_Word.length() : 3); | ||
} | ||
|
||
void EntryScene::KeyDown(SDL_Keycode key) | ||
{ | ||
if (isalpha(key)) | ||
{ | ||
char c = m_Word.length() == 0 ? SDL_toupper(key) : SDL_tolower(key); | ||
m_Word.push_back(c); | ||
UI::PulseLastTile(); | ||
Mixer::Pop(); | ||
return; | ||
} | ||
|
||
if (key == SDLK_BACKSPACE) | ||
{ | ||
if (m_Word.length() == 0) return; | ||
m_Word.pop_back(); | ||
Mixer::Pop(); | ||
} | ||
|
||
if (key == SDLK_RETURN) | ||
{ | ||
LeaderboardScene::AddEntry(m_Word, s_Score); | ||
Mixer::Pop(); | ||
SceneManager::ChangeScene("leaderboard"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "scene.h" | ||
|
||
#include <SDL3/SDL.h> | ||
|
||
namespace ltrm | ||
{ | ||
|
||
class EntryScene : public Scene | ||
{ | ||
public: | ||
EntryScene(); | ||
~EntryScene(); | ||
|
||
void Load(); | ||
void Unload(); | ||
void Update(); | ||
void KeyDown(SDL_Keycode key); | ||
|
||
static void SetScore(int score) { s_Score = score; } | ||
|
||
private: | ||
std::string m_Word; | ||
|
||
static int s_Score; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#include "leaderboard.h" | ||
#include "ui.h" | ||
#include "renderer.h" | ||
#include "style.h" | ||
#include "level.h" | ||
|
||
namespace ltrm | ||
{ | ||
|
||
std::list<LeaderboardScene::Entry> LeaderboardScene::s_Entries; | ||
|
||
LeaderboardScene::LeaderboardScene() | ||
{ | ||
AddEntry("James", 70); | ||
AddEntry("Wes", 84); | ||
} | ||
|
||
LeaderboardScene::~LeaderboardScene() | ||
{ | ||
|
||
} | ||
|
||
void LeaderboardScene::Load() | ||
{ | ||
m_LastTime = SDL_GetTicks(); | ||
} | ||
|
||
void LeaderboardScene::Unload() | ||
{ | ||
|
||
} | ||
|
||
void LeaderboardScene::Update() | ||
{ | ||
float time = SDL_GetTicks(); | ||
m_PulseTime += time - m_LastTime; | ||
m_LastTime = time; | ||
|
||
if (m_PulseTime >= 3000.0f) | ||
{ | ||
m_PulseTime = 0; | ||
UI::PulseTiles(); | ||
} | ||
|
||
Renderer::Clear(Color::Accent); | ||
UI::TiledText(std::string("LEADERBOARD"), Renderer::GetWidth() / 2, Style::SmallMargin + Style::TileSize / 2, 2); | ||
|
||
float y = Renderer::GetHeight() / 2 + 2 * (150 + Style::SmallMargin); | ||
if (UI::Button("Back", Renderer::GetWidth() / 2, y + 100, false)) | ||
{ | ||
SceneManager::ChangeScene("main"); | ||
} | ||
|
||
float panelWidth = 800; | ||
float panelHeight = 600; | ||
float panelX = (Renderer::GetWidth() - panelWidth) / 2; | ||
float panelY = (Renderer::GetHeight() - panelHeight) / 2; | ||
Renderer::Fill(Color::Dark); | ||
Renderer::Stroke(Color::Middle); | ||
Renderer::StrokeWeight(5); | ||
Renderer::Rect(panelX, panelY, panelWidth, panelHeight); | ||
|
||
float textHeight; | ||
y = panelY + 100 + textHeight / 2; | ||
UI::TextSize("Level Complete!", nullptr, &textHeight, 1.2f); | ||
UI::Text("Scores", Renderer::GetWidth() / 2, y, 1.2f); | ||
|
||
float x = Renderer::GetWidth() / 2; | ||
float height; | ||
UI::TextSize("1.", nullptr, &height, 0.75f); | ||
|
||
size_t place = 1; | ||
y += Style::SmallMargin; | ||
for (auto& entry : s_Entries) | ||
{ | ||
y += height + Style::SmallMargin; | ||
std::string s = std::to_string(place).append(". ").append(entry.Name).append(": ").append(std::to_string(entry.Score)); | ||
UI::Text(s.c_str(), x, y, 0.75f); | ||
place++; | ||
} | ||
} | ||
|
||
void LeaderboardScene::KeyDown(SDL_Keycode key) | ||
{ | ||
|
||
} | ||
|
||
void LeaderboardScene::AddEntry(const std::string &name, int score) | ||
{ | ||
size_t i = 0; | ||
for (auto& entry : s_Entries) | ||
{ | ||
if (entry.Name == name) | ||
{ | ||
entry.Score = (entry.Score < score) ? entry.Score : score; | ||
return; | ||
} | ||
|
||
if (entry.Score >= score) | ||
{ | ||
std::list<Entry>::iterator it = s_Entries.begin(); | ||
std::advance(it, i); | ||
s_Entries.emplace(it, name, score); | ||
LevelScene::Reset(); | ||
return; | ||
} | ||
i++; | ||
} | ||
|
||
std::list<Entry>::iterator it = s_Entries.begin(); | ||
std::advance(it, i); | ||
s_Entries.emplace(it, name, score); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
#include "scene.h" | ||
|
||
#include <SDL3/SDL.h> | ||
#include <string> | ||
#include <list> | ||
|
||
namespace ltrm | ||
{ | ||
|
||
class LeaderboardScene : public Scene | ||
{ | ||
struct Entry | ||
{ | ||
std::string Name; | ||
int Score; | ||
|
||
Entry(const std::string& name, int score) | ||
: Name(name), Score(score) {} | ||
}; | ||
|
||
public: | ||
LeaderboardScene(); | ||
~LeaderboardScene(); | ||
|
||
void Load(); | ||
void Unload(); | ||
void Update(); | ||
void KeyDown(SDL_Keycode key); | ||
|
||
static void AddEntry(const std::string& name, int score); | ||
|
||
private: | ||
float m_LastTime = 0, m_PulseTime = 0; | ||
|
||
static std::list<Entry> s_Entries; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.