Changeset 49 for libcaca/trunk
- Timestamp:
- Dec 23, 2002, 10:28:37 AM (20 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/TODO
r31 r49 9 9 * sprite library 10 10 11 *mega ball11 DONE 23 Dec 2002: mega ball 12 12 13 13 * spiral weapon (vertical sine) 14 14 15 *fragmentation bomb (merge with mega-ball?)15 DONE 23 Dec 2002: fragmentation bomb (merge with mega-ball?) 16 16 17 17 * stick aliens to tunnel … … 31 31 * promote precision for all coordinates except screen 32 32 33 *tunnel sometimes doesn't get drawn on the left33 DONE Dec 19 2002: tunnel sometimes doesn't get drawn on the left 34 34 35 35 * write a generic drawing library with automatic clipping … … 39 39 * animate the ship 40 40 41 * the nuke should break the tunnel 42 -
libcaca/trunk/src/collide.c
r41 r49 4 4 * All Rights Reserved 5 5 * 6 * $Id: collide.c,v 1. 7 2002/12/22 22:17:41sam Exp $6 * $Id: collide.c,v 1.8 2002/12/23 09:28:37 sam Exp $ 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify … … 27 27 void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) 28 28 { 29 int i, x, y;29 int i, j, x, y; 30 30 31 31 for( i = 0; i < WEAPONS; i++ ) … … 77 77 break; 78 78 case WEAPON_LASER: 79 if( x <= t->left[y+1] 80 || x >= t->right[y+1] ) 81 { 82 add_explosion( g, ex, x, y+1, 0, 1, EXPLOSION_SMALL ); 83 84 if( x <= t->left[y+1] ) 85 { 86 t->left[y]--; 87 t->left[y+1]-=2; 88 t->left[y+2]--; 89 } 90 else 91 { 92 t->right[y]++; 93 t->right[y+1]+=2; 94 t->right[y+2]++; 95 } 96 97 wp->type[i] = WEAPON_NONE; 98 } 99 else if( x <= t->left[y] 100 || x >= t->right[y] ) 101 { 102 add_explosion( g, ex, x, y, 0, 1, EXPLOSION_SMALL ); 103 104 if( x <= t->left[y] ) 105 { 106 t->left[y-1]--; 107 t->left[y]-=2; 108 t->left[y+1]--; 109 } 110 else 111 { 112 t->right[y-1]++; 113 t->right[y]+=2; 114 t->right[y+1]++; 115 } 116 117 wp->type[i] = WEAPON_NONE; 118 } 119 break; 79 for( j = GET_MIN( 0, wp->vy[i] >> 4 ) ; 80 j < GET_MAX( 0, wp->vy[i] >> 4 ) ; 81 j++ ) 82 { 83 if( x <= t->left[y+j] || x >= t->right[y+j] ) 84 { 85 add_explosion( g, ex, x, y+j, 0, 1, EXPLOSION_SMALL ); 86 wp->type[i] = WEAPON_NONE; 87 88 if( x <= t->left[y+j] ) 89 { 90 t->left[y+j-1]--; 91 t->left[y+j] -= 2; 92 t->left[y+j+1]--; 93 } 94 else 95 { 96 t->right[y+j-1]++; 97 t->right[y+j] += 2; 98 t->right[y+j+1]++; 99 } 100 break; 101 } 102 } 103 break; 104 case WEAPON_BEAM: 105 if( wp->n[i] > 19 ) 106 { 107 break; 108 } 109 110 j = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; 111 j = GET_MIN( y, j ); 112 113 for( ; j > 0 ; j-- ) 114 { 115 if( x - 2 <= t->left[y-j] ) 116 { 117 add_explosion( g, ex, GET_MIN(t->left[y-j], x+3), y-j, 0, 1, EXPLOSION_SMALL ); 118 t->left[y-j] -= GET_RAND(0,3); 119 } 120 else if( x + 3 >= t->right[y-j] ) 121 { 122 add_explosion( g, ex, GET_MAX(t->right[y-j], x-2), y-j, 0, 1, EXPLOSION_SMALL ); 123 t->right[y-j] += GET_RAND(0,3); 124 } 125 } 126 break; 127 120 128 case WEAPON_NUKE: 121 case WEAPON_BEAM: 122 /* The nuke and the laser do not break the tunnel */ 129 /* The nuke does not break the tunnel */ 123 130 break; 124 131 } … … 128 135 void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ) 129 136 { 130 int i, j, x, y;137 int i, j, k, x, y; 131 138 132 139 for( i = 0; i < WEAPONS; i++ ) … … 166 173 167 174 case WEAPON_BEAM: 175 if( wp->n[i] > 19 ) 176 { 177 break; 178 } 179 168 180 r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; 169 181 … … 191 203 } 192 204 193 if( x >= al->x[j] && x <= al->x[j] + 4194 && y >= al->y[j] && y <= al->y[j] + 2 )195 {196 al->life[j]--;197 ok = 1;198 }199 else if( x >= al->x[j] && x <= al->x[j] + 4200 && y+1 >= al->y[j] && y+1 <= al->y[j] + 2 )201 {202 al->life[j]--;203 ok = 1;205 for( k = GET_MIN( 0, wp->vy[i] >> 4 ) ; 206 k < GET_MAX( 0, wp->vy[i] >> 4 ) ; 207 k++ ) 208 { 209 if( x >= al->x[j] && x <= al->x[j] + 4 210 && y+k >= al->y[j] && y+k <= al->y[j] + 2 ) 211 { 212 al->life[j]--; 213 ok = 1; 214 break; 215 } 204 216 } 205 217 } -
libcaca/trunk/src/common.h
r43 r49 4 4 * All Rights Reserved 5 5 * 6 * $Id: common.h,v 1. 9 2002/12/22 22:36:42sam Exp $6 * $Id: common.h,v 1.10 2002/12/23 09:28:37 sam Exp $ 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify … … 22 22 23 23 #define STARS 50 24 #define WEAPONS 10024 #define WEAPONS 200 25 25 #define BONUS 30 26 26 #define ALIENS 30 27 #define EXPLOSIONS 10027 #define EXPLOSIONS 200 28 28 29 29 #ifdef USE_SLANG … … 44 44 45 45 #define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0))) 46 #define GET_MAX(a,b) ((a)>(b)?(a):(b)) 47 #define GET_MIN(a,b) ((a)<(b)?(a):(b)) 46 48 47 49 typedef struct … … 53 55 typedef struct 54 56 { 55 int x[STARS]; 56 int y[STARS]; 57 int z[STARS]; 58 char ch[STARS]; 59 int c[STARS]; 57 int x, y, z, c; 58 char ch; 60 59 61 60 } starfield; … … 170 169 void add_bonus( game *g, bonus *bo, int x, int y, int type ); 171 170 172 void init_starfield( game *g, starfield *s);171 starfield * create_starfield( game *g ); 173 172 void draw_starfield( game *g, starfield *s ); 174 173 void update_starfield( game *g, starfield *s ); 174 void free_starfield( game *g, starfield *s ); 175 175 176 176 tunnel * create_tunnel( game *g, int w, int h ); -
libcaca/trunk/src/main.c
r41 r49 4 4 * All Rights Reserved 5 5 * 6 * $Id: main.c,v 1. 8 2002/12/22 22:17:41sam Exp $6 * $Id: main.c,v 1.9 2002/12/23 09:28:37 sam Exp $ 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify … … 62 62 int purcompteur = 0; 63 63 64 g->sf = malloc(sizeof(starfield));64 g->sf = create_starfield( g ); 65 65 g->wp = malloc(sizeof(weapons)); 66 66 g->ex = malloc(sizeof(explosions)); … … 70 70 g->al = malloc(sizeof(aliens)); 71 71 72 init_starfield( g, g->sf );73 72 init_weapons( g, g->wp ); 74 73 init_explosions( g, g->ex ); … … 223 222 } 224 223 224 free_starfield( g, g->sf ); 225 225 226 #if 0 226 227 free_player( p ); -
libcaca/trunk/src/starfield.c
r37 r49 4 4 * All Rights Reserved 5 5 * 6 * $Id: starfield.c,v 1. 4 2002/12/22 18:44:12sam Exp $6 * $Id: starfield.c,v 1.5 2002/12/23 09:28:37 sam Exp $ 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify … … 25 25 #include "common.h" 26 26 27 void init_starfield( game *g, starfield *s)27 starfield * create_starfield( game *g ) 28 28 { 29 29 int i; 30 starfield *s; 31 32 s = malloc( STARS * sizeof(starfield) ); 30 33 31 34 for( i = 0; i < STARS; i++ ) 32 35 { 33 s ->x[i] = rand() % g->w;34 s ->y[i] = rand() % g->h;35 s ->z[i] = 1 + rand() % 3;36 s ->ch[i] = (rand() % 2) ? '.' : '\'';37 s ->c[i] = 6 + rand() % 2;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 ) ? '.' : '\''; 38 41 } 42 43 return s; 39 44 } 40 45 … … 45 50 for( i = 0; i < STARS; i++ ) 46 51 { 47 if( s ->x[i]>= 0 )52 if( s[i].x >= 0 ) 48 53 { 49 gfx_color( s ->c[i]);50 gfx_goto( s ->x[i], s->y[i]);51 gfx_putchar( s ->ch[i]);54 gfx_color( s[i].c ); 55 gfx_goto( s[i].x, s[i].y ); 56 gfx_putchar( s[i].ch ); 52 57 } 53 58 } … … 60 65 for( i = 0; i < STARS; i++ ) 61 66 { 62 if( s ->x[i]< 0 )67 if( s[i].x < 0 ) 63 68 { 64 s ->x[i] = rand() % g->w;65 s ->y[i]= 0;66 s ->z[i] = 1 + rand() % 2;67 s ->ch[i] = (rand() % 2) ? '.' : '\'';68 s ->c[i] = 6 + rand() % 2;69 s[i].x = GET_RAND( 0, g->w ); 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 ) ? '.' : '\''; 69 74 } 70 else if( s ->y[i]< g->h-1 )75 else if( s[i].y < g->h-1 ) 71 76 { 72 s ->y[i] += s->z[i];77 s[i].y += s[i].z; 73 78 } 74 79 else 75 80 { 76 s ->x[i]= -1;81 s[i].x = -1; 77 82 } 78 83 } 79 84 } 80 85 86 void free_starfield( game *g, starfield *s ) 87 { 88 free( s ); 89 } 90 -
libcaca/trunk/src/tunnel.c
r37 r49 4 4 * All Rights Reserved 5 5 * 6 * $Id: tunnel.c,v 1. 4 2002/12/22 18:44:12sam Exp $6 * $Id: tunnel.c,v 1.5 2002/12/23 09:28:37 sam Exp $ 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify … … 25 25 #include "common.h" 26 26 27 static void draw_wall( game *g, int *wall );27 static void draw_wall( game *g, int *wall, int delta ); 28 28 29 29 /* Init tunnel */ … … 40 40 if( t->w >= g->w ) 41 41 { 42 t->left[0] = -1 ;43 t->right[0] = g->w ;42 t->left[0] = -10; 43 t->right[0] = g->w + 10; 44 44 for( i = 0; i < g->h; i++ ) 45 45 { 46 t->left[i] = -1 ;47 t->right[i] = g->w ;46 t->left[i] = -10; 47 t->right[i] = g->w + 10; 48 48 } 49 49 } … … 72 72 { 73 73 /* Print tunnel */ 74 draw_wall( g, t->left );75 draw_wall( g, t->right );74 draw_wall( g, t->left, -2 ); 75 draw_wall( g, t->right, -1 ); 76 76 } 77 77 78 78 void update_tunnel( game *g, tunnel *t ) 79 79 { 80 static int const delta[] = { - 2, -1, 1, 2};80 static int const delta[] = { -3, -2, -1, 1, 2, 3 }; 81 81 int i,j,k; 82 82 … … 89 89 90 90 /* Generate new values */ 91 i = delta[GET_RAND(0, 4)];92 j = delta[GET_RAND(0, 4)];91 i = delta[GET_RAND(0,6)]; 92 j = delta[GET_RAND(0,6)]; 93 93 94 94 /* Check in which direction we need to alter tunnel */ … … 122 122 else 123 123 { 124 t->left[0] = -1 ;125 t->right[0] = g->w ;124 t->left[0] = -10; 125 t->right[0] = g->w + 10; 126 126 } 127 127 … … 152 152 } 153 153 154 static void draw_wall( game *g, int *wall )154 static void draw_wall( game *g, int *wall, int delta ) 155 155 { 156 156 int i; … … 162 162 char *str; 163 163 164 if( wall[i] < 0 || wall[i] >= g->w)164 if( wall[i] < -10 || wall[i] >= g->w + 10 ) 165 165 { 166 166 continue; … … 178 178 if( wall[i] == wall[i+1] + 2 ) 179 179 { 180 gfx_goto( wall[i] - 1 , i );180 gfx_goto( wall[i] - 1 + delta, i ); 181 181 gfx_putchar( '_' ); 182 182 } 183 183 184 gfx_goto( wall[i] , i );184 gfx_goto( wall[i] + delta, i ); 185 185 gfx_putstr( str ); 186 186 if( wall[i] == wall[i+1] - 2 ) gfx_putchar( '_' ); -
libcaca/trunk/src/weapons.c
r47 r49 4 4 * All Rights Reserved 5 5 * 6 * $Id: weapons.c,v 1.1 1 2002/12/22 23:39:15sam Exp $6 * $Id: weapons.c,v 1.12 2002/12/23 09:28:37 sam Exp $ 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify … … 199 199 { 200 200 32, 0, -32, 0, 0, 16, 0, -16, 201 28, 8, -28, 8, 28, -8, -28, -8, 201 202 24, 12, -24, 12, 24, -12, -24, -12, 202 28, 8, -28, 8, 28, -8, -28, -8,203 203 16, 14, -16, 14, 16, -14, -16, -14 204 204 }; … … 206 206 for( j = 0 ; j < sizeof(coords) / sizeof(int) ; j += 2 ) 207 207 { 208 add_weapon( g, g->wp, wp->x[i] + coords[j], wp->y[i] + coords[j+1], coords[j], coords[j+1], WEAPON_SEEKER ); 208 add_weapon( g, g->wp, wp->x[i] + coords[j], wp->y[i] + coords[j+1] / 2, coords[j], coords[j+1], WEAPON_SEEKER ); 209 add_weapon( g, g->wp, wp->x[i] + coords[j] / 2, wp->y[i] + coords[j+1], coords[j], coords[j+1], WEAPON_SEEKER ); 209 210 } 210 211
Note: See TracChangeset
for help on using the changeset viewer.