Skip to content

Commit d44be05

Browse files
committed
Changed main code to use the UserInput and Renderer code
1 parent b21ab37 commit d44be05

File tree

4 files changed

+46
-44
lines changed

4 files changed

+46
-44
lines changed

include/UserInput.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
#include "GameBoard.h"
77
#include "Player.h"
88

9-
void acceptInput(GameBoard& board, Player& turn, SDL_Event& event);
9+
bool acceptInput(GameBoard& board, Player& turn, SDL_Event& event);
1010

1111
#endif

src/Renderer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#include "Renderer.h"
22

3+
#include <GL/gl.h>
4+
35
#include "GameBoard.h"
46
#include "Player.h"
57

68
void renderBoard(GameBoard& board, Player& perspective) {
9+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
710

11+
glFlush();
812
}

src/UserInput.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@
55
#include "GameBoard.h"
66
#include "Player.h"
77

8-
void acceptInput(GameBoard& board, Player& turn, SDL_Event& event) {
8+
bool handleMouseButtonEvent(const SDL_MouseButtonEvent& event) {
99

10-
}
10+
return true;
11+
}
12+
13+
bool handleKeyboardEvent(const SDL_KeyboardEvent& event) {
14+
15+
return true;
16+
}
17+
18+
bool handleQuitEvent(const SDL_QuitEvent& event) {
19+
return false;
20+
}
21+
22+
// Returns true if the program should continue running, false if it should exit
23+
bool acceptInput(GameBoard& board, Player& turn, SDL_Event& event) {
24+
switch(event.type) {
25+
case SDL_MOUSEBUTTONDOWN:
26+
case SDL_MOUSEBUTTONUP:
27+
return handleMouseButtonEvent(event.button);
28+
case SDL_KEYUP:
29+
case SDL_KEYDOWN:
30+
return handleKeyboardEvent(event.key);
31+
case SDL_QUIT:
32+
return handleQuitEvent(event.quit);
33+
}
34+
return true;
35+
}

src/main.cpp

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
#include <iostream>
1111
#include <utility>
1212

13+
#include "GameBoard.h"
14+
#include "UserInput.h"
15+
#include "Player.h"
16+
#include "Renderer.h"
17+
1318
void initGame() {
1419

1520
}
@@ -33,43 +38,6 @@ int updateViewport(int width, int height) {
3338
glMatrixMode(GL_MODELVIEW);
3439
}
3540

36-
bool handleMouseButtonEvent(const SDL_MouseButtonEvent& event) {
37-
38-
return true;
39-
}
40-
41-
bool handleKeyboardEvent(const SDL_KeyboardEvent& event) {
42-
43-
return true;
44-
}
45-
46-
bool handleQuitEvent(const SDL_QuitEvent& event) {
47-
return false;
48-
}
49-
50-
// Returns true if the program should continue running, false if it should exit
51-
bool handleEvent(const SDL_Event& event) {
52-
switch(event.type) {
53-
case SDL_MOUSEBUTTONDOWN:
54-
case SDL_MOUSEBUTTONUP:
55-
return handleMouseButtonEvent(event.button);
56-
case SDL_KEYUP:
57-
case SDL_KEYDOWN:
58-
return handleKeyboardEvent(event.key);
59-
case SDL_QUIT:
60-
return handleQuitEvent(event.quit);
61-
}
62-
return true;
63-
}
64-
65-
void render(SDL_Window* displayWindow) {
66-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
67-
68-
glFlush();
69-
SDL_GL_SwapWindow(displayWindow);
70-
}
71-
72-
7341
int main(int argc, char *argv[]) {
7442
SDL_Init(SDL_INIT_VIDEO);
7543
SDL_Window* displayWindow;
@@ -86,18 +54,23 @@ int main(int argc, char *argv[]) {
8654

8755
SDL_GLContext glContext = SDL_GL_CreateContext(displayWindow);
8856

89-
initGame();
9057
initOpenGL();
9158

92-
updateViewport(800, 600);
59+
updateViewport(1024, 768);
60+
61+
Player testPlayer;
62+
GameBoard testBoard;
9363

9464
bool running = true;
9565
while(running) {
9666
SDL_Event event;
9767
while(SDL_PollEvent(&event)) {
98-
running = handleEvent(event);
68+
running = acceptInput(testBoard, testPlayer, event);
9969
}
100-
render(displayWindow);
70+
71+
72+
73+
SDL_GL_SwapWindow(displayWindow);
10174
SDL_Delay(100);
10275
}
10376

0 commit comments

Comments
 (0)