-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
86 lines (63 loc) · 1.73 KB
/
main.c
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 <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <ncurses.h>
#include "statemachine.h"
#include "states.h"
#include "input.h"
#include "const.h"
#include "encounters.h"
#include "audio.h"
void runGame() {
struct timeval curr_time;
struct timespec sleep_time;
sleep_time.tv_sec = 0;
sleep_time.tv_nsec = 3000000;
uint64_t last_time;
gettimeofday(&curr_time, NULL);
last_time = curr_time.tv_sec * 1000000 + curr_time.tv_usec;
input_init();
audio_init();
game_t *game_state = (game_t *) malloc(sizeof(game_t));
sm_init(game_state);
states_init();
encounters_init();
sm_set_state(STATE_MENU);
int i = 0;
init_pair(PAIR_GREEN, COLOR_GREEN, COLOR_BLACK);
init_pair(PAIR_BLUE, COLOR_BLUE, COLOR_BLACK);
init_pair(PAIR_CYAN, COLOR_CYAN, COLOR_BLACK);
init_pair(PAIR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
init_pair(PAIR_RED, COLOR_RED, COLOR_BLACK);
init_pair(PAIR_WHITE, COLOR_WHITE, COLOR_BLACK);
init_pair(PAIR_SELECTION_OFF, COLOR_YELLOW, COLOR_BLACK);
init_pair(PAIR_SELECTION_ON, COLOR_BLACK, COLOR_YELLOW);
while (true) {
gettimeofday(&curr_time, NULL);
uint64_t curr = curr_time.tv_sec * 1000000 + curr_time.tv_usec;
float delta = (float) (curr - last_time);
last_time = curr;
input_run();
sm_run(delta);
if (game_state->exit)
{
break;
}
refresh();
nanosleep(&sleep_time, NULL);
}
}
int main(int argc, char **argv)
{
srand(time(NULL));
stdscr = initscr();
curs_set(0);
start_color();
nodelay(stdscr, TRUE);
keypad(stdscr, TRUE);
noecho();
runGame();
endwin();
return 0;
}