-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
104 lines (78 loc) · 1.81 KB
/
Main.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
99
100
101
102
103
104
/*Dmangames 2021*/
//Using SDL, SDL_image, standard IO, and strings
#include <SDL.h>
#include <SDL_image.h>
#include <stdio.h>
#include <string>
#include <SDL_ttf.h>
#include "InputHandler.h"
#include <stdlib.h>
#include <time.h>
#include "Graphics.h"
#include "World.h"
#include "AStar.hpp"
#include <iostream>
enum GameState {
MAIN_MENU,
IN_GAME,
GAME_OVER,
TEST
};
void mainMenu() {
}
int main(int argc, char* args[])
{
InputHandler inputs;
Graphics graphics;
World world(graphics.get_width(), graphics.get_height());
//Game state
GameState gameState = MAIN_MENU;
//GameState gameState = TEST;
//Main loop flag
bool quit = false;
//Event handler
SDL_Event e;
//While application is running
while (!quit)
{
switch (gameState) {
case MAIN_MENU:
//Handle events on queue
while (SDL_PollEvent(&e) != 0)
{
graphics.render_mainmenu();
graphics.present_renderer();
//User requests quit
if (e.type == SDL_QUIT)
{
quit = true;
}
//User pressed any button while in main menu
else if (e.type == SDL_KEYDOWN && gameState == MAIN_MENU) {
if (e.key.keysym.sym == SDLK_SPACE)
gameState = IN_GAME;
}
}
break;
case IN_GAME:
inputs.update();
quit = inputs.get_quit();
world.update(&inputs);
graphics.clear_screen();
graphics.render_tiles(world.get_map(), world.get_delta(), world.get_camera());
graphics.render_actors(world.get_actors(), world.get_delta(), world.get_camera());
graphics.render_players(world.get_players(), world.get_delta(), world.get_camera());
graphics.render_overlay();
graphics.present_renderer(world.get_delta());
break;
case TEST:
inputs.update();
quit = inputs.get_quit();
world.update(&inputs);
break;
default:
break;
}
}
return 0;
}