-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
82 lines (65 loc) · 1.66 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
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <ncurses.h>
#include <math.h>
#include "draw.h"
#define MOVE_SPEED 2.0
#define ROT_SPEED 0.1
int upPressed = 0;
int main(int argc, char *argv[])
{
// seed random
srand(0);
init_terminal();
if (!has_colors()) {
reset_terminal();
printf("error: terminal does not support color\n");
exit(1);
}
init_pair(1, COLOR_BLUE, COLOR_BLACK);
init_pair(2, COLOR_GREEN, COLOR_BLACK);
init_pair(3, COLOR_WHITE, COLOR_BLACK);
//cbreak();
//noecho();
//nodelay(stdscr, TRUE);
//timeout(100);
scrollok(stdscr, TRUE);
Screen scr;
while(1) {
scr.draw();
int key = getch();
//std::cout << std::endl << key << std::endl;
if(key == 'q' || key == 'Q') {
break;
}
if(key == 'r') {
scr.randomizeLight();
continue;
}
float theta = scr.camRot;
if(key == 258) { // down
scr.camPos.z -= cos(theta)*MOVE_SPEED;
scr.camPos.x += sin(theta)*MOVE_SPEED;
}else if(key == 259) { // up
scr.camPos.z += cos(theta)*MOVE_SPEED;
scr.camPos.x -= sin(theta)*MOVE_SPEED;
}else if(key == 260) { // left
scr.camRot += ROT_SPEED;
}else if(key == 261) { // right
scr.camRot -= ROT_SPEED;
}else if(key == 97) { // a
scr.camPos.z -= sin(theta)*MOVE_SPEED;
scr.camPos.x -= cos(theta)*MOVE_SPEED;
}else if(key == 100) { // d
scr.camPos.z += sin(theta)*MOVE_SPEED;
scr.camPos.x += cos(theta)*MOVE_SPEED;
}else if(key == 119) { // w
scr.camPos.y -= MOVE_SPEED;
}else if(key == 115) { // s
scr.camPos.y += MOVE_SPEED;
}
}
reset_terminal();
return 0;
}