-
Notifications
You must be signed in to change notification settings - Fork 0
/
TitleGameState.cpp
90 lines (73 loc) · 2.29 KB
/
TitleGameState.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "TitleGameState.h"
#include <stdio.h>
#include <SDL2/SDL_ttf.h>
bool TitleGameState::Init( SDL_Renderer* renderer )
{
gameStateRequest = -1; // -1 = no request
backgroundTexture.LoadFromFile( renderer, "images/backgroundTitle.png" );
TTF_Font* loadedFont = TTF_OpenFont( "the_first_fontstruction.ttf", 72 );
if( loadedFont == NULL )
{
printf( "Failed to load font. SDL_ttf error: %s\n", TTF_GetError() );
printf( "Failed to load media for title state.\n" );
return false;
}
if( !titleTexture.LoadFromRenderedText( renderer, "TETRIS CLONE", { 0xFF, 0xFF, 0xFF, 0x00 }, loadedFont ) )
return false;
TTF_CloseFont( loadedFont );
loadedFont = NULL;
titleMenu.LoadTextures( renderer );
return true;
}
void TitleGameState::Cleanup()
{
}
void TitleGameState::HandleEvent( SDL_Event& e )
{
if ( e.type == SDL_KEYDOWN )
{
switch ( e.key.keysym.sym )
{
case SDLK_UP:
printf( "Key press up\n" );
titleMenu.ChangeOption( MOVE_UP );
break;
case SDLK_DOWN:
printf( "Key press down\n" );
titleMenu.ChangeOption( MOVE_DOWN );
break;
case SDLK_RETURN:
printf( "Key press return\n" );
switch ( titleMenu.GetCurrentOption() )
{
case MENU_PLAY:
printf( "'Play' selected\n" );
gameStateRequest = GAME_PLAY;
break;
case MENU_SCORE:
printf( "'Score' selected\n" );
gameStateRequest = GAME_SCORE;
break;
case MENU_QUIT:
printf( "'Quit' selected\n" );
gameStateRequest = GAME_QUIT;
break;
default:
printf( "Invalid menu option!\n" );
}
default:
break;
}
}
}
void TitleGameState::Update()
{
}
void TitleGameState::Render( SDL_Renderer* renderer )
{
SDL_SetRenderDrawColor( renderer, 0x00, 0x00, 0x99, 0xFF );
SDL_RenderClear( renderer );
backgroundTexture.Render( renderer, 0, 0 );
titleTexture.Render( renderer, 50, 30 );
titleMenu.Render( renderer, 80, 140 );
}