home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
games
/
volume11
/
blockbuster
/
part01
/
stage.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-10
|
4KB
|
159 lines
/*
* File: stage.c
* Author: Eric Van Gestel
*
* For: blockbuster
*/
#include "blockbuster.h"
#include "bricks.h"
void
get_stage( )
{
FILE *fd;
char buf[MAX_COL + 3], stg[STAGEFILE_LENGTH];
register int row, col, tmp;
register char code;
nbricks = 0;
score_incr = 1;
loop_nhits = 0;
last_busted_brick = NULL;
/* open next stage file */
if ( !( fd = fopen( sprintf( stg, STAGEFILE, playground, stage_nb ),
"r" ) ) ) {
perror( "Can't open stage" );
exit( 1 );
}
/* clear msg */
for ( tmp = 0; tmp < MSG_HEIGHT; tmp++ )
pw_vector( msg_win, 0, tmp, STAGE_WIDTH_IN_PIXELS - 1, tmp,
PIX_CLR, 1 );
/* read stage name */
fscanf( fd, "%s\n", stage_name );
for ( tmp = 0; stage_name[tmp]; tmp++ )
if ( stage_name[tmp] == '_' )
stage_name[tmp] = ' ';
for ( /* tmp = tmp */ ; tmp < NAME_LENGTH - 1; tmp++ )
stage_name[tmp] = ' ';
stage_name[NAME_LENGTH - 1] = '\0';
msg1( OFFSET_SPEED, stage_name );
/* read pallet dimensions */
fscanf( fd, "%d%d\n", &pallet_lengthI, &pallet_heightI );
if ( pallet_lengthI < SHORT_PALLET_LENGTH ||
pallet_lengthI > LONG_PALLET_LENGTH ||
pallet_heightI < pallet_lengthI ||
pallet_heightI > MAX_PALLET_HEIGHT ) {
perror( "Inconsistent pallet dimensions" );
exit( 1 );
}
/* modify for difficulty level */
pallet_lengthI -= ( pallet_modif * pallet_lengthI ) / PALLET_DENOMINATOR;
if ( pallet_lengthI < MIN_PALLET_LENGTH )
pallet_lengthI = MIN_PALLET_LENGTH;
if ( pallet_lengthI > MAX_PALLET_LENGTH )
pallet_lengthI = MAX_PALLET_LENGTH;
if ( pallet_heightI < pallet_lengthI )
pallet_heightI = pallet_lengthI;
pallet_length = ( double ) pallet_lengthI;
pallet_height = ( double ) pallet_heightI;
/* read stage map */
for ( row = 0; row <= MAX_ROW; row++ ) {
if ( !fgets( buf, MAX_COL + 3, fd ) ) {
perror( "Can't read stage" );
exit( 1 );
}
for ( col = 0; col <= MAX_COL; col++ ) {
code = buf[col];
if ( IS_HIT_BRICK( code ) )
nbricks++;
switch ( code ) {
case '/':
launch_quadrant = NE;
launch_row = row;
launch_col = col;
launch_x = ( double ) ( COL_X( col + 1 ) );
launch_y = ( double ) ( ROW_Y( row ) );
break;
case '\\':
launch_quadrant = NW;
launch_row = row;
launch_col = col;
launch_x = ( double ) ( COL_X( col ) );
launch_y = ( double ) ( ROW_Y( row ) );
break;
case '^':
emit_row = row;
emit_col = col;
}
stage[row][col].code = code;
stage[row][col].nhits = 0;
}
}
fclose( fd );
/* draw new stage */
for ( row = 0; row <= MAX_ROW; row++ ) {
draw_brick0( row, 0 );
for ( col = 1; col < MAX_COL; col++ )
draw_brick( row, col );
draw_brick0( row, MAX_COL );
}
/* reset pallet location */
pallet_y = ( double ) ( pallet_yI = PALLET_MAX_Y + 4 );
pallet_row = MAX_ROW - 1;
draw_pallet( );
/* ready ? */
msg0( OFFSET_BALLS,
"Press right mouse button when ready; R1 to save.%7c", ' ' );
}
void
new_stage( )
{
FILE *fd;
register int stage_index, stage_nb_tmp;
char buf[STAGEFILE_LENGTH], buf2[2*STAGEFILE_LENGTH];
/* go faster or make the pallet smaller */
if ( launch_speed < MAX_SPEED )
launch_speed += SPEED_INCR;
else
pallet_modif += PALLET_INCR;
/* determine stage number */
if ( !nb_stages ) {
/* read number of available stages */
if ( !( fd = fopen( sprintf( buf, NB_STAGESFILE, playground ),
"r" ) ) ) {
perror( sprintf( buf2, "Can't open number of stages file <%s>",
buf ) );
exit( 1 );
}
fscanf( fd, "%d", &nb_stages );
fclose( fd );
/* clear stages memory */
for ( stage_nb_tmp = 0; stage_nb_tmp < MAX_NB_STAGES; )
stages[stage_nb_tmp++] = FALSE;
}
/* search for stage index'th available stage number */
stage_index = ( int ) ( random( ) ) % nb_stages--;
if ( stage_index < 0 )
stage_index = -stage_index;
for ( stage_nb = 0; stages[stage_nb]; )
stage_nb++;
while ( stage_index-- ) {
while ( stages[++stage_nb] );
}
stages[stage_nb] = TRUE;
get_stage( );
}