Include and link physfs properly.
[tuxanci.git] / src / client / term.c
blobdc4a51b9d3c90d27c11a845923dd054223bfba44
1 #include <stdlib.h>
2 #include <assert.h>
4 #include "main.h"
5 #include "list.h"
6 #include "myTimer.h"
7 #include "tux.h"
8 #include "space.h"
9 #include "arena.h"
11 #include "interface.h"
12 #include "term.h"
13 #include "font.h"
15 static list_t *listText;
16 static bool_t activeTerm;
17 static my_time_t lastActive;
18 static my_time_t lastRefresh;
20 void term_init()
22 listText = list_new();
24 activeTerm = FALSE;
25 lastActive = timer_get_current_time();
26 lastRefresh = lastActive;
29 static char *getStrGun(int gun)
31 switch (gun) {
32 case GUN_SIMPLE:
33 return "revolver";
34 case GUN_DUAL_SIMPLE:
35 return "dual revolver";
36 case GUN_SCATTER:
37 return "scatter";
38 case GUN_TOMMY:
39 return "tommy";
40 case GUN_LASSER:
41 return "lasser";
42 case GUN_MINE:
43 return "mine";
44 case GUN_BOMBBALL:
45 return "bombball";
46 default:
47 return "none";
50 return "gun_unknown";
53 static char *getStrBonus(int bonus)
55 switch (bonus) {
56 case BONUS_SPEED:
57 return "speed";
58 case BONUS_SHOT:
59 return "shot";
60 case BONUS_TELEPORT:
61 return "teleport";
62 case BONUS_GHOST:
63 return "ghost";
64 case BONUS_4X:
65 return "4";
66 case BONUS_HIDDEN:
67 return "hidden";
68 default:
69 return "none";
72 return "bonus_unknown";
75 static void action_refreshTerm(space_t *space, tux_t *tux, void *p)
77 char str[STR_SIZE];
79 sprintf(str,
80 "name: %s "
81 "score: %d "
82 "gun: %s "
83 "shot: %d "
84 "bonus: %s",
85 tux->name, tux->score,
86 getStrGun(tux->gun), tux->shot[tux->gun], getStrBonus(tux->bonus)
89 list_add(listText, strdup(str));
92 static void refreshTerm()
94 arena_t *arena;
96 arena = arena_get_current();
98 list_destroy_item(listText, free);
99 listText = list_new();
101 space_action(arena->spaceTux, action_refreshTerm, NULL);
103 /*printf("refresh term..\n");*/
106 void term_draw()
108 int i;
110 if (activeTerm == FALSE) {
111 return;
114 for (i = 0; i < listText->count; i++) {
115 char *line;
117 line = (char *) listText->list[i];
118 font_draw(line, 10, 10 + i * 20, COLOR_WHITE);
122 static void switchTerm()
124 if (activeTerm == TRUE) {
125 activeTerm = FALSE;
126 } else {
127 activeTerm = TRUE;
131 void term_event()
133 my_time_t currentTime;
134 Uint8 *mapa;
136 mapa = SDL_GetKeyState(NULL);
138 currentTime = timer_get_current_time();
140 if (currentTime - lastRefresh > TERM_REFRESH_TIME_INTERVAL) {
141 lastRefresh = currentTime;
142 refreshTerm();
145 if (mapa[SDLK_TAB] == SDL_PRESSED) {
146 if (currentTime - lastActive > TERM_ACTIVE_TIME_INTERVAL) {
147 lastActive = currentTime;
148 switchTerm();
153 void term_quit()
155 assert(listText != NULL);
156 list_destroy_item(listText, free);