Tetris: Finish TODOs

This commit is contained in:
zvon 2020-09-26 20:23:03 +02:00
parent 883ad19a50
commit eb60c88dac
3 changed files with 24 additions and 17 deletions

View File

@ -1,4 +1,5 @@
// TODO mutex guard instead of lock/unlock // TODO mutex guard instead of lock/unlock
// TODO virtual destructors
#ifndef SDLPP_HPP #ifndef SDLPP_HPP
#define SDLPP_HPP #define SDLPP_HPP

View File

@ -120,7 +120,6 @@ void resetGame() {
g_main_scene->resetScene(); g_main_scene->resetScene();
g_main_scene->setPrevTicks( SDL_GetTicks() ); g_main_scene->setPrevTicks( SDL_GetTicks() );
// TODO maybe move to main thread
g_active_scenes = {g_main_scene}; g_active_scenes = {g_main_scene};
g_input_functions = {mainSceneInput}; g_input_functions = {mainSceneInput};
for(int i = 0; i < 7; i++) for(int i = 0; i < 7; i++)

View File

@ -5,6 +5,18 @@
#include <thread> #include <thread>
constexpr uint64_t MAIN_MENU_RESUME = 0;
constexpr uint64_t MAIN_MENU_OPTIONS = 1;
constexpr uint64_t MAIN_MENU_RESTART = 2;
constexpr uint64_t MAIN_MENU_QUIT = 3;
constexpr uint64_t GAME_OVER_RESTART = 0;
constexpr uint64_t GAME_OVER_QUIT = 1;
constexpr uint64_t OPTIONS_MENU_COLOR_SCHEME = 0;
constexpr uint64_t OPTIONS_MENU_SHADOW = 1;
constexpr uint64_t OPTIONS_MENU_SAVE = 2;
// Scene preparation // Scene preparation
void addMainSceneItems( SDLPP::Scene &scene, std::shared_ptr< SDLPP::Renderer > &r, std::shared_ptr<SDLPP::Font> font ) { void addMainSceneItems( SDLPP::Scene &scene, std::shared_ptr< SDLPP::Renderer > &r, std::shared_ptr<SDLPP::Font> font ) {
@ -455,22 +467,21 @@ void handleKeyDownMenu( SDL_Keycode key ) {
g_menu_options[g_menu_select]->setColor( colors["menu_item_background"] ); g_menu_options[g_menu_select]->setColor( colors["menu_item_background"] );
break; break;
case SDLK_RETURN: case SDLK_RETURN:
// TODO maybe define macros for these
switch ( g_menu_select ) { switch ( g_menu_select ) {
case 0: { case MAIN_MENU_RESUME: {
g_main_scene->setPrevTicks( SDL_GetTicks() ); g_main_scene->setPrevTicks( SDL_GetTicks() );
g_active_scenes.pop_back(); g_active_scenes.pop_back();
g_input_functions.pop_back(); g_input_functions.pop_back();
} break; } break;
case 1: case MAIN_MENU_OPTIONS:
g_options_scene->updateSizeAndPosition(); g_options_scene->updateSizeAndPosition();
g_active_scenes.push_back(g_options_scene); g_active_scenes.push_back(g_options_scene);
g_input_functions.push_back(optionsSceneInput); g_input_functions.push_back(optionsSceneInput);
break; break;
case 2: case MAIN_MENU_RESTART:
resetGame(); resetGame();
break; break;
case 3: case MAIN_MENU_QUIT:
quitGame(); quitGame();
default: default:
break; break;
@ -531,12 +542,11 @@ void handleKeyDownGameOver( SDL_Keycode key ) {
g_game_over_options[g_game_over_select]->setColor( colors["menu_item_background"] ); g_game_over_options[g_game_over_select]->setColor( colors["menu_item_background"] );
break; break;
case SDLK_RETURN: case SDLK_RETURN:
//TODO maybe define macros for these
switch ( g_game_over_select ) { switch ( g_game_over_select ) {
case 0: case GAME_OVER_RESTART:
resetGame(); resetGame();
break; break;
case 1: case GAME_OVER_QUIT:
quitGame(); quitGame();
default: default:
break; break;
@ -605,16 +615,15 @@ void handleKeyDownOptions( SDL_Keycode key ) {
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
case SDLK_d: case SDLK_d:
//TODO define macros
switch( g_options_select ) { switch( g_options_select ) {
case 0: case OPTIONS_MENU_COLOR_SCHEME:
selected_color_scheme++; selected_color_scheme++;
if(selected_color_scheme >= color_schemes_names.size()) if(selected_color_scheme >= color_schemes_names.size())
selected_color_scheme = 0; selected_color_scheme = 0;
std::dynamic_pointer_cast<SDLPP::TextRenderer>(g_options_options[0])->changeText("Color scheme: " + color_schemes_names[selected_color_scheme]); std::dynamic_pointer_cast<SDLPP::TextRenderer>(g_options_options[0])->changeText("Color scheme: " + color_schemes_names[selected_color_scheme]);
g_update_colors = true; g_update_colors = true;
break; break;
case 1: case OPTIONS_MENU_SHADOW:
g_show_shadow = !g_show_shadow; g_show_shadow = !g_show_shadow;
std::dynamic_pointer_cast<SDLPP::TextRenderer>(g_options_options[1])->changeText(std::string("Show shadow: ") + (g_show_shadow ? "YES" : "NO")); std::dynamic_pointer_cast<SDLPP::TextRenderer>(g_options_options[1])->changeText(std::string("Show shadow: ") + (g_show_shadow ? "YES" : "NO"));
g_update_colors = true; g_update_colors = true;
@ -624,16 +633,15 @@ void handleKeyDownOptions( SDL_Keycode key ) {
break; break;
case SDLK_LEFT: case SDLK_LEFT:
case SDLK_a: case SDLK_a:
//TODO define macros
switch( g_options_select ) { switch( g_options_select ) {
case 0: case OPTIONS_MENU_COLOR_SCHEME:
if(selected_color_scheme == 0) if(selected_color_scheme == 0)
selected_color_scheme = color_schemes_names.size(); selected_color_scheme = color_schemes_names.size();
selected_color_scheme--; selected_color_scheme--;
std::dynamic_pointer_cast<SDLPP::TextRenderer>(g_options_options[0])->changeText("Color scheme: " + color_schemes_names[selected_color_scheme]); std::dynamic_pointer_cast<SDLPP::TextRenderer>(g_options_options[0])->changeText("Color scheme: " + color_schemes_names[selected_color_scheme]);
g_update_colors = true; g_update_colors = true;
break; break;
case 1: case OPTIONS_MENU_SHADOW:
g_show_shadow = !g_show_shadow; g_show_shadow = !g_show_shadow;
std::dynamic_pointer_cast<SDLPP::TextRenderer>(g_options_options[1])->changeText(std::string("Show shadow: ") + (g_show_shadow ? "YES" : "NO")); std::dynamic_pointer_cast<SDLPP::TextRenderer>(g_options_options[1])->changeText(std::string("Show shadow: ") + (g_show_shadow ? "YES" : "NO"));
g_update_colors = true; g_update_colors = true;
@ -642,9 +650,8 @@ void handleKeyDownOptions( SDL_Keycode key ) {
} }
break; break;
case SDLK_RETURN: case SDLK_RETURN:
//TODO define macros
switch ( g_options_select ) { switch ( g_options_select ) {
case 2: case OPTIONS_MENU_SAVE:
saveOptions(); saveOptions();
g_active_scenes.pop_back(); g_active_scenes.pop_back();
g_input_functions.pop_back(); g_input_functions.pop_back();