-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
86 lines (70 loc) · 1.98 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
#include <iostream>
#include <curses.h>
#include "ui.h"
#include "game.h"
#include <chrono>
#include "settings_constants.h"
using namespace std;
// microseconds , time taken by one frame to execute - 4 sec
void event_loop(){
// next probem - mainatain the speed
// auto last_time = chrono::system_clock::now();
int dt;
while(true){
auto last_time = chrono::system_clock::now();
erase();
//........... 0.2 seconds , 0.3 -> let's say there is some computation
bool game_over;
game_over = game_logic();
if(game_over)
break;
refresh();
do {
auto current_time = chrono::system_clock::now();
dt = chrono::duration_cast<std::chrono::microseconds>(current_time - last_time).count();
} while(dt < TIME_DELAY_BETWEEN_FRAMES);
// 10 frames - 1 sec
// 1 frame - 0.1 sec
// 100 ms
// 1sec - 10^6 microseconds
// 0.1 -> 10 ^ 5 microseconds
// sleep(100); // sleep of 100 ms (0.1 sec), 1 sec = 1000 ms
// 1 sec - 10 frames / sec
// 1 sec - 3 frames / sec
// bad for a game to have variable fps
}
}
int main(){
init_ui();
event_loop();
tear_down_ui();
cout << "THANKS FOR PLAYING SNAKE GAME! BUT DON\'T BE A SNAKE IN REAL WORLD" << endl;
return 0;
}
// /*
// #############
// # #
// # #
// # #
// # #
// #############
// */
// int width = 20;
// int height = 20;
// for(int i = 0; i < width; i ++){
// cout << "#";
// }
// cout << endl;
// for(int i = 1 ; i < height - 1; i++){
// cout << "#";
// for(int j = 1 ; j < width - 1; j ++){
// cout << " ";
// }
// cout << "#";
// cout << endl;
// }
// //cout << endl;
// for(int i = 0; i < width; i ++){
// cout << "#";
// }
// cout << endl;