Compare commits
9 Commits
c85b335478
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| e2a787ab2f | |||
| 7ecd47f20c | |||
| 095dbfb0b9 | |||
| 2f0c9ad012 | |||
| 6fa0475acf | |||
| 3d461163d3 | |||
| c9809a934f | |||
| e08f8be87d | |||
| db921e3390 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -7,3 +7,6 @@ build/
|
|||||||
|
|
||||||
# Vscode
|
# Vscode
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
|
# ImGui
|
||||||
|
**/imgui.ini
|
||||||
21
README.md
Normal file
21
README.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Perfect Ear
|
||||||
|
|
||||||
|
Train your ears to recognize piano notes !
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|
[[screenshots/success.png]]
|
||||||
|
|
||||||
|
[[screenshots/failure.png]]
|
||||||
|
|
||||||
|
## Build ⚙️
|
||||||
|
|
||||||
|
```bash
|
||||||
|
xmake # xmake will download all the required dependencies
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run 🏃
|
||||||
|
|
||||||
|
```bash
|
||||||
|
xmake run
|
||||||
|
```
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace ph {
|
namespace ph {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
|
|
||||||
void Render();
|
bool Render();
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
BIN
screenshots/failure.png
Normal file
BIN
screenshots/failure.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
BIN
screenshots/success.png
Normal file
BIN
screenshots/success.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
@@ -5,12 +5,12 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define DISABLED_COND(code, cond) \
|
#define DISABLED_COND(cond, ...) \
|
||||||
{ \
|
{ \
|
||||||
bool Disabled = cond; \
|
bool Disabled = (cond); \
|
||||||
if (Disabled) \
|
if (Disabled) \
|
||||||
ImGui::BeginDisabled(); \
|
ImGui::BeginDisabled(); \
|
||||||
code if (Disabled) ImGui::EndDisabled(); \
|
__VA_ARGS__ if (Disabled) ImGui::EndDisabled(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,11 +65,10 @@ static void RenderGameWindow() {
|
|||||||
ImGui::Text("Quelle est la note ?");
|
ImGui::Text("Quelle est la note ?");
|
||||||
|
|
||||||
DISABLED_COND(
|
DISABLED_COND(
|
||||||
if (ImGui::Button("Réécouter")) {
|
!Hint, if (ImGui::Button("Réécouter")) {
|
||||||
audio::PlayNote(Answer);
|
audio::PlayNote(Answer);
|
||||||
Hint = false;
|
Hint = false;
|
||||||
},
|
})
|
||||||
!Hint)
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Voir la réponse")) {
|
if (ImGui::Button("Voir la réponse")) {
|
||||||
@@ -84,10 +83,8 @@ static void RenderGameWindow() {
|
|||||||
Right = false;
|
Right = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cooldown > 0.0)
|
DISABLED_COND(
|
||||||
ImGui::BeginDisabled();
|
Cooldown > 0.0f, for (int i = 0; i < NoteCount; i++) {
|
||||||
|
|
||||||
for (int i = 0; i < NoteCount; i++) {
|
|
||||||
ImVec4 color = (i == Ab || i == Bb || i == Db || i == Eb || i == Gb) ? ImVec4{0, 0, 0, 1} : ImVec4{0.5, .5, .5, 1};
|
ImVec4 color = (i == Ab || i == Bb || i == Db || i == Eb || i == Gb) ? ImVec4{0, 0, 0, 1} : ImVec4{0.5, .5, .5, 1};
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, color);
|
ImGui::PushStyleColor(ImGuiCol_Button, color);
|
||||||
bool green = (ShowAnswer && i == Answer);
|
bool green = (ShowAnswer && i == Answer);
|
||||||
@@ -107,28 +104,32 @@ static void RenderGameWindow() {
|
|||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
}
|
})
|
||||||
|
|
||||||
if (Cooldown > 0.0)
|
|
||||||
ImGui::EndDisabled();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RenderMainWindow() {
|
static bool RenderMainWindow() {
|
||||||
if (ImGui::Button("Nouvelle Partie")) {
|
if (ImGui::Button("Nouvelle Partie")) {
|
||||||
InGame = true;
|
InGame = true;
|
||||||
Right = true;
|
Right = true;
|
||||||
}
|
}
|
||||||
if (ImGui::Button("Quitter")) {}
|
if (ImGui::Button("Quitter")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render() {
|
bool Render() {
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||||
ImGui::Begin("MainWindow", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration);
|
ImGui::Begin("MainWindow", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration);
|
||||||
if (InGame)
|
if (InGame)
|
||||||
RenderGameWindow();
|
RenderGameWindow();
|
||||||
else
|
else {
|
||||||
RenderMainWindow();
|
if (!RenderMainWindow()) {
|
||||||
|
ImGui::End();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Cooldown > 0.0f) {
|
if (Cooldown > 0.0f) {
|
||||||
ImGui::NewLine();
|
ImGui::NewLine();
|
||||||
@@ -143,6 +144,8 @@ void Render() {
|
|||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
ImGui::ShowDemoWindow();
|
ImGui::ShowDemoWindow();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init() {}
|
void Init() {}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ int main(int, char**) {
|
|||||||
// io.Fonts->GetGlyphRangesJapanese()); IM_ASSERT(font != nullptr);
|
// io.Fonts->GetGlyphRangesJapanese()); IM_ASSERT(font != nullptr);
|
||||||
|
|
||||||
ImFontConfig cfg;
|
ImFontConfig cfg;
|
||||||
cfg.SizePixels = 30;
|
cfg.SizePixels = 40;
|
||||||
io.Fonts->AddFontDefault(&cfg);
|
io.Fonts->AddFontDefault(&cfg);
|
||||||
|
|
||||||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||||
@@ -146,7 +146,10 @@ int main(int, char**) {
|
|||||||
ImGui_ImplSDL2_NewFrame();
|
ImGui_ImplSDL2_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
ph::gui::Render();
|
if (!done && !ph::gui::Render()) {
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
add_rules("mode.debug", "mode.release")
|
add_rules("mode.debug", "mode.release")
|
||||||
|
|
||||||
add_requires("libsdl")
|
add_requires("libsdl2_mixer 2.8.1")
|
||||||
add_requires("libsdl_mixer", {system = true})
|
add_requires("imgui v1.91.8", {configs = {sdl2 = true, opengl3 = true}})
|
||||||
add_requires("imgui", {configs = {sdl2 = true, opengl3 = true}})
|
|
||||||
|
|
||||||
target("PerfectHear")
|
target("PerfectHear")
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
add_files("src/*.cpp")
|
add_files("src/*.cpp")
|
||||||
add_includedirs("include")
|
add_includedirs("include")
|
||||||
|
|
||||||
add_packages("libsdl", "libsdl_mixer", "imgui")
|
add_packages("libsdl2", "libsdl2_mixer", "imgui")
|
||||||
|
|
||||||
if is_os("windows") then
|
if is_plat("mingw") then
|
||||||
add_ldflags("-static")
|
add_ldflags("-static")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user