TETRIS: Use FontConfiguration
This commit is contained in:
parent
73f67a3f47
commit
fe675369ea
@ -52,6 +52,7 @@
|
|||||||
#define TETRIS_Z_LEFT 6
|
#define TETRIS_Z_LEFT 6
|
||||||
|
|
||||||
#define PIECE_ACTION_UPDATE_COLOR 0
|
#define PIECE_ACTION_UPDATE_COLOR 0
|
||||||
|
#define PIECE_ACTION_UPDATE_BLOCK 1
|
||||||
|
|
||||||
#define colors color_schemes[color_schemes_names[selected_color_scheme]]
|
#define colors color_schemes[color_schemes_names[selected_color_scheme]]
|
||||||
|
|
||||||
|
@ -34,11 +34,11 @@ public:
|
|||||||
}
|
}
|
||||||
virtual std::shared_ptr< RenderObject > copySelf() override {
|
virtual std::shared_ptr< RenderObject > copySelf() override {
|
||||||
auto ret = std::make_shared< TetrisBlock >( *this );
|
auto ret = std::make_shared< TetrisBlock >( *this );
|
||||||
copyTo(ret);
|
copyTo( ret );
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
virtual void copyTo(std::shared_ptr<RenderObject> other) override {
|
virtual void copyTo( std::shared_ptr< RenderObject > other ) override {
|
||||||
RectangleRender::copyTo(other);
|
RectangleRender::copyTo( other );
|
||||||
}
|
}
|
||||||
std::shared_ptr< TetrisBlock > copyInScene() {
|
std::shared_ptr< TetrisBlock > copyInScene() {
|
||||||
auto ret = std::shared_ptr< TetrisBlock >( new TetrisBlock( *this ) );
|
auto ret = std::shared_ptr< TetrisBlock >( new TetrisBlock( *this ) );
|
||||||
@ -56,13 +56,13 @@ public:
|
|||||||
}
|
}
|
||||||
virtual void specialAction( int code ) override {
|
virtual void specialAction( int code ) override {
|
||||||
switch ( code ) {
|
switch ( code ) {
|
||||||
case PIECE_ACTION_UPDATE_COLOR: {
|
case PIECE_ACTION_UPDATE_COLOR:
|
||||||
setColors();
|
setColors();
|
||||||
|
case PIECE_ACTION_UPDATE_BLOCK:
|
||||||
if ( g_show_3d )
|
if ( g_show_3d )
|
||||||
setTexture( "block.png" );
|
setTexture( "block.png" );
|
||||||
else
|
else
|
||||||
unsetTexture();
|
unsetTexture();
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -414,6 +414,12 @@ void updateSize() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateBlocks() {
|
||||||
|
for ( auto &x : g_main_scene->getObjects( { BRICK_ID, SHADOW_ID } ) ) {
|
||||||
|
x->specialAction( PIECE_ACTION_UPDATE_BLOCK );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void updateColors() {
|
void updateColors() {
|
||||||
for ( auto &x : g_main_scene->getObjects( { BRICK_ID, SHADOW_ID } ) ) {
|
for ( auto &x : g_main_scene->getObjects( { BRICK_ID, SHADOW_ID } ) ) {
|
||||||
x->specialAction( PIECE_ACTION_UPDATE_COLOR );
|
x->specialAction( PIECE_ACTION_UPDATE_COLOR );
|
||||||
@ -430,9 +436,12 @@ void updateColors() {
|
|||||||
for ( auto &x : g_main_scene->getObjects( { LINE_ID } ) ) {
|
for ( auto &x : g_main_scene->getObjects( { LINE_ID } ) ) {
|
||||||
x->setColor( colors["line"] );
|
x->setColor( colors["line"] );
|
||||||
}
|
}
|
||||||
|
if ( g_font_config != nullptr ) {
|
||||||
|
g_font_config->setColor( colors["text"] );
|
||||||
|
g_font_config->setOutlineColor( colors["text_out"] );
|
||||||
for ( auto &x : g_main_scene->getObjects( { TEXT_ID } ) ) {
|
for ( auto &x : g_main_scene->getObjects( { TEXT_ID } ) ) {
|
||||||
static_cast< SDLPP::TextRenderer * >( x.get() )->setTextColor(
|
x->updateSizeAndPosition();
|
||||||
g_font, colors["text"], colors["text_out"], 0.1 );
|
}
|
||||||
}
|
}
|
||||||
g_menu_options[g_menu_select]->setColor( colors["menu_item_background"] );
|
g_menu_options[g_menu_select]->setColor( colors["menu_item_background"] );
|
||||||
g_game_over_options[g_game_over_select]->setColor(
|
g_game_over_options[g_game_over_select]->setColor(
|
||||||
|
@ -33,6 +33,7 @@ std::shared_ptr< TetrisPiece >
|
|||||||
tetrisZLeft( std::shared_ptr< SDLPP::Renderer > renderer,
|
tetrisZLeft( std::shared_ptr< SDLPP::Renderer > renderer,
|
||||||
std::shared_ptr< SDLPP::Scene > scene );
|
std::shared_ptr< SDLPP::Scene > scene );
|
||||||
void updateColors();
|
void updateColors();
|
||||||
|
void updateBlocks();
|
||||||
void updateSize();
|
void updateSize();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,6 +17,7 @@ std::shared_ptr< SDLPP::Renderer > g_active_renderer{};
|
|||||||
int g_score = 0;
|
int g_score = 0;
|
||||||
bool g_update_score = false;
|
bool g_update_score = false;
|
||||||
bool g_update_colors = false;
|
bool g_update_colors = false;
|
||||||
|
bool g_update_3d = false;
|
||||||
bool g_checked_line = false;
|
bool g_checked_line = false;
|
||||||
bool g_wait_for_anim = false;
|
bool g_wait_for_anim = false;
|
||||||
bool g_update_size = false;
|
bool g_update_size = false;
|
||||||
@ -51,3 +52,4 @@ std::vector< std::shared_ptr< TetrisPiece > ( * )(
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr< SDLPP::Font > g_font{};
|
std::shared_ptr< SDLPP::Font > g_font{};
|
||||||
|
std::shared_ptr< SDLPP::FontConfiguration > g_font_config{};
|
||||||
|
@ -23,6 +23,7 @@ extern std::shared_ptr< SDLPP::Renderer > g_active_renderer;
|
|||||||
extern int g_score;
|
extern int g_score;
|
||||||
extern bool g_update_score;
|
extern bool g_update_score;
|
||||||
extern bool g_update_colors;
|
extern bool g_update_colors;
|
||||||
|
extern bool g_update_3d;
|
||||||
extern bool g_checked_line;
|
extern bool g_checked_line;
|
||||||
extern bool g_wait_for_anim;
|
extern bool g_wait_for_anim;
|
||||||
extern bool g_update_size;
|
extern bool g_update_size;
|
||||||
@ -54,5 +55,6 @@ extern std::vector< std::shared_ptr< TetrisPiece > ( * )(
|
|||||||
g_tetrisFunctions;
|
g_tetrisFunctions;
|
||||||
|
|
||||||
extern std::shared_ptr< SDLPP::Font > g_font;
|
extern std::shared_ptr< SDLPP::Font > g_font;
|
||||||
|
extern std::shared_ptr< SDLPP::FontConfiguration > g_font_config;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -21,8 +21,7 @@ constexpr uint64_t OPTIONS_MENU_SAVE = 3;
|
|||||||
// Scene preparation
|
// Scene preparation
|
||||||
|
|
||||||
void addMainSceneItems( SDLPP::Scene &scene,
|
void addMainSceneItems( SDLPP::Scene &scene,
|
||||||
std::shared_ptr< SDLPP::Renderer > &r,
|
std::shared_ptr< SDLPP::Renderer > &r ) {
|
||||||
std::shared_ptr< SDLPP::Font > font ) {
|
|
||||||
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
||||||
0, 0, 10, 10, r, colors["background"], true );
|
0, 0, 10, 10, r, colors["background"], true );
|
||||||
bg->setPermanent();
|
bg->setPermanent();
|
||||||
@ -90,16 +89,15 @@ void addMainSceneItems( SDLPP::Scene &scene,
|
|||||||
scene.addObject( bottom_barrier );
|
scene.addObject( bottom_barrier );
|
||||||
|
|
||||||
auto tetris = std::make_shared< SDLPP::TextRenderer >(
|
auto tetris = std::make_shared< SDLPP::TextRenderer >(
|
||||||
0.4, 0, 0.2, 0.1, r, font, "TETRIS", colors["text"], colors["text_out"],
|
0.4, 0, 0.2, 0.1, r, "TETRIS", g_font_config );
|
||||||
0.1 );
|
|
||||||
tetris->centerX();
|
tetris->centerX();
|
||||||
tetris->setStatic();
|
tetris->setStatic();
|
||||||
tetris->setId( TEXT_ID );
|
tetris->setId( TEXT_ID );
|
||||||
scene.addObject( tetris );
|
scene.addObject( tetris );
|
||||||
|
|
||||||
auto next = std::make_shared< SDLPP::TextRenderer >(
|
auto next = std::make_shared< SDLPP::TextRenderer >(
|
||||||
RIGHT_BORDER + 0.1, 0.35, 0.2, 0.1, r, font, "NEXT", colors["text"],
|
RIGHT_BORDER + 0.1, 0.35, 0.2, 0.1, r, "NEXT", g_font_config,
|
||||||
colors["text_out"], 0.1, SDLPP_TEXT_CENTER );
|
SDLPP_TEXT_CENTER );
|
||||||
next->centerX();
|
next->centerX();
|
||||||
next->setStatic();
|
next->setStatic();
|
||||||
next->setId( TEXT_ID );
|
next->setId( TEXT_ID );
|
||||||
@ -117,16 +115,16 @@ void addMainSceneItems( SDLPP::Scene &scene,
|
|||||||
scene.addObject( gameover );
|
scene.addObject( gameover );
|
||||||
|
|
||||||
auto score_text = std::make_shared< SDLPP::TextRenderer >(
|
auto score_text = std::make_shared< SDLPP::TextRenderer >(
|
||||||
RIGHT_BORDER + 0.1, 0.1, 0.2, 0.1, r, font, "SCORE", colors["text"],
|
RIGHT_BORDER + 0.1, 0.1, 0.2, 0.1, r, "SCORE", g_font_config,
|
||||||
colors["text_out"], 0.1, SDLPP_TEXT_CENTER );
|
SDLPP_TEXT_CENTER );
|
||||||
score_text->centerX();
|
score_text->centerX();
|
||||||
score_text->setStatic();
|
score_text->setStatic();
|
||||||
score_text->setId( TEXT_ID );
|
score_text->setId( TEXT_ID );
|
||||||
scene.addObject( score_text );
|
scene.addObject( score_text );
|
||||||
|
|
||||||
auto score_texture = std::make_shared< SDLPP::TextRenderer >(
|
auto score_texture = std::make_shared< SDLPP::TextRenderer >(
|
||||||
RIGHT_BORDER + 0.1, 0.2, 0.2, 0.1, r, font, "0", colors["text"],
|
RIGHT_BORDER + 0.1, 0.2, 0.2, 0.1, r, "0", g_font_config,
|
||||||
colors["text_out"], 0.1, SDLPP_TEXT_TOP );
|
SDLPP_TEXT_TOP );
|
||||||
score_texture->centerX();
|
score_texture->centerX();
|
||||||
score_texture->setStatic();
|
score_texture->setStatic();
|
||||||
score_texture->setId( SCORE_TEXTURE_ID );
|
score_texture->setId( SCORE_TEXTURE_ID );
|
||||||
@ -161,21 +159,20 @@ void addMainSceneItems( SDLPP::Scene &scene,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void addMenuSceneItems( SDLPP::Scene &scene,
|
void addMenuSceneItems( SDLPP::Scene &scene,
|
||||||
std::shared_ptr< SDLPP::Renderer > &r,
|
std::shared_ptr< SDLPP::Renderer > &r ) {
|
||||||
std::shared_ptr< SDLPP::Font > font ) {
|
|
||||||
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
||||||
0, 0, 10, 10, r, colors["menu_background"], true );
|
0, 0, 10, 10, r, colors["menu_background"], true );
|
||||||
bg->setId( MENU_BACKGROUND_ID );
|
bg->setId( MENU_BACKGROUND_ID );
|
||||||
bg->setPermanent( true );
|
bg->setPermanent( true );
|
||||||
scene.addObject( bg );
|
scene.addObject( bg );
|
||||||
auto y = std::make_shared< SDLPP::TextRenderer >( 0.25, 0.1, 0.5, 0.3, r );
|
auto y = std::make_shared< SDLPP::TextRenderer >( 0.25, 0.1, 0.5, 0.3, r );
|
||||||
y->setText( font, "PAUSED", colors["text"], colors["text_out"], 0.1 );
|
y->setText( "PAUSED", g_font_config );
|
||||||
y->setId( MENU_TEXT_ID );
|
y->setId( MENU_TEXT_ID );
|
||||||
y->centerX();
|
y->centerX();
|
||||||
scene.addObject( y );
|
scene.addObject( y );
|
||||||
auto resume =
|
auto resume =
|
||||||
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.46, 0.2, 0.08, r );
|
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.46, 0.2, 0.08, r );
|
||||||
resume->setText( font, "Resume", colors["text"], colors["text_out"], 0.1 );
|
resume->setText( "Resume", g_font_config );
|
||||||
resume->setColor( colors["menu_item_background"] );
|
resume->setColor( colors["menu_item_background"] );
|
||||||
resume->centerX();
|
resume->centerX();
|
||||||
resume->setId( MENU_ITEM_ID );
|
resume->setId( MENU_ITEM_ID );
|
||||||
@ -183,23 +180,21 @@ void addMenuSceneItems( SDLPP::Scene &scene,
|
|||||||
scene.addObject( resume );
|
scene.addObject( resume );
|
||||||
auto options =
|
auto options =
|
||||||
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.56, 0.2, 0.08, r );
|
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.56, 0.2, 0.08, r );
|
||||||
options->setText( font, "Options", colors["text"], colors["text_out"],
|
options->setText( "Options", g_font_config );
|
||||||
0.1 );
|
|
||||||
options->centerX();
|
options->centerX();
|
||||||
options->setId( MENU_ITEM_ID );
|
options->setId( MENU_ITEM_ID );
|
||||||
g_menu_options.push_back( options );
|
g_menu_options.push_back( options );
|
||||||
scene.addObject( options );
|
scene.addObject( options );
|
||||||
auto restart =
|
auto restart =
|
||||||
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.66, 0.2, 0.08, r );
|
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.66, 0.2, 0.08, r );
|
||||||
restart->setText( font, "Restart", colors["text"], colors["text_out"],
|
restart->setText( "Restart", g_font_config );
|
||||||
0.1 );
|
|
||||||
restart->centerX();
|
restart->centerX();
|
||||||
restart->setId( MENU_ITEM_ID );
|
restart->setId( MENU_ITEM_ID );
|
||||||
g_menu_options.push_back( restart );
|
g_menu_options.push_back( restart );
|
||||||
scene.addObject( restart );
|
scene.addObject( restart );
|
||||||
auto quit =
|
auto quit =
|
||||||
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.76, 0.2, 0.08, r );
|
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.76, 0.2, 0.08, r );
|
||||||
quit->setText( font, "Quit Game", colors["text"], colors["text_out"], 0.1 );
|
quit->setText( "Quit Game", g_font_config );
|
||||||
quit->centerX();
|
quit->centerX();
|
||||||
quit->setId( MENU_ITEM_ID );
|
quit->setId( MENU_ITEM_ID );
|
||||||
g_menu_options.push_back( quit );
|
g_menu_options.push_back( quit );
|
||||||
@ -207,22 +202,20 @@ void addMenuSceneItems( SDLPP::Scene &scene,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void addGameOverSceneItems( SDLPP::Scene &scene,
|
void addGameOverSceneItems( SDLPP::Scene &scene,
|
||||||
std::shared_ptr< SDLPP::Renderer > &r,
|
std::shared_ptr< SDLPP::Renderer > &r ) {
|
||||||
std::shared_ptr< SDLPP::Font > font ) {
|
|
||||||
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
||||||
0, 0, 10, 10, r, colors["menu_background"], true );
|
0, 0, 10, 10, r, colors["menu_background"], true );
|
||||||
bg->setId( MENU_BACKGROUND_ID );
|
bg->setId( MENU_BACKGROUND_ID );
|
||||||
bg->setPermanent( true );
|
bg->setPermanent( true );
|
||||||
scene.addObject( bg );
|
scene.addObject( bg );
|
||||||
auto y = std::make_shared< SDLPP::TextRenderer >( 0.25, 0.1, 0.5, 0.3, r );
|
auto y = std::make_shared< SDLPP::TextRenderer >( 0.25, 0.1, 0.5, 0.3, r );
|
||||||
y->setText( font, "GAME OVER", colors["text"], colors["text_out"], 0.1 );
|
y->setText( "GAME OVER", g_font_config );
|
||||||
y->setId( 0 );
|
y->setId( 0 );
|
||||||
y->centerX();
|
y->centerX();
|
||||||
scene.addObject( y );
|
scene.addObject( y );
|
||||||
auto restart =
|
auto restart =
|
||||||
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.5, 0.2, 0.1, r );
|
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.5, 0.2, 0.1, r );
|
||||||
restart->setText( font, "Restart", colors["text"], colors["text_out"],
|
restart->setText( "Restart", g_font_config );
|
||||||
0.1 );
|
|
||||||
restart->centerX();
|
restart->centerX();
|
||||||
restart->setColor( colors["menu_item_background"] );
|
restart->setColor( colors["menu_item_background"] );
|
||||||
restart->setId( MENU_ITEM_ID );
|
restart->setId( MENU_ITEM_ID );
|
||||||
@ -230,7 +223,7 @@ void addGameOverSceneItems( SDLPP::Scene &scene,
|
|||||||
scene.addObject( restart );
|
scene.addObject( restart );
|
||||||
auto quit =
|
auto quit =
|
||||||
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.7, 0.2, 0.1, r );
|
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.7, 0.2, 0.1, r );
|
||||||
quit->setText( font, "Quit Game", colors["text"], colors["text_out"], 0.1 );
|
quit->setText( "Quit Game", g_font_config );
|
||||||
quit->centerX();
|
quit->centerX();
|
||||||
quit->setId( MENU_ITEM_ID );
|
quit->setId( MENU_ITEM_ID );
|
||||||
g_game_over_options.push_back( quit );
|
g_game_over_options.push_back( quit );
|
||||||
@ -238,23 +231,22 @@ void addGameOverSceneItems( SDLPP::Scene &scene,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void addOptionsSceneItems( SDLPP::Scene &scene,
|
void addOptionsSceneItems( SDLPP::Scene &scene,
|
||||||
std::shared_ptr< SDLPP::Renderer > &r,
|
std::shared_ptr< SDLPP::Renderer > &r ) {
|
||||||
std::shared_ptr< SDLPP::Font > font ) {
|
|
||||||
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
||||||
0, 0, 10, 10, r, colors["menu_background"], true );
|
0, 0, 10, 10, r, colors["menu_background"], true );
|
||||||
bg->setId( MENU_BACKGROUND_ID );
|
bg->setId( MENU_BACKGROUND_ID );
|
||||||
bg->setPermanent( true );
|
bg->setPermanent( true );
|
||||||
scene.addObject( bg );
|
scene.addObject( bg );
|
||||||
auto y = std::make_shared< SDLPP::TextRenderer >( 0.25, 0.1, 0.5, 0.3, r );
|
auto y = std::make_shared< SDLPP::TextRenderer >( 0.25, 0.1, 0.5, 0.3, r );
|
||||||
y->setText( font, "OPTIONS", colors["text"], colors["text_out"], 0.1 );
|
y->setText( "OPTIONS", g_font_config );
|
||||||
y->setId( 0 );
|
y->setId( 0 );
|
||||||
y->centerX();
|
y->centerX();
|
||||||
scene.addObject( y );
|
scene.addObject( y );
|
||||||
auto color_scheme =
|
auto color_scheme =
|
||||||
std::make_shared< SDLPP::TextRenderer >( 0.18, 0.35, 0.64, 0.09, r );
|
std::make_shared< SDLPP::TextRenderer >( 0.18, 0.35, 0.64, 0.09, r );
|
||||||
color_scheme->setText(
|
color_scheme->setText( "Color scheme: " +
|
||||||
font, "Color scheme: " + color_schemes_names[selected_color_scheme],
|
color_schemes_names[selected_color_scheme],
|
||||||
colors["text"], colors["text_out"], 0.1 );
|
g_font_config );
|
||||||
color_scheme->centerX();
|
color_scheme->centerX();
|
||||||
color_scheme->setColor( colors["menu_item_background"] );
|
color_scheme->setColor( colors["menu_item_background"] );
|
||||||
color_scheme->setId( MENU_ITEM_ID );
|
color_scheme->setId( MENU_ITEM_ID );
|
||||||
@ -262,23 +254,21 @@ void addOptionsSceneItems( SDLPP::Scene &scene,
|
|||||||
scene.addObject( color_scheme );
|
scene.addObject( color_scheme );
|
||||||
auto shadow =
|
auto shadow =
|
||||||
std::make_shared< SDLPP::TextRenderer >( 0.26, 0.45, 0.48, 0.09, r );
|
std::make_shared< SDLPP::TextRenderer >( 0.26, 0.45, 0.48, 0.09, r );
|
||||||
shadow->setText( font, "Show shadow: YES", colors["text"],
|
shadow->setText( "Show shadow: YES", g_font_config );
|
||||||
colors["text_out"], 0.1 );
|
|
||||||
shadow->centerX();
|
shadow->centerX();
|
||||||
shadow->setId( MENU_ITEM_ID );
|
shadow->setId( MENU_ITEM_ID );
|
||||||
g_options_options.push_back( shadow );
|
g_options_options.push_back( shadow );
|
||||||
scene.addObject( shadow );
|
scene.addObject( shadow );
|
||||||
auto show3d =
|
auto show3d =
|
||||||
std::make_shared< SDLPP::TextRenderer >( 0.2, 0.55, 0.6, 0.09, r );
|
std::make_shared< SDLPP::TextRenderer >( 0.2, 0.55, 0.6, 0.09, r );
|
||||||
show3d->setText( font, "Show block texture: NO", colors["text"],
|
show3d->setText( "Show block texture: NO", g_font_config );
|
||||||
colors["text_out"], 0.1 );
|
|
||||||
show3d->centerX();
|
show3d->centerX();
|
||||||
show3d->setId( MENU_ITEM_ID );
|
show3d->setId( MENU_ITEM_ID );
|
||||||
g_options_options.push_back( show3d );
|
g_options_options.push_back( show3d );
|
||||||
scene.addObject( show3d );
|
scene.addObject( show3d );
|
||||||
auto save =
|
auto save =
|
||||||
std::make_shared< SDLPP::TextRenderer >( 0.42, 0.65, 0.16, 0.09, r );
|
std::make_shared< SDLPP::TextRenderer >( 0.42, 0.65, 0.16, 0.09, r );
|
||||||
save->setText( font, "SAVE", colors["text"], colors["text_out"], 0.1 );
|
save->setText( "SAVE", g_font_config );
|
||||||
save->centerX();
|
save->centerX();
|
||||||
save->setId( MENU_ITEM_ID );
|
save->setId( MENU_ITEM_ID );
|
||||||
g_options_options.push_back( save );
|
g_options_options.push_back( save );
|
||||||
@ -286,34 +276,30 @@ void addOptionsSceneItems( SDLPP::Scene &scene,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr< SDLPP::Scene >
|
std::shared_ptr< SDLPP::Scene >
|
||||||
prepareMainScene( std::shared_ptr< SDLPP::Renderer > renderer,
|
prepareMainScene( std::shared_ptr< SDLPP::Renderer > renderer ) {
|
||||||
std::shared_ptr< SDLPP::Font > font ) {
|
|
||||||
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
||||||
addMainSceneItems( *scene, renderer, font );
|
addMainSceneItems( *scene, renderer );
|
||||||
return scene;
|
return scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr< SDLPP::Scene >
|
std::shared_ptr< SDLPP::Scene >
|
||||||
prepareMenuScene( std::shared_ptr< SDLPP::Renderer > renderer,
|
prepareMenuScene( std::shared_ptr< SDLPP::Renderer > renderer ) {
|
||||||
std::shared_ptr< SDLPP::Font > font ) {
|
|
||||||
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
||||||
addMenuSceneItems( *scene, renderer, font );
|
addMenuSceneItems( *scene, renderer );
|
||||||
return scene;
|
return scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr< SDLPP::Scene >
|
std::shared_ptr< SDLPP::Scene >
|
||||||
prepareGameOverScene( std::shared_ptr< SDLPP::Renderer > renderer,
|
prepareGameOverScene( std::shared_ptr< SDLPP::Renderer > renderer ) {
|
||||||
std::shared_ptr< SDLPP::Font > font ) {
|
|
||||||
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
||||||
addGameOverSceneItems( *scene, renderer, font );
|
addGameOverSceneItems( *scene, renderer );
|
||||||
return scene;
|
return scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr< SDLPP::Scene >
|
std::shared_ptr< SDLPP::Scene >
|
||||||
prepareOptionsScene( std::shared_ptr< SDLPP::Renderer > renderer,
|
prepareOptionsScene( std::shared_ptr< SDLPP::Renderer > renderer ) {
|
||||||
std::shared_ptr< SDLPP::Font > font ) {
|
|
||||||
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
||||||
addOptionsSceneItems( *scene, renderer, font );
|
addOptionsSceneItems( *scene, renderer );
|
||||||
return scene;
|
return scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,7 +641,6 @@ void gameOverSceneInput(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void saveOptions() {
|
void saveOptions() {
|
||||||
g_update_colors = true;
|
|
||||||
if ( g_cur_shadow )
|
if ( g_cur_shadow )
|
||||||
g_cur_shadow->setHidden( !g_show_shadow );
|
g_cur_shadow->setHidden( !g_show_shadow );
|
||||||
g_main_scene->setPrevTicks( SDL_GetTicks() );
|
g_main_scene->setPrevTicks( SDL_GetTicks() );
|
||||||
@ -715,6 +700,7 @@ void handleKeyDownOptions( SDL_Keycode key ) {
|
|||||||
g_options_options[OPTIONS_MENU_3D].get() )
|
g_options_options[OPTIONS_MENU_3D].get() )
|
||||||
->changeText( std::string( "Show block texture: " ) +
|
->changeText( std::string( "Show block texture: " ) +
|
||||||
( g_show_3d ? "YES" : "NO" ) );
|
( g_show_3d ? "YES" : "NO" ) );
|
||||||
|
g_update_3d = true;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -745,6 +731,7 @@ void handleKeyDownOptions( SDL_Keycode key ) {
|
|||||||
g_options_options[OPTIONS_MENU_3D].get() )
|
g_options_options[OPTIONS_MENU_3D].get() )
|
||||||
->changeText( std::string( "Show block texture: " ) +
|
->changeText( std::string( "Show block texture: " ) +
|
||||||
( g_show_3d ? "YES" : "NO" ) );
|
( g_show_3d ? "YES" : "NO" ) );
|
||||||
|
g_update_3d = true;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,13 @@
|
|||||||
#include "../sdlpp/sdlpp.hpp"
|
#include "../sdlpp/sdlpp.hpp"
|
||||||
|
|
||||||
std::shared_ptr< SDLPP::Scene >
|
std::shared_ptr< SDLPP::Scene >
|
||||||
prepareMainScene( std::shared_ptr< SDLPP::Renderer > renderer,
|
prepareMainScene( std::shared_ptr< SDLPP::Renderer > renderer );
|
||||||
std::shared_ptr< SDLPP::Font > font );
|
|
||||||
std::shared_ptr< SDLPP::Scene >
|
std::shared_ptr< SDLPP::Scene >
|
||||||
prepareMenuScene( std::shared_ptr< SDLPP::Renderer > renderer,
|
prepareMenuScene( std::shared_ptr< SDLPP::Renderer > renderer );
|
||||||
std::shared_ptr< SDLPP::Font > font );
|
|
||||||
std::shared_ptr< SDLPP::Scene >
|
std::shared_ptr< SDLPP::Scene >
|
||||||
prepareGameOverScene( std::shared_ptr< SDLPP::Renderer > renderer,
|
prepareGameOverScene( std::shared_ptr< SDLPP::Renderer > renderer );
|
||||||
std::shared_ptr< SDLPP::Font > font );
|
|
||||||
std::shared_ptr< SDLPP::Scene >
|
std::shared_ptr< SDLPP::Scene >
|
||||||
prepareOptionsScene( std::shared_ptr< SDLPP::Renderer > renderer,
|
prepareOptionsScene( std::shared_ptr< SDLPP::Renderer > renderer );
|
||||||
std::shared_ptr< SDLPP::Font > font );
|
|
||||||
|
|
||||||
void mainSceneInput(
|
void mainSceneInput(
|
||||||
std::shared_ptr< SDLPP::Scene > scene, int base,
|
std::shared_ptr< SDLPP::Scene > scene, int base,
|
||||||
|
@ -61,16 +61,18 @@ int main() {
|
|||||||
|
|
||||||
g_font = std::make_shared< SDLPP::Font >( "testfont.ttf", 36 );
|
g_font = std::make_shared< SDLPP::Font >( "testfont.ttf", 36 );
|
||||||
|
|
||||||
g_main_scene = prepareMainScene( renderer, g_font );
|
g_font_config = std::make_shared< SDLPP::FontConfiguration >(
|
||||||
|
g_font, colors["text"], colors["text_out"], 0.1 );
|
||||||
|
g_main_scene = prepareMainScene( renderer );
|
||||||
line_coliders = g_main_scene->getObjects( { COLIDER_ID } );
|
line_coliders = g_main_scene->getObjects( { COLIDER_ID } );
|
||||||
g_score_texture = std::dynamic_pointer_cast< SDLPP::TextRenderer >(
|
g_score_texture = std::dynamic_pointer_cast< SDLPP::TextRenderer >(
|
||||||
g_main_scene->getObjects( { SCORE_TEXTURE_ID } )[0] );
|
g_main_scene->getObjects( { SCORE_TEXTURE_ID } )[0] );
|
||||||
g_active_scenes.push_back( g_main_scene );
|
g_active_scenes.push_back( g_main_scene );
|
||||||
g_main_scene->saveScene();
|
g_main_scene->saveScene();
|
||||||
|
|
||||||
g_menu_scene = prepareMenuScene( renderer, g_font );
|
g_menu_scene = prepareMenuScene( renderer );
|
||||||
g_game_over_scene = prepareGameOverScene( renderer, g_font );
|
g_game_over_scene = prepareGameOverScene( renderer );
|
||||||
g_options_scene = prepareOptionsScene( renderer, g_font );
|
g_options_scene = prepareOptionsScene( renderer );
|
||||||
|
|
||||||
auto base = SDL_GetTicks();
|
auto base = SDL_GetTicks();
|
||||||
int frames = 0;
|
int frames = 0;
|
||||||
@ -137,6 +139,10 @@ int main() {
|
|||||||
updateColors();
|
updateColors();
|
||||||
g_update_colors = false;
|
g_update_colors = false;
|
||||||
}
|
}
|
||||||
|
if ( g_update_3d ) {
|
||||||
|
updateBlocks();
|
||||||
|
g_update_3d = false;
|
||||||
|
}
|
||||||
if ( g_update_size ) {
|
if ( g_update_size ) {
|
||||||
updateSize();
|
updateSize();
|
||||||
g_update_size = false;
|
g_update_size = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user