- Timestamp:
- Nov 9, 2003, 2:32:04 PM (19 years ago)
- Location:
- ttyvaders/trunk
- Files:
-
- 1 added
- 1 deleted
- 12 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
ttyvaders/trunk/libee/Makefile.am
r86 r90 16 16 17 17 lib_LIBRARIES = libee.a 18 libee_a_SOURCES = ee.c ee.h 18 libee_a_SOURCES = ee.c ee.h io.c math.c 19 19 libee_a_CPPFLAGS = $(CPPFLAGS_slang) $(CPPFLAGS_ncurses) 20 20 -
ttyvaders/trunk/libee/ee.c
r84 r90 205 205 } 206 206 207 char ee_get_key(void)208 {209 #ifdef USE_SLANG210 if(SLang_input_pending(0))211 {212 return SLang_getkey();213 }214 #elif USE_NCURSES215 char key = getch();216 217 if(key != ERR)218 {219 return key;220 }221 #else222 return 0;223 224 #endif225 226 return 0;227 }228 -
ttyvaders/trunk/libee/ee.h
r80 r90 73 73 char ee_get_key(void); 74 74 75 int ee_rand(int, int); 76 int ee_sqrt(int); 77 -
ttyvaders/trunk/libee/io.c
r87 r90 23 23 #include "config.h" 24 24 25 #include <stdlib.h>26 #include <unistd.h>27 #include <string.h>28 #include <sys/time.h>29 #include <time.h>30 31 25 #include "ee.h" 32 33 int ee_init(void)34 {35 #ifdef USE_SLANG36 static char * colors[] = { "black", "green", "yellow", "white",37 "red", "gray", "lightgray", "blue", "cyan", "magenta", NULL };38 int i;39 40 /* Initialize slang library */41 SLsig_block_signals();42 SLtt_get_terminfo();43 44 if(SLkp_init() == -1)45 {46 SLsig_unblock_signals();47 return -1;48 }49 50 SLang_init_tty(-1, 0, 1);51 52 if(SLsmg_init_smg() == -1)53 {54 SLsig_unblock_signals();55 return -1;56 }57 58 SLsig_unblock_signals();59 60 SLsmg_cls();61 SLtt_set_cursor_visibility(0);62 SLsmg_refresh();63 64 for(i = 0; colors[i]; i++)65 {66 SLtt_set_color(i + 1, NULL, colors[i], "black");67 }68 69 #elif USE_NCURSES70 /* Initialize ncurses library */71 initscr();72 keypad(stdscr, TRUE);73 nonl();74 cbreak();75 noecho();76 nodelay(stdscr, TRUE);77 curs_set(0);78 79 start_color();80 81 init_pair(EE_BLACK, COLOR_BLACK, COLOR_BLACK);82 init_pair(EE_GREEN, COLOR_GREEN, COLOR_BLACK);83 init_pair(EE_YELLOW, COLOR_YELLOW, COLOR_BLACK);84 init_pair(EE_WHITE, COLOR_WHITE, COLOR_BLACK);85 init_pair(EE_RED, COLOR_RED, COLOR_BLACK);86 init_pair(EE_GRAY, COLOR_WHITE, COLOR_BLACK); // XXX87 init_pair(EE_LIGHTGRAY, COLOR_WHITE, COLOR_BLACK); // XXX88 init_pair(EE_BLUE, COLOR_BLUE, COLOR_BLACK);89 init_pair(EE_CYAN, COLOR_CYAN, COLOR_BLACK);90 init_pair(EE_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);91 92 #else93 /* Dummy driver */94 95 #endif96 97 return 0;98 }99 100 int ee_get_width(void)101 {102 #ifdef USE_SLANG103 return SLtt_Screen_Cols;104 #elif USE_NCURSES105 return COLS;106 #else107 return 80;108 #endif109 }110 111 int ee_get_height(void)112 {113 #ifdef USE_SLANG114 return SLtt_Screen_Rows;115 #elif USE_NCURSES116 return LINES;117 #else118 return 25;119 #endif120 }121 122 void ee_clear(void)123 {124 #if defined(USE_SLANG) || defined(USE_NCURSES)125 /* We could use SLsmg_cls(), but drawing empty lines is much faster */126 int x = ee_get_width(), y = ee_get_height();127 char *empty_line = malloc((x + 1) * sizeof(char));128 129 memset(empty_line, ' ', x);130 empty_line[x] = '\0';131 132 while(y--)133 {134 ee_goto(0, y);135 ee_putstr(empty_line);136 }137 138 free(empty_line);139 #else140 /* Use dummy driver */141 #endif142 }143 144 static int64_t local_time(void)145 {146 struct timeval tv;147 int64_t now;148 149 gettimeofday(&tv, NULL);150 now = tv.tv_sec;151 now *= 1000000;152 now += tv.tv_usec;153 return now;154 }155 156 #define DELAY 40000157 void ee_refresh(void)158 {159 static int64_t local_clock = 0;160 int64_t now;161 162 ee_goto(0, 0);163 164 if(!local_clock)165 {166 /* Initialize local_clock */167 local_clock = local_time();168 }169 170 if(local_time() > local_clock + 10000)171 {172 /* If we are late, we shouldn't display anything */173 }174 175 #ifdef USE_SLANG176 SLsmg_refresh();177 #elif USE_NCURSES178 refresh();179 #else180 /* Use dummy driver */181 #endif182 183 now = local_time();184 185 if(now < local_clock + DELAY - 10000)186 {187 usleep(local_clock + DELAY - 10000 - now);188 }189 190 local_clock += DELAY;191 }192 193 void ee_end(void)194 {195 #ifdef USE_SLANG196 SLtt_set_cursor_visibility(1);197 SLang_reset_tty();198 SLsmg_reset_smg();199 #elif USE_NCURSES200 curs_set(1);201 endwin();202 #else203 /* Use dummy driver */204 #endif205 }206 26 207 27 char ee_get_key(void) -
ttyvaders/trunk/src/Makefile.am
r80 r90 28 28 explosions.c \ 29 29 main.c \ 30 math.c \31 30 overlay.c \ 32 31 player.c \ -
ttyvaders/trunk/src/aliens.c
r88 r90 73 73 add_explosion(g, g->ex, al->x[i], al->y[i], 0, 0, EXPLOSION_MEDIUM); 74 74 al->type[i] = ALIEN_NONE; 75 add_bonus(g, g->bo, al->x[i], al->y[i], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE);75 add_bonus(g, g->bo, al->x[i], al->y[i], ee_rand(0,5) ? BONUS_GREEN : BONUS_LIFE); 76 76 } 77 77 -
ttyvaders/trunk/src/collide.c
r88 r90 126 126 { 127 127 add_explosion(g, ex, GET_MIN(t->left[y-j], x+3), y-j, 0, 1, EXPLOSION_SMALL); 128 t->left[y-j] -= GET_RAND(0,3);128 t->left[y-j] -= ee_rand(0,3); 129 129 } 130 130 else if(x + 3 >= t->right[y-j]) 131 131 { 132 132 add_explosion(g, ex, GET_MAX(t->right[y-j], x-2), y-j, 0, 1, EXPLOSION_SMALL); 133 t->right[y-j] += GET_RAND(0,3);133 t->right[y-j] += ee_rand(0,3); 134 134 } 135 135 } -
ttyvaders/trunk/src/common.h
r88 r90 48 48 * Useful macros 49 49 */ 50 #define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))51 50 #define GET_MAX(a,b) ((a)>(b)?(a):(b)) 52 51 #define GET_MIN(a,b) ((a)<(b)?(a):(b)) … … 188 187 189 188 /* 190 * From math.c191 */192 int r00t(int);193 194 /*195 189 * From overlay.c 196 190 */ -
ttyvaders/trunk/src/explosions.c
r88 r90 74 74 ee_color(GREEN); 75 75 ee_goto(ex->x[i] + 3, ex->y[i]); 76 switch( GET_RAND(0,3))76 switch(ee_rand(0,3)) 77 77 { 78 78 case 0: -
ttyvaders/trunk/src/main.c
r88 r90 183 183 184 184 /* XXX: to be removed */ 185 if( GET_RAND(0,10) == 0)185 if(ee_rand(0,10) == 0) 186 186 { 187 187 int list[3] = { ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ }; 188 188 189 add_alien(g, g->al, 0, rand() % g->h / 2, list[ GET_RAND(0,3)]);189 add_alien(g, g->al, 0, rand() % g->h / 2, list[ee_rand(0,3)]); 190 190 } 191 191 -
ttyvaders/trunk/src/starfield.c
r88 r90 34 34 for(i = 0; i < STARS; i++) 35 35 { 36 s[i].x = GET_RAND(0, g->w);37 s[i].y = GET_RAND(0, g->h);38 s[i].z = GET_RAND(1, 4);39 s[i].c = GET_RAND(6, 8);40 s[i].ch = GET_RAND(0, 2) ? '.' : '\'';36 s[i].x = ee_rand(0, g->w); 37 s[i].y = ee_rand(0, g->h); 38 s[i].z = ee_rand(1, 4); 39 s[i].c = ee_rand(6, 8); 40 s[i].ch = ee_rand(0, 2) ? '.' : '\''; 41 41 } 42 42 … … 67 67 if(s[i].x < 0) 68 68 { 69 s[i].x = GET_RAND(0, g->w);69 s[i].x = ee_rand(0, g->w); 70 70 s[i].y = 0; 71 s[i].z = GET_RAND(1, 3);72 s[i].c = GET_RAND(6, 8);73 s[i].ch = GET_RAND(0, 2) ? '.' : '\'';71 s[i].z = ee_rand(1, 3); 72 s[i].c = ee_rand(6, 8); 73 s[i].ch = ee_rand(0, 2) ? '.' : '\''; 74 74 } 75 75 else if(s[i].y < g->h-1) -
ttyvaders/trunk/src/tunnel.c
r88 r90 170 170 171 171 /* Generate new values */ 172 i = delta[ GET_RAND(0,6)];173 j = delta[ GET_RAND(0,6)];172 i = delta[ee_rand(0,6)]; 173 j = delta[ee_rand(0,6)]; 174 174 175 175 /* Check in which direction we need to alter tunnel */ -
ttyvaders/trunk/src/weapons.c
r88 r90 173 173 if(dx | dy) 174 174 { 175 int norm = r00t(dx * dx + 4 * dy * dy);175 int norm = ee_sqrt(dx * dx + 4 * dy * dy); 176 176 dx = dx * 32 / norm; 177 177 dy = dy * 32 / norm; … … 185 185 if(dx | dy) 186 186 { 187 int norm = r00t(dx * dx + 4 * dy * dy);187 int norm = ee_sqrt(dx * dx + 4 * dy * dy); 188 188 wp->vx[i] = dx * 32 / norm; 189 189 wp->vy[i] = dy * 32 / norm;
Note: See TracChangeset
for help on using the changeset viewer.