-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.cpp
More file actions
75 lines (57 loc) · 1.36 KB
/
Copy pathgame.cpp
File metadata and controls
75 lines (57 loc) · 1.36 KB
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
#include "game.h"
Game::Game(){
window = new sf::RenderWindow(sf::VideoMode(1200, 760), "S_01");
window->SetFramerateLimit(60);
event_h = new Event_Handler(window);
game_state = new Game_States(MENU);
menu.init();
ingame_menu.init();
*game_state = MENU;
pause_if_in_menu = true;
ctr=0;
}
void Game::run(){
while (window->IsOpened()){
//std::cout << ctr << '\n';
if (ctr == 4) ctr=0; else ctr++;
event_h->update();
if (ctr == 0) window->Clear(sf::Color(20, 20, 50));
update();
if (ctr == 0) window->Display();
}
}
void Game::update(){
switch (*game_state) {
case MENU:
//std::cout << "in menuloop\n";
menuloop();
break;
case IN_GAME:
//std::cout << "in gameloop\n";
gameloop();
break;
case IN_GAME_MENU:
//std::cout << "in ingame menuloop\n";
if (pause_if_in_menu) gameloop();
ingame_menuloop();
break;
}
}
void Game::menuloop(){
//if(event_h->pollCh('a')) *game_state = IN_GAME;
menu.update(game_state, event_h, window);
menu.draw(window);
if(*game_state == IN_GAME) session = new Session(window, event_h);
}
void Game::gameloop(){
if(event_h->pollSp('E')){
*game_state = IN_GAME_MENU;
}
session->update();
if (ctr == 0) session->draw();
}
void Game::ingame_menuloop(){
ingame_menu.update(game_state, event_h, window);
ingame_menu.draw(window);
if(*game_state == MENU) delete session;
}