* the starfield is now an array of stars. * fixed wall rendering (offset issues and disappearing left wall). * 32 seekers on fragbomb explosion, not 16. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@50 92316355-f0b4-4df1-b90c-862c8a59935fmaster
@@ -8,11 +8,11 @@ Things to do | |||
* sprite library | |||
* mega ball | |||
DONE 23 Dec 2002: mega ball | |||
* spiral weapon (vertical sine) | |||
* fragmentation bomb (merge with mega-ball?) | |||
DONE 23 Dec 2002: fragmentation bomb (merge with mega-ball?) | |||
* stick aliens to tunnel | |||
@@ -30,7 +30,7 @@ Things to do | |||
* promote precision for all coordinates except screen | |||
* tunnel sometimes doesn't get drawn on the left | |||
DONE Dec 19 2002: tunnel sometimes doesn't get drawn on the left | |||
* write a generic drawing library with automatic clipping | |||
@@ -38,3 +38,5 @@ Things to do | |||
* animate the ship | |||
* the nuke should break the tunnel | |||
@@ -3,7 +3,7 @@ | |||
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* $Id: collide.c,v 1.7 2002/12/22 22:17:41 sam Exp $ | |||
* $Id: collide.c,v 1.8 2002/12/23 09:28:37 sam Exp $ | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
@@ -26,7 +26,7 @@ | |||
void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) | |||
{ | |||
int i, x, y; | |||
int i, j, x, y; | |||
for( i = 0; i < WEAPONS; i++ ) | |||
{ | |||
@@ -76,50 +76,57 @@ void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) | |||
} | |||
break; | |||
case WEAPON_LASER: | |||
if( x <= t->left[y+1] | |||
|| x >= t->right[y+1] ) | |||
for( j = GET_MIN( 0, wp->vy[i] >> 4 ) ; | |||
j < GET_MAX( 0, wp->vy[i] >> 4 ) ; | |||
j++ ) | |||
{ | |||
add_explosion( g, ex, x, y+1, 0, 1, EXPLOSION_SMALL ); | |||
if( x <= t->left[y+1] ) | |||
{ | |||
t->left[y]--; | |||
t->left[y+1]-=2; | |||
t->left[y+2]--; | |||
} | |||
else | |||
if( x <= t->left[y+j] || x >= t->right[y+j] ) | |||
{ | |||
t->right[y]++; | |||
t->right[y+1]+=2; | |||
t->right[y+2]++; | |||
} | |||
add_explosion( g, ex, x, y+j, 0, 1, EXPLOSION_SMALL ); | |||
wp->type[i] = WEAPON_NONE; | |||
wp->type[i] = WEAPON_NONE; | |||
if( x <= t->left[y+j] ) | |||
{ | |||
t->left[y+j-1]--; | |||
t->left[y+j] -= 2; | |||
t->left[y+j+1]--; | |||
} | |||
else | |||
{ | |||
t->right[y+j-1]++; | |||
t->right[y+j] += 2; | |||
t->right[y+j+1]++; | |||
} | |||
break; | |||
} | |||
} | |||
else if( x <= t->left[y] | |||
|| x >= t->right[y] ) | |||
break; | |||
case WEAPON_BEAM: | |||
if( wp->n[i] > 19 ) | |||
{ | |||
add_explosion( g, ex, x, y, 0, 1, EXPLOSION_SMALL ); | |||
break; | |||
} | |||
if( x <= t->left[y] ) | |||
j = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; | |||
j = GET_MIN( y, j ); | |||
for( ; j > 0 ; j-- ) | |||
{ | |||
if( x - 2 <= t->left[y-j] ) | |||
{ | |||
t->left[y-1]--; | |||
t->left[y]-=2; | |||
t->left[y+1]--; | |||
add_explosion( g, ex, GET_MIN(t->left[y-j], x+3), y-j, 0, 1, EXPLOSION_SMALL ); | |||
t->left[y-j] -= GET_RAND(0,3); | |||
} | |||
else | |||
else if( x + 3 >= t->right[y-j] ) | |||
{ | |||
t->right[y-1]++; | |||
t->right[y]+=2; | |||
t->right[y+1]++; | |||
add_explosion( g, ex, GET_MAX(t->right[y-j], x-2), y-j, 0, 1, EXPLOSION_SMALL ); | |||
t->right[y-j] += GET_RAND(0,3); | |||
} | |||
wp->type[i] = WEAPON_NONE; | |||
} | |||
break; | |||
case WEAPON_NUKE: | |||
case WEAPON_BEAM: | |||
/* The nuke and the laser do not break the tunnel */ | |||
/* The nuke does not break the tunnel */ | |||
break; | |||
} | |||
} | |||
@@ -127,7 +134,7 @@ void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) | |||
void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ) | |||
{ | |||
int i, j, x, y; | |||
int i, j, k, x, y; | |||
for( i = 0; i < WEAPONS; i++ ) | |||
{ | |||
@@ -165,6 +172,11 @@ void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ) | |||
break; | |||
case WEAPON_BEAM: | |||
if( wp->n[i] > 19 ) | |||
{ | |||
break; | |||
} | |||
r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; | |||
for( j = 0; j < ALIENS; j++ ) | |||
@@ -190,17 +202,17 @@ void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ) | |||
continue; | |||
} | |||
if( x >= al->x[j] && x <= al->x[j] + 4 | |||
&& y >= al->y[j] && y <= al->y[j] + 2 ) | |||
for( k = GET_MIN( 0, wp->vy[i] >> 4 ) ; | |||
k < GET_MAX( 0, wp->vy[i] >> 4 ) ; | |||
k++ ) | |||
{ | |||
al->life[j]--; | |||
ok = 1; | |||
} | |||
else if( x >= al->x[j] && x <= al->x[j] + 4 | |||
&& y+1 >= al->y[j] && y+1 <= al->y[j] + 2 ) | |||
{ | |||
al->life[j]--; | |||
ok = 1; | |||
if( x >= al->x[j] && x <= al->x[j] + 4 | |||
&& y+k >= al->y[j] && y+k <= al->y[j] + 2 ) | |||
{ | |||
al->life[j]--; | |||
ok = 1; | |||
break; | |||
} | |||
} | |||
} | |||
@@ -3,7 +3,7 @@ | |||
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* $Id: common.h,v 1.9 2002/12/22 22:36:42 sam Exp $ | |||
* $Id: common.h,v 1.10 2002/12/23 09:28:37 sam Exp $ | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
@@ -21,10 +21,10 @@ | |||
*/ | |||
#define STARS 50 | |||
#define WEAPONS 100 | |||
#define WEAPONS 200 | |||
#define BONUS 30 | |||
#define ALIENS 30 | |||
#define EXPLOSIONS 100 | |||
#define EXPLOSIONS 200 | |||
#ifdef USE_SLANG | |||
# include <slang.h> | |||
@@ -43,6 +43,8 @@ | |||
#define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0) | |||
#define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0))) | |||
#define GET_MAX(a,b) ((a)>(b)?(a):(b)) | |||
#define GET_MIN(a,b) ((a)<(b)?(a):(b)) | |||
typedef struct | |||
{ | |||
@@ -52,11 +54,8 @@ typedef struct | |||
typedef struct | |||
{ | |||
int x[STARS]; | |||
int y[STARS]; | |||
int z[STARS]; | |||
char ch[STARS]; | |||
int c[STARS]; | |||
int x, y, z, c; | |||
char ch; | |||
} starfield; | |||
@@ -169,9 +168,10 @@ void draw_bonus( game *g, bonus *bo ); | |||
void update_bonus( game *g, bonus *bo ); | |||
void add_bonus( game *g, bonus *bo, int x, int y, int type ); | |||
void init_starfield( game *g, starfield *s ); | |||
starfield * create_starfield( game *g ); | |||
void draw_starfield( game *g, starfield *s ); | |||
void update_starfield( game *g, starfield *s ); | |||
void free_starfield( game *g, starfield *s ); | |||
tunnel * create_tunnel( game *g, int w, int h ); | |||
void free_tunnel( tunnel *t ); | |||
@@ -3,7 +3,7 @@ | |||
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* $Id: main.c,v 1.8 2002/12/22 22:17:41 sam Exp $ | |||
* $Id: main.c,v 1.9 2002/12/23 09:28:37 sam Exp $ | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
@@ -61,7 +61,7 @@ static void start_game (game *g) | |||
int skip = 0; | |||
int purcompteur = 0; | |||
g->sf = malloc(sizeof(starfield)); | |||
g->sf = create_starfield( g ); | |||
g->wp = malloc(sizeof(weapons)); | |||
g->ex = malloc(sizeof(explosions)); | |||
g->bo = malloc(sizeof(bonus)); | |||
@@ -69,7 +69,6 @@ static void start_game (game *g) | |||
g->p = create_player( g ); | |||
g->al = malloc(sizeof(aliens)); | |||
init_starfield( g, g->sf ); | |||
init_weapons( g, g->wp ); | |||
init_explosions( g, g->ex ); | |||
init_aliens( g, g->al ); | |||
@@ -222,6 +221,8 @@ static void start_game (game *g) | |||
purcompteur++; | |||
} | |||
free_starfield( g, g->sf ); | |||
#if 0 | |||
free_player( p ); | |||
free_tunnel( g->t ); | |||
@@ -3,7 +3,7 @@ | |||
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* $Id: starfield.c,v 1.4 2002/12/22 18:44:12 sam Exp $ | |||
* $Id: starfield.c,v 1.5 2002/12/23 09:28:37 sam Exp $ | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
@@ -24,18 +24,23 @@ | |||
#include "common.h" | |||
void init_starfield( game *g, starfield *s ) | |||
starfield * create_starfield( game *g ) | |||
{ | |||
int i; | |||
starfield *s; | |||
s = malloc( STARS * sizeof(starfield) ); | |||
for( i = 0; i < STARS; i++ ) | |||
{ | |||
s->x[i] = rand() % g->w; | |||
s->y[i] = rand() % g->h; | |||
s->z[i] = 1 + rand() % 3; | |||
s->ch[i] = (rand() % 2) ? '.' : '\''; | |||
s->c[i] = 6 + rand() % 2; | |||
s[i].x = GET_RAND( 0, g->w ); | |||
s[i].y = GET_RAND( 0, g->h ); | |||
s[i].z = GET_RAND( 1, 4 ); | |||
s[i].c = GET_RAND( 6, 8 ); | |||
s[i].ch = GET_RAND( 0, 2 ) ? '.' : '\''; | |||
} | |||
return s; | |||
} | |||
void draw_starfield( game *g, starfield *s ) | |||
@@ -44,11 +49,11 @@ void draw_starfield( game *g, starfield *s ) | |||
for( i = 0; i < STARS; i++ ) | |||
{ | |||
if( s->x[i] >= 0 ) | |||
if( s[i].x >= 0 ) | |||
{ | |||
gfx_color( s->c[i] ); | |||
gfx_goto( s->x[i], s->y[i] ); | |||
gfx_putchar( s->ch[i] ); | |||
gfx_color( s[i].c ); | |||
gfx_goto( s[i].x, s[i].y ); | |||
gfx_putchar( s[i].ch ); | |||
} | |||
} | |||
} | |||
@@ -59,22 +64,27 @@ void update_starfield( game *g, starfield *s ) | |||
for( i = 0; i < STARS; i++ ) | |||
{ | |||
if( s->x[i] < 0 ) | |||
if( s[i].x < 0 ) | |||
{ | |||
s->x[i] = rand() % g->w; | |||
s->y[i] = 0; | |||
s->z[i] = 1 + rand() % 2; | |||
s->ch[i] = (rand() % 2) ? '.' : '\''; | |||
s->c[i] = 6 + rand() % 2; | |||
s[i].x = GET_RAND( 0, g->w ); | |||
s[i].y = 0; | |||
s[i].z = GET_RAND( 1, 3 ); | |||
s[i].c = GET_RAND( 6, 8 ); | |||
s[i].ch = GET_RAND( 0, 2 ) ? '.' : '\''; | |||
} | |||
else if( s->y[i] < g->h-1 ) | |||
else if( s[i].y < g->h-1 ) | |||
{ | |||
s->y[i] += s->z[i]; | |||
s[i].y += s[i].z; | |||
} | |||
else | |||
{ | |||
s->x[i] = -1; | |||
s[i].x = -1; | |||
} | |||
} | |||
} | |||
void free_starfield( game *g, starfield *s ) | |||
{ | |||
free( s ); | |||
} | |||
@@ -3,7 +3,7 @@ | |||
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* $Id: tunnel.c,v 1.4 2002/12/22 18:44:12 sam Exp $ | |||
* $Id: tunnel.c,v 1.5 2002/12/23 09:28:37 sam Exp $ | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
@@ -24,7 +24,7 @@ | |||
#include "common.h" | |||
static void draw_wall( game *g, int *wall ); | |||
static void draw_wall( game *g, int *wall, int delta ); | |||
/* Init tunnel */ | |||
tunnel * create_tunnel( game *g, int w, int h ) | |||
@@ -39,12 +39,12 @@ tunnel * create_tunnel( game *g, int w, int h ) | |||
if( t->w >= g->w ) | |||
{ | |||
t->left[0] = -1; | |||
t->right[0] = g->w; | |||
t->left[0] = -10; | |||
t->right[0] = g->w + 10; | |||
for( i = 0; i < g->h; i++ ) | |||
{ | |||
t->left[i] = -1; | |||
t->right[i] = g->w; | |||
t->left[i] = -10; | |||
t->right[i] = g->w + 10; | |||
} | |||
} | |||
else | |||
@@ -71,13 +71,13 @@ void free_tunnel( tunnel *t ) | |||
void draw_tunnel( game *g, tunnel *t ) | |||
{ | |||
/* Print tunnel */ | |||
draw_wall( g, t->left ); | |||
draw_wall( g, t->right ); | |||
draw_wall( g, t->left, -2 ); | |||
draw_wall( g, t->right, -1 ); | |||
} | |||
void update_tunnel( game *g, tunnel *t ) | |||
{ | |||
static int const delta[] = { -2, -1, 1, 2 }; | |||
static int const delta[] = { -3, -2, -1, 1, 2, 3 }; | |||
int i,j,k; | |||
/* Slide tunnel one block vertically */ | |||
@@ -88,8 +88,8 @@ void update_tunnel( game *g, tunnel *t ) | |||
} | |||
/* Generate new values */ | |||
i = delta[GET_RAND(0,4)]; | |||
j = delta[GET_RAND(0,4)]; | |||
i = delta[GET_RAND(0,6)]; | |||
j = delta[GET_RAND(0,6)]; | |||
/* Check in which direction we need to alter tunnel */ | |||
if( t->right[1] - t->left[1] < t->w ) | |||
@@ -121,8 +121,8 @@ void update_tunnel( game *g, tunnel *t ) | |||
} | |||
else | |||
{ | |||
t->left[0] = -1; | |||
t->right[0] = g->w; | |||
t->left[0] = -10; | |||
t->right[0] = g->w + 10; | |||
} | |||
if( t->w > g->w ) | |||
@@ -151,7 +151,7 @@ void update_tunnel( game *g, tunnel *t ) | |||
} | |||
} | |||
static void draw_wall( game *g, int *wall ) | |||
static void draw_wall( game *g, int *wall, int delta ) | |||
{ | |||
int i; | |||
@@ -161,7 +161,7 @@ static void draw_wall( game *g, int *wall ) | |||
{ | |||
char *str; | |||
if( wall[i] < 0 || wall[i] >= g->w ) | |||
if( wall[i] < -10 || wall[i] >= g->w + 10 ) | |||
{ | |||
continue; | |||
} | |||
@@ -177,11 +177,11 @@ static void draw_wall( game *g, int *wall ) | |||
if( wall[i] == wall[i+1] + 2 ) | |||
{ | |||
gfx_goto( wall[i] - 1, i ); | |||
gfx_goto( wall[i] - 1 + delta, i ); | |||
gfx_putchar( '_' ); | |||
} | |||
gfx_goto( wall[i], i ); | |||
gfx_goto( wall[i] + delta, i ); | |||
gfx_putstr( str ); | |||
if( wall[i] == wall[i+1] - 2 ) gfx_putchar( '_' ); | |||
} | |||
@@ -3,7 +3,7 @@ | |||
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* $Id: weapons.c,v 1.11 2002/12/22 23:39:15 sam Exp $ | |||
* $Id: weapons.c,v 1.12 2002/12/23 09:28:37 sam Exp $ | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
@@ -198,14 +198,15 @@ void update_weapons( game *g, weapons *wp ) | |||
int coords[] = | |||
{ | |||
32, 0, -32, 0, 0, 16, 0, -16, | |||
24, 12, -24, 12, 24, -12, -24, -12, | |||
28, 8, -28, 8, 28, -8, -28, -8, | |||
24, 12, -24, 12, 24, -12, -24, -12, | |||
16, 14, -16, 14, 16, -14, -16, -14 | |||
}; | |||
for( j = 0 ; j < sizeof(coords) / sizeof(int) ; j += 2 ) | |||
{ | |||
add_weapon( g, g->wp, wp->x[i] + coords[j], wp->y[i] + coords[j+1], coords[j], coords[j+1], WEAPON_SEEKER ); | |||
add_weapon( g, g->wp, wp->x[i] + coords[j], wp->y[i] + coords[j+1] / 2, coords[j], coords[j+1], WEAPON_SEEKER ); | |||
add_weapon( g, g->wp, wp->x[i] + coords[j] / 2, wp->y[i] + coords[j+1], coords[j], coords[j+1], WEAPON_SEEKER ); | |||
} | |||
wp->type[i] = WEAPON_NONE; | |||