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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
#include <stdlib.h>
#include <assert.h>
#include "main.h"
#include "list.h"
#include "myTimer.h"
#include "tux.h"
#include "space.h"
#include "arena.h"
#include "interface.h"
#include "term.h"
#include "font.h"
static list_t *listText;
static bool_t activeTerm;
static my_time_t lastActive;
static my_time_t lastRefresh;
void initTerm()
{
listText = newList();
activeTerm = FALSE;
lastActive = getMyTime();
lastRefresh = lastActive;
}
static char *getStrGun(int gun)
{
switch (gun) {
case GUN_SIMPLE:
return "revolver";
case GUN_DUAL_SIMPLE:
return "dual revolver";
case GUN_SCATTER:
return "scatter";
case GUN_TOMMY:
return "tommy";
case GUN_LASSER:
return "lasser";
case GUN_MINE:
return "mine";
case GUN_BOMBBALL:
return "bombball";
default:
return "none";
}
return "gun_unknow";
}
static char *getStrBonus(int bonus)
{
switch (bonus) {
case BONUS_SPEED:
return "speed";
case BONUS_SHOT:
return "shot";
case BONUS_TELEPORT:
return "teleport";
case BONUS_GHOST:
return "ghost";
case BONUS_4X:
return "4X";
case BONUS_HIDDEN:
return "hidden";
default:
return "none";
}
return "bonus_unknow";
}
static void action_refreshTerm(space_t * space, tux_t * tux, void *p)
{
char str[STR_SIZE];
sprintf(str,
"name: %s "
"score: %d "
"gun: %s "
"shot: %d "
"bonus: %s",
tux->name, tux->score,
getStrGun(tux->gun), tux->shot[tux->gun], getStrBonus(tux->bonus)
);
addList(listText, strdup(str));
}
static void refreshTerm()
{
arena_t *arena;
arena = getCurrentArena();
destroyListItem(listText, free);
listText = newList();
actionSpace(arena->spaceTux, action_refreshTerm, NULL);
//printf("refresh term..\n");
}
void drawTerm()
{
int i;
if (activeTerm == FALSE) {
return;
}
for (i = 0; i < listText->count; i++) {
char *line;
line = (char *) listText->list[i];
drawFont(line, 10, 10 + i * 20, COLOR_WHITE);
}
}
static void switchTerm()
{
if (activeTerm == TRUE) {
activeTerm = FALSE;
} else {
activeTerm = TRUE;
}
}
void eventTerm()
{
my_time_t currentTime;
Uint8 *mapa;
mapa = SDL_GetKeyState(NULL);
currentTime = getMyTime();
if (currentTime - lastRefresh > TERM_REFRESH_TIME_INTERVAL) {
lastRefresh = currentTime;
refreshTerm();
}
if (mapa[SDLK_TAB] == SDL_PRESSED) {
if (currentTime - lastActive > TERM_ACTIVE_TIME_INTERVAL) {
lastActive = currentTime;
switchTerm();
}
}
}
void quitTerm()
{
assert(listText != NULL);
destroyListItem(listText, free);
}
|