-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayGameState.cpp
98 lines (81 loc) · 2.81 KB
/
PlayGameState.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
91
92
93
94
95
96
97
98
#include "PlayGameState.h"
#include <stdio.h>
bool PlayGameState::Init( SDL_Renderer* renderer )
{
gameStateRequest = -1; // -1 = no request
backgroundTexture.LoadFromFile( renderer, "images/backgroundPlay.png" );
playField.LoadTextures( renderer );
playField.SetUpNewGame();
return true;
}
void PlayGameState::Cleanup()
{
}
void PlayGameState::HandleEvent( SDL_Event& e )
{
if ( e.type == SDL_KEYDOWN )
{
if ( playField.GetCurrentState() == FIELD_DESCEND )
{
switch ( e.key.keysym.sym )
{
case SDLK_UP:
printf( "Key press up\n" );
playField.MoveBlock( ROTATE_LEFT );
break;
case SDLK_DOWN:
printf( "Key press down\n" );
if ( !playField.MoveBlock( TRANSLATE_DOWN ) )
playField.PlaceBlock();
break;
case SDLK_LEFT:
printf( "Key press left\n" );
playField.MoveBlock( TRANSLATE_LEFT );
break;
case SDLK_RIGHT:
printf( "Key press right\n" );
playField.MoveBlock( TRANSLATE_RIGHT );
break;
case SDLK_ESCAPE:
printf( "Key press Esc\n" );
gameStateRequest = GAME_TITLE;
break;
default:
break;
}
}
}
}
void PlayGameState::Update()
{
playField.Update();
if ( playField.GetScore() != globalScore )
globalScore = playField.GetScore();
if ( playField.GetCurrentState() == FIELD_GAMEOVER )
gameStateRequest = GAME_SCORE;
}
void PlayGameState::Render( SDL_Renderer* renderer )
{
SDL_SetRenderDrawColor( renderer, 0x00, 0x00, 0x99, 0xFF );
SDL_RenderClear( renderer );
backgroundTexture.Render( renderer, 0, 0 );
const int squareSize = playField.GetSquareSize();
SDL_Rect rects[2];
/*{
SDL_Rect fieldBorderRect = { 38, 38, 10 * squareSize + 4, 20 * squareSize + 4 };
SDL_Rect nextBorderRect = { 38 + 11 * squareSize, 38 + 3 * squareSize, 2 * squareSize + 4, 4 * squareSize + 4 };
rects[0] = fieldBorderRect;
rects[1] = nextBorderRect;
}
SDL_SetRenderDrawColor( renderer, 0x00, 0x80, 0xFF, 0xFF );
SDL_RenderFillRects( renderer, rects, 2 );
{
SDL_Rect fieldRect = { 40, 40, 10 * squareSize, 20 * squareSize };
SDL_Rect nextRect = { 40 + 11 * squareSize, 40 + 3 * squareSize, 2 * squareSize, 4 * squareSize };
rects[0] = fieldRect;
rects[1] = nextRect;
}
SDL_SetRenderDrawColor( renderer, 0x00, 0x00, 0x00, 0xFF );
SDL_RenderFillRects( renderer, rects, 2 );*/
playField.Render( renderer, 40, 40 );
}