2020-06-27 08:21:47 +08:00
|
|
|
#include <stdio.h>
|
2020-06-12 09:46:44 +08:00
|
|
|
#include <ncurses.h>
|
2020-06-24 09:51:30 +08:00
|
|
|
// Delay and timing.
|
2020-06-12 09:46:44 +08:00
|
|
|
#include <unistd.h>
|
2020-06-18 08:44:21 +08:00
|
|
|
#include <time.h>
|
2020-06-24 09:51:30 +08:00
|
|
|
// math
|
|
|
|
#include <math.h>
|
|
|
|
// game
|
|
|
|
#include "game.h"
|
2020-07-01 09:01:52 +08:00
|
|
|
#include "log.h"
|
2020-07-10 06:58:17 +08:00
|
|
|
#include "ui.h"
|
2020-06-12 09:46:44 +08:00
|
|
|
|
2020-06-22 07:58:05 +08:00
|
|
|
|
2020-06-12 09:46:44 +08:00
|
|
|
int main()
|
|
|
|
{
|
2020-06-19 05:26:14 +08:00
|
|
|
// framerate of the game
|
2020-06-23 09:34:29 +08:00
|
|
|
const int FRAME_RATE = 30;
|
2020-06-22 07:58:05 +08:00
|
|
|
const float FRAME_TIME = 1.f/(float)FRAME_RATE;
|
2020-06-12 09:46:44 +08:00
|
|
|
|
2020-07-10 06:58:17 +08:00
|
|
|
startLog("log.txt");
|
2020-06-24 21:27:24 +08:00
|
|
|
initGame();
|
2020-06-23 09:34:29 +08:00
|
|
|
|
2020-06-22 07:58:05 +08:00
|
|
|
float t = 0;
|
2020-06-24 09:51:30 +08:00
|
|
|
while (isRunning()) {
|
2020-06-18 08:44:21 +08:00
|
|
|
clock_t start_t = clock();
|
|
|
|
char ch = getch();
|
|
|
|
|
2020-06-22 07:58:05 +08:00
|
|
|
handleInput(ch);
|
|
|
|
|
2020-06-24 21:27:24 +08:00
|
|
|
drawGame();
|
2020-07-10 06:58:17 +08:00
|
|
|
//drawLastPressed(ch);
|
2020-06-24 21:27:24 +08:00
|
|
|
drawCurPos();
|
2020-07-10 06:58:17 +08:00
|
|
|
drawUI();
|
2020-06-24 21:27:24 +08:00
|
|
|
|
|
|
|
refresh();
|
2020-06-24 11:05:49 +08:00
|
|
|
|
2020-06-24 21:27:24 +08:00
|
|
|
updateGame();
|
2020-06-12 09:46:44 +08:00
|
|
|
|
2020-06-22 07:58:05 +08:00
|
|
|
usleep(pow(10,6)*(FRAME_TIME-t));
|
2020-07-05 20:47:00 +08:00
|
|
|
t = (float) (clock()-start_t) / (float) CLOCKS_PER_SEC;
|
2020-06-12 09:46:44 +08:00
|
|
|
}
|
|
|
|
|
2020-07-10 06:58:17 +08:00
|
|
|
endUI();
|
2020-06-27 08:21:47 +08:00
|
|
|
endGame();
|
2020-07-01 09:01:52 +08:00
|
|
|
endLog();
|
2020-06-12 09:46:44 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|