2
2
// Created by shehbaz on 12/6/2023.
3
3
//
4
4
5
-
6
-
7
5
#include < algorithm>
8
6
9
7
#include " Game.h"
10
8
#include " Grid.h"
11
9
#include " Cell.h"
12
10
#include " DrawComponent.h"
13
11
12
+ #define RAYGUI_IMPLEMENTATION
13
+ #include " raygui.h"
14
+
14
15
Game::Game (int screenWidth, int screenHeight, const char *title)
15
16
:mScreenWidth(screenWidth)
16
17
,mScreenHeight(screenHeight)
17
18
,mTitle(title)
18
19
,mIsRunning(true )
20
+ ,mGameState(INITIAL)
21
+ ,mGrid(nullptr )
19
22
{
20
23
}
21
24
@@ -38,7 +41,10 @@ void Game::RunGame()
38
41
39
42
void Game::ProcessInput ()
40
43
{
41
- mGrid ->ProcessInput (GetMouseX (), GetMouseY ());
44
+ if (mGameState == PLAYING)
45
+ {
46
+ mGrid ->ProcessInput (GetMouseX (), GetMouseY ());
47
+ }
42
48
}
43
49
44
50
void Game::UpdateGame ()
@@ -52,10 +58,43 @@ void Game::UpdateGame()
52
58
void Game::GenerateOutput ()
53
59
{
54
60
BeginDrawing ();
55
- ClearBackground (LIGHTGRAY);
56
- for ( auto drawCom : mDraws )
61
+ // Display menu screen according to game state
62
+ switch ( mGameState )
57
63
{
58
- drawCom->Draw ();
64
+ case INITIAL:
65
+ {
66
+ float buttonWidth = 300 .f , buttonHeight = 100 .f ;
67
+ float padding = 75 .f ;
68
+ ClearBackground (DARKGRAY);
69
+ GuiSetStyle (DEFAULT, TEXT_SIZE, 40 );
70
+ GuiSetStyle (DEFAULT, TEXT_SPACING, 10 );
71
+ GuiSetStyle (BUTTON, BASE_COLOR_NORMAL, 0x000000FF );
72
+ if (GuiButton ({ (mScreenWidth / 2 .f ) - (buttonWidth / 2 .f ),
73
+ (mScreenHeight / 2 .f ) - (buttonHeight / 2 .f ) - padding,
74
+ buttonWidth,
75
+ buttonHeight },
76
+ " START" ))
77
+ {
78
+ printf (" START GAME!\n " );
79
+ mGameState = PLAYING;
80
+ }
81
+ if (GuiButton ({ (mScreenWidth / 2 .f ) - (buttonWidth / 2 .f ),
82
+ (mScreenHeight / 2 .f ) - (buttonHeight / 2 .f ) + buttonHeight,
83
+ buttonWidth,
84
+ buttonHeight },
85
+ " EXIT" ))
86
+ {
87
+ printf (" EXIT GAME!\n " );
88
+ mIsRunning = false ;
89
+ }
90
+ }
91
+ break ;
92
+ case PLAYING:
93
+ ClearBackground (LIGHTGRAY);
94
+ for (auto drawCom : mDraws )
95
+ {
96
+ drawCom->Draw ();
97
+ }
59
98
}
60
99
EndDrawing ();
61
100
}
@@ -97,10 +136,8 @@ void Game::RemoveDraw(class DrawComponent *mesh)
97
136
}
98
137
}
99
138
100
- bool Game::IsRunning ()
139
+ bool Game::IsRunning () const
101
140
{
102
- // We can use this method to close the game window with additional conditions
103
- mIsRunning = !WindowShouldClose ();
104
141
return mIsRunning ;
105
142
}
106
143
0 commit comments