-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.cpp
119 lines (103 loc) · 3.19 KB
/
gui.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "gui.h"
#include <ncurses.h>
#include <stdio.h>
namespace openage {
namespace tubepong {
std::vector<event> &Gui::getInputs(const PongPlayer &player) {
input_cache.clear();
event evnt;
evnt.player = player.id;
evnt.state = event::IDLE;
timeout(0);
int c = getch();
//mvprintw(0,1, "IN: %i", c);
switch (c) {
case KEY_DOWN:
evnt.state = event::DOWN;
input_cache.push_back(evnt);
mvprintw(1,1, "DOWN");
break;
case KEY_UP:
evnt.state = event::UP;
input_cache.push_back(evnt);
mvprintw(1,1, "UP");
break;
case ' ':
evnt.state = event::START;
break;
default:
break;
}
return input_cache;
}
enum {
COLOR_PLAYER1 = 1,
COLOR_PLAYER2 = 2,
COLOR_BALL = 3,
COLOR_DEBUG = 4,
};
Gui::Gui() {
initscr();
start_color();
init_pair(COLOR_PLAYER1, COLOR_BLUE,COLOR_BLUE);
init_pair(COLOR_PLAYER2, COLOR_RED,COLOR_RED);
init_pair(COLOR_BALL , COLOR_BLUE,COLOR_WHITE);
init_pair(COLOR_DEBUG , COLOR_WHITE,COLOR_BLACK);
keypad(stdscr,true);
noecho();
curs_set(0);
// getmaxyx(stdscr,state.resolution[1], state.resolution[0]);
attron(COLOR_PAIR(COLOR_DEBUG));
mvprintw(4,5," oooooooooo ");
mvprintw(5,5," 888 888 ooooooo ooooooo oooooooo8 ");
mvprintw(6,5," 888oooo88 888 888 888 888 888 88o ");
mvprintw(7,5," 888 888 888 888 888 888oo888o ");
mvprintw(8,5," o888o 88ooo88 o888o o888o 88 888 ");
mvprintw(9,5," 888ooo888 ");
attroff(COLOR_PAIR(COLOR_DEBUG));
getch();
}
void Gui::draw(PongState &state, const tube::tube_time_t &now) {
erase();
// clear();
//Print Score
attron(COLOR_PAIR(COLOR_DEBUG));
getmaxyx(stdscr, state.resolution[1], state.resolution[0]);
attron(COLOR_PAIR(COLOR_DEBUG));
mvprintw(2, state.resolution[0]/2-5, "P1 %i | P2 %i",
state.p1.lives(now),
state.p2.lives(now));
mvvline(0, state.resolution[0]/2, ACS_VLINE, state.resolution[1]);
mvprintw(0, 1, "NOW: %f", now);
mvprintw(1, 1, "SCR: %i | %i", state.resolution[0], state.resolution[1]);
mvprintw(2, 1, "P1: %f, %f, %i", state.p1.position(now), state.p1.y, state.p1.state(now).state);
mvprintw(3, 1, "P2: %f, %f, %i", state.p2.position(now), state.p2.y, state.p2.state(now).state);
for (int i = 0; i < 1000; i += 100) {
mvprintw(4 + i / 100, 1, "BALL in %03i: %f | %f; SPEED: %f | %f",
i,
state.ball.position(now + i)[0],
state.ball.position(now + i)[1],
state.ball.speed(now + i)[0],
state.ball.speed(now + i)[1]);
}
attroff(COLOR_PAIR(COLOR_DEBUG));
attron(COLOR_PAIR(COLOR_PLAYER1));
for(int i=-state.p1.size(now) / 2; i < state.p1.size(now) / 2; i++) {
mvprintw(state.p1.position(now)+i,
state.p1.y,"|");
}
attroff(COLOR_PAIR(COLOR_PLAYER1));
attron(COLOR_PAIR(COLOR_PLAYER2));
for(int i=-state.p2.size(now) / 2; i < state.p2.size(now) / 2; i++) {
mvprintw(state.p2.position(now)+i,
state.p2.y,"|");
}
attroff(COLOR_PAIR(COLOR_PLAYER2));
attron(COLOR_PAIR(COLOR_BALL));
mvprintw(state.ball.position(now)[1],
state.ball.position(now)[0],
"o");
attroff(COLOR_PAIR(COLOR_BALL));
refresh();
}
}} // openage::tubepong