2008-09-17 12:34:39 +10:00
# include <stdio.h>
# include <stdarg.h>
# include <stdlib.h>
# include <string.h>
# include <time.h>
# include <sys/time.h>
# include <sys/types.h>
# include <unistd.h>
# include <math.h>
# include <SDL.h>
# include <SDL_keysym.h>
# include <SDL_rotozoom.h>
# include <SDL_ttf.h>
# include <SDL_framerate.h>
# include "defs.h"
# include "globals.h"
# include "shared.h"
2008-10-10 10:49:43 +11:00
int loadlevel ( int wnum , int lnum , int wantmonsters ) {
2008-09-17 12:34:39 +10:00
FILE * f ;
int x , y ;
2008-09-29 18:32:56 +10:00
int xx , yy ;
2008-09-17 12:34:39 +10:00
char buf [ BUFLEN ] ;
char buf2 [ BUFLEN ] ;
char filename [ BUFLEN ] ;
2008-10-10 08:04:41 +11:00
char tempfile [ BUFLEN ] ;
2008-09-17 12:34:39 +10:00
char * help [ MAXHELP ] ;
int numhelp = 0 ;
2008-10-23 17:30:48 +11:00
int curhelp = 0 ;
2008-09-17 12:34:39 +10:00
char * p ;
int tileid ;
int i ;
2008-09-26 19:51:17 +10:00
//int *ii;
2008-10-07 16:53:06 +11:00
//mapping_t mapping[MAXMAPPINGS];
//int nmappings = 0;
//tiletype_t *lasttile;
2008-09-17 12:34:39 +10:00
int newversion ;
2008-09-17 21:16:19 +10:00
int numanim = 0 ;
2008-09-29 18:32:56 +10:00
int leveldone ;
2008-09-17 21:16:19 +10:00
int tempanim [ LEVELW * LEVELH ] ;
2008-09-17 12:34:39 +10:00
2008-09-27 20:50:19 +10:00
int numenemies = 0 ;
2008-09-17 12:34:39 +10:00
2008-09-28 13:18:36 +10:00
2008-09-26 19:51:17 +10:00
printf ( " Loading level %d-%d... " , wnum , lnum ) ;
2008-10-10 07:51:09 +11:00
sprintf ( filename , " %s/world%d/%s " , datadir , wnum , levelentry [ lnum ] . filename ) ;
2008-09-30 17:42:09 +10:00
//filename = levelentry[lnum].filename;
//sprintf(filename, "world%d/level%d.dat",wnum,lnum);
f = fopen ( filename , " rt " ) ;
if ( ! f ) {
printf ( " can't open level file %s \n " , filename ) ;
return B_TRUE ;
}
2008-09-28 13:18:36 +10:00
// remember exit direction for current level
// before loading the new one.
if ( level ) {
oldexitdir = level - > exitdir ;
} else {
oldexitdir = D_RIGHT ;
}
2008-10-21 10:17:43 +11:00
if ( ! level ) {
level = malloc ( sizeof ( level_t ) ) ;
level - > animtiles = NULL ;
}
2008-09-17 21:16:19 +10:00
2008-10-07 16:53:06 +11:00
sprintf ( level - > filename , levelentry [ lnum ] . filename ) ;
2008-10-03 17:37:05 +10:00
/* set current level pointer */
curlevel = level ;
2008-09-17 21:16:19 +10:00
if ( level - > animtiles ) free ( level - > animtiles ) ;
2008-09-17 12:34:39 +10:00
2008-10-01 17:27:44 +10:00
level - > id = levelentry [ lnum ] . id ;
2008-09-30 17:42:09 +10:00
//sprintf(level->name, "Level %d-%d",wnum,lnum);
2008-10-07 16:53:06 +11:00
sprintf ( level - > name , " %s " , levelentry [ lnum ] . desc ) ;
2008-09-17 12:34:39 +10:00
level - > prev = NULL ;
level - > next = NULL ;
2008-09-30 17:42:09 +10:00
2008-09-17 12:34:39 +10:00
/* default */
level - > hurryuptime = 30 ;
2008-09-28 15:19:23 +10:00
if ( cheat ) {
level - > poweruptime = 5 ;
} else level - > poweruptime = POWERUPTIME ;
2008-09-17 12:34:39 +10:00
level - > p1x = 0 ;
level - > p1y = 0 ;
2008-09-28 13:18:36 +10:00
level - > powerupx = - 1 ;
level - > powerupy = - 1 ;
2008-09-17 12:34:39 +10:00
2008-09-28 13:18:36 +10:00
/* remove all onscreen text */
while ( text ) {
killtext ( text ) ;
}
/* clear sprite linked list (leave player) */
2008-09-17 12:34:39 +10:00
if ( sprite ! = NULL ) {
while ( sprite - > next ) {
killsprite ( sprite - > next ) ;
}
}
/* read tileset */
2008-10-03 17:37:05 +10:00
/*
2008-09-17 12:34:39 +10:00
fgets ( buf , BUFLEN , f ) ;
if ( strstr ( buf , " tileset " ) = = buf ) {
p = strtok ( buf , " " ) ;
p = strtok ( NULL , " " ) ;
2008-10-03 17:37:05 +10:00
// strip newline
2008-09-17 12:34:39 +10:00
p [ strlen ( p ) - 1 ] = ' \0 ' ;
2008-09-17 21:16:19 +10:00
if ( level - > tileset ) free ( level - > tileset ) ;
level - > tileset = strdup ( p ) ;
2008-09-17 12:34:39 +10:00
strcat ( p , " .tiles " ) ;
if ( loadtiletypes ( p ) ) {
printf ( " Cannot load tileset file: %s \n " , p ) ;
return B_TRUE ;
}
} else {
printf ( " invalid tileset file in line: '%s' \n " , buf ) ;
return B_TRUE ;
}
2008-10-03 17:37:05 +10:00
*/
/* load background image */
fgets ( buf , BUFLEN , f ) ;
if ( strstr ( buf , " bgfile " ) = = buf ) {
p = strtok ( buf , " " ) ;
p = strtok ( NULL , " " ) ;
// strip newline
p [ strlen ( p ) - 1 ] = ' \0 ' ;
if ( levelbg ) SDL_FreeSurface ( levelbg ) ;
2008-10-13 11:43:01 +11:00
sprintf ( level - > bgfile , " %s " , p ) ;
sprintf ( tempfile , " %s/backgrounds/%s " , datadir , level - > bgfile ) ;
levelbg = IMG_Load ( tempfile ) ;
2008-10-03 17:37:05 +10:00
if ( ! levelbg ) {
2008-10-13 11:43:01 +11:00
printf ( " Cannot load background file: %s \n " , tempfile ) ;
2008-10-03 17:37:05 +10:00
// default to forest
2008-10-10 08:04:41 +11:00
sprintf ( tempfile , " %s/backgrounds/forest.png " , datadir ) ;
levelbg = IMG_Load ( tempfile ) ;
2008-10-03 17:37:05 +10:00
}
} else {
// default to forest
if ( levelbg ) SDL_FreeSurface ( levelbg ) ;
2008-10-10 08:04:41 +11:00
sprintf ( tempfile , " %s/backgrounds/forest.png " , datadir ) ;
levelbg = IMG_Load ( tempfile ) ;
2008-10-03 17:37:05 +10:00
}
//if (levelbg) SDL_FreeSurface(levelbg);
//levelbg = IMG_Load("backgrounds/forest.png");
2008-09-17 12:34:39 +10:00
/* read background tile */
fgets ( buf , BUFLEN , f ) ;
if ( strstr ( buf , " bg " ) = = buf ) {
p = strtok ( buf , " " ) ;
p = strtok ( NULL , " " ) ;
level - > bgtileid = atoi ( p ) ;
if ( ! gettile ( level - > bgtileid ) ) {
printf ( " invalid background tile id: %d \n " , level - > bgtileid ) ;
return B_TRUE ;
}
//printf("Background tile id is %d (%s)\n",level->bgtileid,(gettile(level->bgtileid)->name));
} else {
printf ( " invalid background tile id line: '%s' \n " , buf ) ;
return B_TRUE ;
}
/* read hurryup time tile */
fgets ( buf , BUFLEN , f ) ;
if ( strstr ( buf , " hurryup " ) = = buf ) {
p = strtok ( buf , " " ) ;
p = strtok ( NULL , " " ) ;
level - > hurryuptime = atoi ( p ) ;
//printf("Hurryup time is %d\n",level->hurryuptime);
} else {
printf ( " invalid hurryup time line: '%s' \n " , buf ) ;
return B_TRUE ;
}
level - > nummonsters = 0 ;
fgets ( buf , BUFLEN , f ) ;
/* read help messages if present */
if ( strstr ( buf , " help " ) ) {
curhelp = 0 ; // used later
numhelp = 0 ;
fgets ( buf , BUFLEN , f ) ;
while ( ! strstr ( buf , " endhelp " ) ) {
// strip newline
buf [ strlen ( buf ) - 1 ] = ' \0 ' ;
help [ numhelp ] = strdup ( buf ) ;
numhelp + + ;
fgets ( buf , BUFLEN , f ) ;
}
/* this reads the first line of the level */
fgets ( buf , BUFLEN , f ) ;
}
/* read monster definitions if present */
if ( strstr ( buf , " monsters " ) ) {
fgets ( buf , BUFLEN , f ) ;
while ( ! strstr ( buf , " endmonsters " ) ) {
2008-10-07 16:53:06 +11:00
//char ch;
2008-09-17 12:34:39 +10:00
int monid ;
int x , y ;
// strip newline
buf [ strlen ( buf ) - 1 ] = ' \0 ' ;
strncpy ( buf2 , buf , BUFLEN ) ;
p = strtok ( buf2 , " " ) ;
if ( p = = NULL ) {
printf ( " invalid monster definition (missing type): '%s' \n " , buf ) ;
return B_TRUE ;
}
2008-10-07 16:53:06 +11:00
//ch = p[0]; // type of monster
//monid = chartomonster(ch);
// type of monster
monid = atoi ( p ) ;
2008-09-17 12:34:39 +10:00
if ( monid < 0 ) {
printf ( " invalid monster definition (invalid type): '%s' \n " , buf ) ;
return B_TRUE ;
}
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) {
printf ( " invalid monster definition (missing x): '%s' \n " , buf ) ;
return B_TRUE ;
}
x = atoi ( p ) ; // monster x pos
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) {
printf ( " invalid monster definition (missing y): '%s' \n " , buf ) ;
return B_TRUE ;
}
y = atoi ( p ) ; // monster y pos
2008-11-06 20:15:09 +11:00
// waypoints
if ( isplatform ( monid ) ) {
2008-11-09 16:24:07 +11:00
// initial waypoint is start position
level - > initm [ level - > nummonsters ] . wayx [ 0 ] = x * TILEW + ( TILEW / 2 ) ;
level - > initm [ level - > nummonsters ] . wayy [ 0 ] = y * TILEH + ( TILEH - 2 ) + 2 ;
level - > initm [ level - > nummonsters ] . numwaypoints = 1 ;
2008-11-06 20:15:09 +11:00
// read waypoints
p = strtok ( NULL , " " ) ;
while ( p ) {
level - > initm [ level - > nummonsters ] . wayx [ level - > initm [ level - > nummonsters ] . numwaypoints ] = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
level - > initm [ level - > nummonsters ] . wayy [ level - > initm [ level - > nummonsters ] . numwaypoints ] = atoi ( p ) ;
level - > initm [ level - > nummonsters ] . numwaypoints + + ;
// go to next one
p = strtok ( NULL , " " ) ;
}
if ( level - > initm [ level - > nummonsters ] . numwaypoints < = 0 ) {
printf ( " missing waypoint data for platform! \n " ) ;
}
}
2008-09-17 12:34:39 +10:00
if ( monid = = P_PLAYER ) {
level - > p1x = x ;
level - > p1y = y ;
2008-09-28 13:18:36 +10:00
} else if ( monid = = P_POWERUPPOS ) {
level - > powerupx = x ;
level - > powerupy = y ;
2008-10-03 17:37:05 +10:00
level - > poweruptype = randompowerup ( ) ;
2008-09-17 12:34:39 +10:00
} else {
/* place the monster */
level - > initm [ level - > nummonsters ] . startx = x * TILEW + ( TILEW / 2 ) ;
2008-09-26 19:51:17 +10:00
level - > initm [ level - > nummonsters ] . starty = y * TILEH + ( TILEH - 2 ) + 2 ;
2008-09-17 12:34:39 +10:00
level - > initm [ level - > nummonsters ] . id = monid ;
2008-10-07 18:58:36 +11:00
2008-09-27 20:50:19 +10:00
if ( ismonster ( monid ) ) numenemies + + ;
2008-09-17 12:34:39 +10:00
if ( monid = = P_HELP ) {
if ( curhelp > = numhelp ) {
printf ( " Error in level - more help icons than help texts. \n " ) ;
exit ( 1 ) ;
} else {
level - > initm [ level - > nummonsters ] . help = strdup ( help [ curhelp ] ) ;
curhelp + + ;
}
}
level - > nummonsters + + ;
2008-10-09 14:32:15 +11:00
if ( level - > nummonsters > = MAXMONSTERSPERLEVEL ) {
printf ( " ERROR: too many sprites ! \n " ) ;
fclose ( f ) ;
return B_TRUE ;
}
2008-09-17 12:34:39 +10:00
}
fgets ( buf , BUFLEN , f ) ;
}
2008-09-28 13:18:36 +10:00
/* this reads the next line after monster defs */
2008-09-17 12:34:39 +10:00
fgets ( buf , BUFLEN , f ) ;
}
2008-09-27 20:50:19 +10:00
2008-09-28 13:18:36 +10:00
/* exitdir ? */
if ( strstr ( buf , " exitdir " ) ) {
p = strtok ( buf , " " ) ; // "exitdir"
p = strtok ( NULL , " " ) ;
level - > exitdir = atoi ( p ) ;
2008-10-01 22:42:59 +10:00
/*
2008-09-28 13:18:36 +10:00
printf ( " Exit direction is " ) ;
switch ( level - > exitdir ) {
case D_RIGHT :
printf ( " RIGHT " ) ; break ;
case D_LEFT :
2008-09-30 17:42:09 +10:00
printf ( " lEFT " ) ; break ;
2008-09-28 13:18:36 +10:00
case D_UP :
printf ( " UP " ) ; break ;
case D_DOWN :
printf ( " DOWN " ) ; break ;
default :
level - > exitdir = D_RIGHT ;
printf ( " *INVALID* " ) ;
break ;
}
2008-10-01 22:42:59 +10:00
*/
2008-09-28 13:18:36 +10:00
printf ( " \n " ) ;
fgets ( buf , BUFLEN , f ) ;
} else {
level - > exitdir = D_RIGHT ;
printf ( " Defaulting to exitdir of RIGHT. \n " ) ;
}
2008-09-17 12:34:39 +10:00
/* check whether we've got a new or old level version */
if ( strstr ( buf , " , " ) ) {
/* new version */
newversion = B_TRUE ;
printf ( " Level data is new version. \n " ) ;
} else {
/* old version */
newversion = B_FALSE ;
printf ( " Level data is old version. \n " ) ;
}
x = 0 ;
y = 0 ;
2008-09-29 18:32:56 +10:00
leveldone = B_FALSE ;
while ( ! leveldone ) {
2008-09-17 12:34:39 +10:00
/* process a line of level data */
if ( newversion ) {
strncpy ( buf2 , buf , BUFLEN ) ;
p = strtok ( buf2 , " , " ) ;
while ( p ) {
2008-09-17 21:16:19 +10:00
int numframes ;
2008-09-17 12:34:39 +10:00
tileid = atoi ( p ) ;
/* validate it */
if ( ! gettile ( tileid ) ) {
printf ( " invalid tileid: %d \n " , tileid ) ;
fclose ( f ) ;
return B_TRUE ;
}
if ( x > LEVELW ) {
printf ( " Too many tiles on line %d: %d,%d \n " , y , x , y ) ;
fclose ( f ) ;
return B_TRUE ;
}
if ( y > = LEVELH ) {
printf ( " Too many lines at line %d: %d,%d \n " , y , x , y ) ;
fclose ( f ) ;
return B_TRUE ;
}
/* all okay */
level - > map [ y * LEVELW + x ] = tileid ;
2008-09-17 21:16:19 +10:00
numframes = gettileframecount ( tileid ) ;
if ( numframes = = 1 ) {
// not animated
level - > tileframe [ y * LEVELW + x ] = 0 ;
} else {
// animated
level - > tileframe [ y * LEVELW + x ] = rand ( ) % numframes ;
tempanim [ numanim ] = y * LEVELW + x ;
numanim + + ;
}
2008-09-17 12:34:39 +10:00
x + + ;
p = strtok ( NULL , " , " ) ;
}
2008-10-09 14:32:15 +11:00
} else { // old level data version
printf ( " ERROR: old level data! \n " ) ;
fclose ( f ) ;
return B_TRUE ;
}
2008-09-17 12:34:39 +10:00
/* make sure enough data was found */
if ( x < LEVELW + 1 ) {
printf ( " Not enough tiles on line: y = %d \n " , y ) ;
fclose ( f ) ;
return B_TRUE ;
}
/* go to next line */
y + + ;
x = 0 ;
fgets ( buf , BUFLEN , f ) ;
2008-09-29 18:32:56 +10:00
if ( feof ( f ) ) {
leveldone = B_TRUE ;
} else if ( strstr ( buf , " layer2 " ) ) {
leveldone = B_TRUE ;
}
}
// clear out layer2 by default
for ( xx = 0 ; xx < LEVELW ; xx + + ) {
for ( yy = 0 ; yy < LEVELH ; yy + + ) {
level - > map2 [ yy * LEVELW + xx ] = T_BLANK ;
}
}
if ( ! feof ( f ) ) {
int tid , xx , yy ;
2008-10-01 22:42:59 +10:00
//printf("found second layer\n");
2008-09-29 18:32:56 +10:00
// second layer exists - read it
fgets ( buf , BUFLEN , f ) ;
while ( ! feof ( f ) ) {
// format is x,y,tileid
p = strtok ( buf , " , " ) ; xx = atoi ( p ) ;
p = strtok ( NULL , " , " ) ; yy = atoi ( p ) ;
p = strtok ( NULL , " , " ) ; tid = atoi ( p ) ;
level - > map2 [ yy * LEVELW + xx ] = tid ;
fgets ( buf , BUFLEN , f ) ;
}
2008-09-17 12:34:39 +10:00
}
fclose ( f ) ;
2008-09-17 21:16:19 +10:00
// copy from our temp buffer into the real one
level - > animtiles = malloc ( sizeof ( int ) * ( numanim + 1 ) ) ;
memcpy ( level - > animtiles , tempanim , numanim * sizeof ( int ) ) ;
level - > animtiles [ numanim ] = - 1 ;
//level->animtiles = realloc(level->animtiles, (numanim+2) * sizeof(int)); // leave space for terminator
2008-09-17 12:34:39 +10:00
if ( ( numhelp > 0 ) & & ( curhelp ! = numhelp ) ) {
printf ( " WARNING: Unused help text. First unused is '%s' \n " , help [ curhelp ] ) ;
}
if ( y < LEVELH ) {
printf ( " Not enough lines in level: last y=%d, should be %d. \n " ,
y , LEVELH ) ;
return B_TRUE ;
}
2008-09-26 19:51:17 +10:00
# ifndef __EDITOR
2008-09-17 12:34:39 +10:00
if ( ( level - > p1x = = 0 ) | | ( level - > p1y = = 0 ) ) {
printf ( " Level is missing player 1 start position. \n " ) ;
return B_TRUE ;
}
2008-09-26 19:51:17 +10:00
# endif
2008-09-17 12:34:39 +10:00
/* free help texts */
for ( i = 0 ; i < numhelp ; i + + ) {
free ( help [ i ] ) ;
}
2008-09-28 13:18:36 +10:00
/* add player if required */
2008-09-17 12:34:39 +10:00
if ( player = = NULL ) {
addsprite ( P_PLAYER , ( curlevel - > p1x * TILEW ) + ( TILEW / 2 ) ,
2008-09-28 13:18:36 +10:00
( curlevel - > p1y * TILEH ) + TILEH - 2 , " Player " ) ;
player = lastsprite ;
2008-10-28 07:22:33 +11:00
}
// don't move player to start of the level if they already exist, becuase they're
// currently on a cloud - we move them after the level transition animation.
2008-09-28 13:18:36 +10:00
# ifdef __EDITOR
2008-09-28 14:42:09 +10:00
/* add powerup and player pos if they exists */
2008-09-28 13:18:36 +10:00
if ( ( level - > powerupx ! = - 1 ) & & ( level - > powerupy ! = - 1 ) ) {
addsprite ( P_POWERUPPOS , ( curlevel - > powerupx * TILEW ) + ( TILEW / 2 ) ,
( curlevel - > powerupy * TILEH ) + TILEH - 2 , " poweruppos " ) ;
}
2008-09-28 14:42:09 +10:00
player - > x = ( curlevel - > p1x * TILEW ) + ( TILEW / 2 ) ;
player - > y = ( curlevel - > p1y * TILEH ) + TILEH - 2 ;
2008-09-28 13:18:36 +10:00
# endif
/*else {
2008-09-17 12:34:39 +10:00
player - > x = ( curlevel - > p1x * TILEW ) + ( TILEW / 2 ) ;
player - > y = ( curlevel - > p1y * TILEH ) + TILEH - 2 ;
}
2008-09-28 13:18:36 +10:00
*/
2008-09-17 12:34:39 +10:00
2008-10-09 14:32:15 +11:00
2008-09-17 12:34:39 +10:00
/* add monsters */
2008-10-10 10:49:43 +11:00
if ( wantmonsters ) {
for ( i = 0 ; i < level - > nummonsters ; i + + ) {
char name [ MIDBUFLEN ] ;
int delay ;
2008-09-28 13:18:36 +10:00
2008-10-10 10:49:43 +11:00
if ( level - > initm [ i ] . id = = P_HELP ) {
2008-10-31 11:41:33 +11:00
// is help disabled?
if ( showhelp = = B_FALSE ) continue ;
2008-10-10 10:49:43 +11:00
strncpy ( name , level - > initm [ i ] . help , MIDBUFLEN ) ;
} else {
sprintf ( name , " Monster-%d " , i ) ;
}
2008-09-28 13:18:36 +10:00
2008-10-10 10:49:43 +11:00
if ( ismonster ( level - > initm [ i ] . id ) ) {
delay = 20 ;
} else {
delay = 0 ;
}
2008-10-07 16:53:06 +11:00
2008-10-09 14:32:15 +11:00
2008-11-06 20:15:09 +11:00
if ( isplatform ( level - > initm [ i ] . id ) ) {
sprite_t * newsp ;
int w ;
newsp = addsprite ( level - > initm [ i ] . id , level - > initm [ i ] . startx , level - > initm [ i ] . starty , name ) ;
newsp - > numwaypoints = level - > initm [ i ] . numwaypoints ;
for ( w = 0 ; w < newsp - > numwaypoints ; w + + ) {
newsp - > wayx [ w ] = level - > initm [ i ] . wayx [ w ] ;
newsp - > wayy [ w ] = level - > initm [ i ] . wayy [ w ] ;
}
} else {
2008-11-06 20:33:54 +11:00
# ifdef __EDITOR
addsprite ( level - > initm [ i ] . id , level - > initm [ i ] . startx , level - > initm [ i ] . starty , name ) ;
# else
2008-11-06 20:15:09 +11:00
puffin ( level - > initm [ i ] . id , level - > initm [ i ] . startx , level - > initm [ i ] . starty , name , delay ) ;
2008-10-10 10:49:43 +11:00
# endif
2008-11-06 20:33:54 +11:00
}
2008-10-10 10:49:43 +11:00
}
2008-09-17 12:34:39 +10:00
}
gtime = 0 ;
2008-10-20 09:58:54 +11:00
resethurryup ( level ) ;
2008-09-17 12:34:39 +10:00
2008-10-07 16:53:06 +11:00
boss = NULL ;
2008-10-13 11:43:01 +11:00
mask = NULL ;
2008-10-07 16:53:06 +11:00
2008-09-26 19:51:17 +10:00
printf ( " Done. \n " ) ;
/*
2008-09-17 21:16:19 +10:00
for ( ii = level - > animtiles ; ii & & * ii ! = - 1 ; ii + + ) {
printf ( " %d " , * ii ) ;
}
printf ( " . \n " ) ;
2008-09-26 19:51:17 +10:00
*/
2008-09-17 21:16:19 +10:00
2008-09-17 12:34:39 +10:00
return B_FALSE ;
}
void setdefaults ( sprite_t * s ) {
2008-10-22 06:42:50 +11:00
if ( s = = player ) {
// player powerup stats
if ( s - > permspeed ) {
s - > speed = 2 ;
} else {
s - > speed = 1 ;
}
if ( s - > permbignet ) {
s - > netbig = B_TRUE ;
} else {
s - > netbig = B_FALSE ;
}
2008-10-15 14:20:10 +11:00
2008-10-22 06:42:50 +11:00
if ( s - > permnumnets ) {
2008-11-05 08:07:52 +11:00
s - > netmax = s - > permnumnets ;
2008-10-22 06:42:50 +11:00
} else {
s - > netmax = 1 ;
}
if ( s - > permsticky ) {
s - > netsticky = B_TRUE ;
} else {
s - > netsticky = B_FALSE ;
}
if ( s - > permdoublejump ) {
s - > doublejump = B_TRUE ;
} else {
s - > doublejump = B_FALSE ;
}
if ( s - > permarmour ) {
s - > armour = B_TRUE ;
s - > id = P_ARMOUR ;
} else {
s - > armour = B_FALSE ;
}
2008-10-15 14:20:10 +11:00
} else {
2008-11-09 08:14:10 +11:00
if ( s - > id = = P_PLATFORM ) {
s - > speed = PLATFORM_MAXSPEED ;
} else {
s - > speed = 1 ;
}
2008-10-22 06:42:50 +11:00
s - > armour = B_FALSE ;
2008-10-15 14:20:10 +11:00
s - > netsticky = B_FALSE ;
2008-10-19 19:00:34 +11:00
s - > doublejump = B_FALSE ;
2008-10-22 06:42:50 +11:00
s - > netbig = B_FALSE ;
s - > netmax = 1 ;
2008-10-19 19:00:34 +11:00
}
2008-10-15 06:36:51 +11:00
2008-10-19 08:52:08 +11:00
s - > doublejumpready = B_FALSE ;
2008-10-18 15:49:08 +11:00
2008-10-26 14:31:16 +11:00
s - > allocimg = B_FALSE ;
2008-10-18 15:49:08 +11:00
2008-10-15 06:36:51 +11:00
s - > frame = 0 ;
2008-11-06 20:15:09 +11:00
s - > onplatform = NULL ;
2008-10-13 11:43:01 +11:00
s - > hasmask = B_FALSE ;
2008-10-03 17:37:05 +10:00
s - > hasbell = B_FALSE ;
s - > gemboost = 1 ;
s - > powerup = 0 ;
// player-only states
s - > netting = 0 ;
s - > netcaught = 0 ;
s - > slamming = 0 ;
s - > invuln = 0 ;
// states
2008-10-09 14:32:15 +11:00
s - > recoiling = B_FALSE ;
2008-09-17 12:34:39 +10:00
s - > teleporting = 0 ;
s - > climbing = 0 ;
2008-11-06 20:15:09 +11:00
s - > swimming = 0 ;
2008-09-17 12:34:39 +10:00
s - > jumping = 0 ;
s - > jumpspeed = 0 ;
s - > jumpdir = 1 ;
2008-10-18 15:49:08 +11:00
s - > useddoublejump = B_FALSE ;
2008-11-06 13:15:49 +11:00
if ( s - > id ! = P_RANDOM ) {
// random gets timer1 set during addsprite()
s - > timer1 = 0 ;
}
2008-09-27 16:02:42 +10:00
s - > timer2 = 0 ;
s - > timer3 = 0 ;
2008-10-30 12:06:25 +11:00
s - > timer4 = 0 ;
2008-11-09 08:14:10 +11:00
s - > dbltimer = - 1 ;
2008-09-26 19:51:17 +10:00
s - > dropping = 0 ;
s - > dropx = - 1 ;
2008-10-03 17:37:05 +10:00
s - > dropy = - 1 ;
2008-09-29 18:32:56 +10:00
s - > ontramp = B_FALSE ;
s - > trampx = - 1 ;
s - > trampy = - 1 ;
2008-09-28 13:18:36 +10:00
s - > quickdie = B_FALSE ;
2008-09-17 12:34:39 +10:00
s - > falling = 0 ;
s - > fallspeed = 0 ;
s - > dir = 1 ;
s - > dead = 0 ;
s - > angry = 0 ;
s - > jumptimer = 0 ;
2008-10-07 16:53:06 +11:00
s - > willjumpspeed = 0 ;
2008-10-03 21:11:07 +10:00
s - > iced = B_FALSE ;
if ( s - > iceimg ) {
SDL_FreeSurface ( s - > iceimg ) ;
s - > iceimg = NULL ;
}
2008-09-17 12:34:39 +10:00
2008-10-09 14:32:15 +11:00
s - > watertimer = 0 ;
2008-09-17 12:34:39 +10:00
s - > bullet = NULL ;
s - > owner = NULL ;
s - > willbecome = P_CHEESE ;
2008-10-07 16:53:06 +11:00
// special
if ( s - > id = = P_PINKCLOUD ) {
s - > size = 0.1 ;
2008-10-10 10:12:51 +11:00
} else if ( s - > id = = P_BLACKCLOUD ) {
s - > size = 0.1 ;
2008-10-07 16:53:06 +11:00
} else {
// not used
s - > size = - 1 ;
}
2008-10-09 14:32:15 +11:00
// special
if ( s - > id = = P_SNAIL ) {
s - > lives = 1 ;
}
2008-10-07 16:53:06 +11:00
// special for bosses
if ( s - > id = = P_KINGRAT ) {
s - > timer1 = 0 ;
s - > timer2 = KR_WALKTIME ;
s - > timer3 = 0 ;
2008-11-03 17:06:37 +11:00
} else if ( s - > id = = P_KINGSNAIL ) {
s - > timer1 = KSS_WALK1 ;
s - > timer2 = KS_WALKTIME ;
s - > timer3 = 0 ;
2008-10-07 16:53:06 +11:00
}
if ( isboss ( s - > id ) ) {
s - > lives = getbosshealth ( s - > id ) ; // health
}
// flying
2008-09-17 12:34:39 +10:00
switch ( s - > id ) {
case P_BEE :
2008-10-10 21:06:40 +11:00
case P_FISH :
2008-10-07 16:53:06 +11:00
case P_BLACKCLOUD :
2008-10-03 17:37:05 +10:00
case P_SPIDER :
2008-09-17 12:34:39 +10:00
s - > flies = B_TRUE ;
break ;
2008-11-09 16:24:07 +11:00
case P_FLY :
s - > flies = F_FLYVERT ;
break ;
2008-09-17 12:34:39 +10:00
default :
s - > flies = B_FALSE ;
break ;
}
2008-10-01 22:42:59 +10:00
if ( s ! = player ) {
s - > score = getpoints ( s - > id ) ;
}
2008-09-17 12:34:39 +10:00
s - > caughtby = NULL ;
2008-10-19 20:00:03 +11:00
s - > caughtstate = B_FALSE ;
2008-09-17 12:34:39 +10:00
2008-10-30 12:06:25 +11:00
s - > zapping = NULL ;
2008-09-17 12:34:39 +10:00
s - > xs = - 99 ;
s - > ys = - 99 ;
s - > doomcount = 0 ;
}
/* initial is TRUE if we are populating the level for the first time */
2008-09-28 13:18:36 +10:00
sprite_t * addsprite ( int id , int x , int y , char * name ) {
2008-09-17 12:34:39 +10:00
sprite_t * s ;
2008-10-15 14:20:10 +11:00
int c ;
2008-09-17 12:34:39 +10:00
if ( sprite = = NULL ) {
sprite = malloc ( sizeof ( sprite_t ) ) ;
s = sprite ;
s - > prev = NULL ;
} else {
s = lastsprite ;
s - > next = malloc ( sizeof ( sprite_t ) ) ;
s - > next - > prev = s ;
s = s - > next ;
}
2008-11-06 13:15:49 +11:00
2008-09-17 12:34:39 +10:00
s - > id = id ;
s - > x = x ;
s - > y = y ;
2008-11-06 13:15:49 +11:00
// special case for random powerup
if ( s - > id = = P_RANDOM ) {
s - > timer1 = randompowerup ( ) ;
while ( s - > timer1 = = P_RANDOM ) {
s - > timer1 = randompowerup ( ) ;
}
}
2008-10-07 16:53:06 +11:00
if ( s - > id = = P_BLACKCLOUD ) {
2008-10-10 10:12:51 +11:00
s - > img = rotozoomSurfaceXY ( imageset [ id ] . img [ F_WALK1 ] , 0 , 0.1 , 0.1 , 0 ) ;
2008-10-07 16:53:06 +11:00
} else if ( s - > id = = P_PINKCLOUD ) {
s - > img = rotozoomSurfaceXY ( imageset [ id ] . img [ F_WALK1 ] , 0 , ( double ) PCGROWSPEED , ( double ) PCGROWSPEED , 0 ) ;
2008-11-06 13:15:49 +11:00
} else if ( s - > id = = P_RANDOM ) {
s - > img = imageset [ s - > timer1 ] . img [ F_WALK1 ] ;
2008-09-17 12:34:39 +10:00
} else {
s - > img = imageset [ id ] . img [ F_WALK1 ] ;
}
if ( s - > y > ( 480 - TILEH - 1 ) ) {
s - > y = 480 - TILEH - 1 ;
}
strcpy ( s - > name , name ) ;
if ( s = = sprite ) {
s - > netbg = SDL_CreateRGBSurface ( SDL_SWSURFACE ,
200 , 64 ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
} else {
s - > netbg = NULL ;
}
2008-10-03 21:11:07 +10:00
s - > iceimg = NULL ;
2008-09-17 12:34:39 +10:00
2008-11-06 20:15:09 +11:00
// waypoints for moving platforms
s - > numwaypoints = 0 ;
s - > curwaypoint = 0 ;
2008-10-15 14:20:10 +11:00
// don't set these in setdefaults() as setdefaults() is called after each player death
2008-10-10 16:29:35 +11:00
s - > permspeed = B_FALSE ;
2008-10-15 14:20:10 +11:00
s - > permbignet = B_FALSE ;
s - > permnumnets = B_FALSE ;
s - > permsticky = B_FALSE ;
2008-10-19 19:00:34 +11:00
s - > permdoublejump = B_FALSE ;
2008-10-22 06:42:50 +11:00
s - > permarmour = B_FALSE ;
2008-10-15 14:20:10 +11:00
// don't set this in setdefaults() as setdefaults() is called after each player death
s - > numcards = 0 ;
for ( c = 0 ; c < MAXCARDS ; c + + ) {
s - > card [ c ] = - 1 ;
s - > usedcard [ c ] = 0 ;
}
2008-10-10 16:29:35 +11:00
2008-09-17 12:34:39 +10:00
setdefaults ( s ) ;
2008-10-10 16:29:35 +11:00
2008-09-28 13:18:36 +10:00
// initial fruits don't time out
# ifndef __EDITOR
if ( ( levelcomplete ! = LV_NEXTLEV ) & & ( levelcomplete ! = LV_INIT ) ) {
2008-09-17 12:34:39 +10:00
if ( isfruit ( s - > id ) ) {
2008-09-28 13:18:36 +10:00
// random powerups stay for longer
if ( ! strcmp ( s - > name , " random_up " ) ) {
s - > doomcount = 900 ;
} else {
2008-09-17 12:34:39 +10:00
s - > doomcount = 500 ;
}
}
}
2008-09-28 13:18:36 +10:00
# endif
2008-09-17 12:34:39 +10:00
2008-10-03 21:11:07 +10:00
2008-11-06 13:15:49 +11:00
2008-09-17 12:34:39 +10:00
s - > next = NULL ;
lastsprite = s ;
return s ;
}
tiletype_t * gettileat ( int pixx , int pixy , int * tilex , int * tiley ) {
int tx , ty ;
2008-09-29 18:32:56 +10:00
int tid ;
2008-09-17 12:34:39 +10:00
tx = pixx / TILEW ;
ty = pixy / TILEH ;
if ( tilex ! = NULL ) {
* tilex = tx ;
}
if ( tiley ! = NULL ) {
* tiley = ty ;
}
2008-10-09 14:32:15 +11:00
if ( ty > = LEVELH ) {
// if tile is off the bottom of the screen,
// return one from the top row
ty = 0 ;
}
if ( pixy < 0 ) {
// if tile is off the top of the screen,
// return one from the bottom row
ty = LEVELH - 1 ;
}
2008-09-29 18:32:56 +10:00
// return layer2 if it exists
tid = curlevel - > map2 [ ty * LEVELW + tx ] ;
if ( tid = = T_BLANK ) {
tid = curlevel - > map [ ty * LEVELW + tx ] ;
}
return gettile ( tid ) ;
2008-09-17 12:34:39 +10:00
}
int loadtiletypes ( char * filename ) {
2008-10-10 07:51:09 +11:00
char fullfile [ BUFLEN ] ;
2008-09-17 12:34:39 +10:00
tiletype_t * t = NULL ;
int i ;
int state ;
FILE * f ;
char buf [ BUFLEN ] ;
2008-09-26 19:51:17 +10:00
char dirname [ BUFLEN ] ;
char imagefile [ BUFLEN ] ;
2008-09-17 12:34:39 +10:00
char * p , * pp ;
int uniq = 0 ;
2008-10-03 17:37:05 +10:00
/* clear tiletype linked list */
while ( tiletype ! = NULL ) {
int i ;
tiletype_t * tt ;
/* kill first tile */
for ( i = 0 ; i < tiletype - > numframes ; i + + ) {
if ( tiletype - > img [ i ] ) {
SDL_FreeSurface ( tiletype - > img [ i ] ) ;
tiletype - > img [ i ] = NULL ;
}
}
tt = tiletype - > next ;
free ( tiletype ) ;
tiletype = tt ;
}
2008-10-10 07:51:09 +11:00
sprintf ( fullfile , " %s/%s " , datadir , filename ) ;
2008-09-17 12:34:39 +10:00
state = 0 ;
2008-10-10 07:51:09 +11:00
f = fopen ( fullfile , " rt " ) ;
2008-09-17 12:34:39 +10:00
if ( ! f ) {
printf ( " can't open tiles file \n " ) ;
return B_TRUE ;
}
fgets ( buf , BUFLEN , f ) ;
while ( ! feof ( f ) ) {
if ( state = = 0 ) {
if ( strstr ( buf , " tile " ) = = buf ) {
if ( t = = NULL ) {
tiletype = malloc ( sizeof ( tiletype_t ) ) ;
t = tiletype ;
t - > prev = NULL ;
} else {
t - > next = malloc ( sizeof ( tiletype_t ) ) ;
t - > next - > prev = t ;
t = t - > next ;
}
p = strtok ( buf , " " ) ;
p = strtok ( NULL , " " ) ;
/* strip newline */
p [ strlen ( p ) - 1 ] = ' \0 ' ;
strcpy ( t - > name , p ) ;
/* defaults */
2008-09-26 19:51:17 +10:00
strcpy ( dirname , " . " ) ;
2008-09-17 12:34:39 +10:00
t - > id = 0 ;
2008-09-17 21:16:19 +10:00
t - > animspeed = 0 ; // not animated
t - > numframes = 1 ; // not animated
2008-09-17 12:34:39 +10:00
t - > water = B_FALSE ;
t - > spikes = B_FALSE ;
t - > solid = B_TRUE ;
for ( i = 0 ; i < TILEW ; i + + ) {
t - > lowness [ i ] = 0 ;
}
2008-09-17 21:16:19 +10:00
for ( i = 0 ; i < MAXTILEFRAMES ; i + + ) {
t - > img [ i ] = NULL ;
}
2008-09-17 12:34:39 +10:00
t - > next = NULL ;
state = 1 ;
/* unique id */
t - > uniqid = uniq ;
uniq + + ;
}
} else if ( state = = 1 ) { /* inside a definition */
if ( strstr ( buf , " end " ) = = buf ) {
2008-09-17 21:16:19 +10:00
2008-09-17 12:34:39 +10:00
//printf("got tile %d: %s (solid=%d)\n",t->id,t->name,t->solid);
2008-09-17 21:16:19 +10:00
/* check */
2008-09-17 12:34:39 +10:00
state = 0 ;
} else if ( strstr ( buf , " id " ) = = buf ) {
p = strtok ( buf , " " ) ;
p = strtok ( NULL , " " ) ;
t - > id = atoi ( p ) ;
2008-09-26 19:51:17 +10:00
} else if ( strstr ( buf , " dir " ) = = buf ) { // tile directory
/* strip newline */
buf [ strlen ( buf ) - 1 ] = ' \0 ' ;
p = strtok ( buf , " " ) ;
p = strtok ( NULL , " " ) ;
strcpy ( dirname , p ) ;
2008-09-17 21:16:19 +10:00
} else if ( strstr ( buf , " animspeed " ) = = buf ) {
p = strtok ( buf , " " ) ;
p = strtok ( NULL , " " ) ;
t - > animspeed = atoi ( p ) ;
2008-09-17 12:34:39 +10:00
} else if ( strstr ( buf , " lowness " ) = = buf ) {
p = strtok ( buf , " " ) ;
p = strtok ( NULL , " " ) ;
pp = strtok ( p , " , " ) ;
for ( i = 0 ; i < TILEW ; i + + ) {
t - > lowness [ i ] = atoi ( pp ) ;
pp = strtok ( NULL , " , " ) ;
}
} else if ( strstr ( buf , " solid " ) = = buf ) {
p = strtok ( buf , " " ) ;
p = strtok ( NULL , " " ) ;
t - > solid = atoi ( p ) ;
} else if ( strstr ( buf , " spikes " ) = = buf ) {
p = strtok ( buf , " " ) ;
p = strtok ( NULL , " " ) ;
t - > spikes = atoi ( p ) ;
} else if ( strstr ( buf , " water " ) = = buf ) {
p = strtok ( buf , " " ) ;
p = strtok ( NULL , " " ) ;
t - > water = atoi ( p ) ;
} else if ( strstr ( buf , " file " ) = = buf ) {
2008-09-17 21:16:19 +10:00
int frame ;
/* strip newline */
buf [ strlen ( buf ) - 1 ] = ' \0 ' ;
2008-09-17 12:34:39 +10:00
p = strtok ( buf , " " ) ;
2008-09-17 21:16:19 +10:00
// read all images
frame = 0 ;
2008-09-17 12:34:39 +10:00
p = strtok ( NULL , " " ) ;
2008-09-17 21:16:19 +10:00
while ( p ) {
if ( t - > img [ frame ] ) {
SDL_FreeSurface ( t - > img [ frame ] ) ;
t - > img [ frame ] = NULL ;
}
2008-10-10 08:04:41 +11:00
sprintf ( imagefile , " %s/%s/%s " , datadir , dirname , p ) ;
//strcpy(imagefile, dirname);
//strcat(imagefile, "/");
//strcat(imagefile, p);
2008-09-26 19:51:17 +10:00
t - > img [ frame ] = IMG_Load ( imagefile ) ;
2008-09-17 21:16:19 +10:00
if ( ! t - > img [ frame ] ) {
2008-09-26 19:51:17 +10:00
printf ( " cannot load tile image file: '%s' \n " , imagefile ) ;
2008-09-17 21:16:19 +10:00
fclose ( f ) ;
return B_TRUE ;
2008-09-26 19:51:17 +10:00
}
2008-09-17 21:16:19 +10:00
// black is transparent
SDL_SetColorKey ( t - > img [ frame ] , SDL_SRCCOLORKEY , SDL_MapRGB ( screen - > format , 0 , 0 , 0 ) ) ;
// get next one
frame + + ;
p = strtok ( NULL , " " ) ;
2008-09-17 12:34:39 +10:00
}
2008-09-17 21:16:19 +10:00
t - > numframes = frame ;
// default animation speed
t - > animspeed = 20 ;
2008-09-17 12:34:39 +10:00
}
}
fgets ( buf , BUFLEN , f ) ;
}
fclose ( f ) ;
return B_FALSE ;
}
int loadimagesets ( void ) {
int p , i ;
SDL_Surface * tempimg ;
SDL_Surface * reds ;
2008-10-10 08:04:41 +11:00
char tempfile [ BUFLEN ] ;
2008-09-17 12:34:39 +10:00
2008-10-10 08:04:41 +11:00
sprintf ( tempfile , " %s/sprites/dwarfhead.png " , datadir ) ;
head = IMG_Load ( tempfile ) ;
2008-10-19 08:46:55 +11:00
sprintf ( tempfile , " %s/sprites/dwarfhead5.png " , datadir ) ;
head5 = IMG_Load ( tempfile ) ;
2008-10-10 08:04:41 +11:00
sprintf ( tempfile , " %s/sprites/icecube.png " , datadir ) ;
icecube = IMG_Load ( tempfile ) ;
2008-10-07 16:53:06 +11:00
2008-10-10 08:04:41 +11:00
sprintf ( tempfile , " %s/sprites/health.png " , datadir ) ;
healthbar [ HF_GREEN ] = IMG_Load ( tempfile ) ;
sprintf ( tempfile , " %s/sprites/healthyellow.png " , datadir ) ;
healthbar [ HF_YELLOW ] = IMG_Load ( tempfile ) ;
sprintf ( tempfile , " %s/sprites/healthred.png " , datadir ) ;
healthbar [ HF_RED ] = IMG_Load ( tempfile ) ;
2008-10-07 16:53:06 +11:00
// green square for flyspray effect
greenbox = SDL_CreateRGBSurface ( SDL_SWSURFACE ,
screen - > w ,
screen - > h ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask , 0 ) ;
SDL_FillRect ( greenbox , NULL , SDL_MapRGB ( greenbox - > format , 0 , 150 , 0 ) ) ;
SDL_SetAlpha ( greenbox , SDL_SRCALPHA , 80 ) ;
2008-10-30 10:00:12 +11:00
// red square for gunner effect
redbox = SDL_CreateRGBSurface ( SDL_SWSURFACE ,
screen - > w ,
screen - > h ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask , 0 ) ;
SDL_FillRect ( redbox , NULL , SDL_MapRGB ( greenbox - > format , 150 , 0 , 0 ) ) ;
SDL_SetAlpha ( redbox , SDL_SRCALPHA , 80 ) ;
2008-10-01 22:42:59 +10:00
2008-09-17 21:16:19 +10:00
loadspriteimage ( P_PLAYER , F_WALK1 , " sprites/pdwarf.png " ) ;
loadspriteimage ( P_PLAYER , F_JUMP , " sprites/pdwarfjump.png " ) ;
loadspriteimage ( P_PLAYER , F_FALL , " sprites/pdwarffall.png " ) ;
loadspriteimage ( P_PLAYER , F_CAUGHT , " sprites/pdwarf.png " ) ;
loadspriteimage ( P_PLAYER , F_DEAD , " sprites/dwarfdie.png " ) ;
2008-09-17 12:34:39 +10:00
/* next 3 are auto generated */
2008-09-17 21:16:19 +10:00
loadspriteimage ( P_PLAYER , F_CLIMB1 , " sprites/dclimb1.png " ) ;
loadspriteimage ( P_PLAYER , F_CLIMB2 , " sprites/dclimb2.png " ) ;
2008-09-26 19:51:17 +10:00
loadspriteimage ( P_PLAYER , F_SHOOT , " sprites/dwarfshoot.png " ) ;
2008-09-27 20:50:19 +10:00
loadspriteimage ( P_PLAYER , F_SLAM1 , " sprites/dslam1.png " ) ;
loadspriteimage ( P_PLAYER , F_SLAM2 , " sprites/dslam2.png " ) ;
loadspriteimage ( P_PLAYER , F_SLAM3 , " sprites/dslam3.png " ) ;
loadspriteimage ( P_PLAYER , F_SLAM4 , " sprites/dslam4.png " ) ;
loadspriteimage ( P_PLAYER , F_SLAM5 , " sprites/dslam5.png " ) ;
2008-10-03 17:37:05 +10:00
loadspriteimage ( P_PLAYER , F_SWIM1 , " sprites/dswim1.png " ) ;
loadspriteimage ( P_PLAYER , F_SWIM2 , " sprites/dswim2.png " ) ;
imageset [ P_PLAYER ] . numimages = 18 ;
loadspriteimage ( P_ARMOUR , F_WALK1 , " sprites/armor.png " ) ;
loadspriteimage ( P_ARMOUR , F_JUMP , " sprites/armorjump.png " ) ;
loadspriteimage ( P_ARMOUR , F_FALL , " sprites/armorfall.png " ) ;
loadspriteimage ( P_ARMOUR , F_CAUGHT , " sprites/armor.png " ) ;
loadspriteimage ( P_ARMOUR , F_DEAD , " sprites/dwarfdie.png " ) ;
/* next 3 are auto generated */
loadspriteimage ( P_ARMOUR , F_CLIMB1 , " sprites/armorclimb1.png " ) ;
loadspriteimage ( P_ARMOUR , F_CLIMB2 , " sprites/armorclimb2.png " ) ;
loadspriteimage ( P_ARMOUR , F_SHOOT , " sprites/armorshoot.png " ) ;
loadspriteimage ( P_ARMOUR , F_SLAM1 , " sprites/armorslam1.png " ) ;
loadspriteimage ( P_ARMOUR , F_SLAM2 , " sprites/armorslam2.png " ) ;
loadspriteimage ( P_ARMOUR , F_SLAM3 , " sprites/armorslam3.png " ) ;
loadspriteimage ( P_ARMOUR , F_SLAM4 , " sprites/armorslam4.png " ) ;
loadspriteimage ( P_ARMOUR , F_SLAM5 , " sprites/armorslam5.png " ) ;
loadspriteimage ( P_ARMOUR , F_SWIM1 , " sprites/armorswim1.png " ) ;
loadspriteimage ( P_ARMOUR , F_SWIM2 , " sprites/armorswim2.png " ) ;
imageset [ P_ARMOUR ] . numimages = 18 ;
2008-09-17 12:34:39 +10:00
2008-10-01 17:27:44 +10:00
loadspriteimage ( P_SNAKE , F_WALK1 , " sprites/snake.png " ) ;
loadspriteimage ( P_SNAKE , F_JUMP , " sprites/snakejump.png " ) ;
loadspriteimage ( P_SNAKE , F_FALL , " sprites/snakejump.png " ) ;
loadspriteimage ( P_SNAKE , F_CAUGHT , " sprites/snakecaught.png " ) ;
loadspriteimage ( P_SNAKE , F_DEAD , " sprites/snakedead.png " ) ;
2008-09-17 12:34:39 +10:00
/* next 3 are auto generated */
imageset [ P_SNAKE ] . numimages = 8 ;
2008-10-01 17:27:44 +10:00
loadspriteimage ( P_RAT , F_WALK1 , " sprites/rat.png " ) ;
loadspriteimage ( P_RAT , F_JUMP , " sprites/ratjump.png " ) ;
loadspriteimage ( P_RAT , F_FALL , " sprites/ratjump.png " ) ;
loadspriteimage ( P_RAT , F_CAUGHT , " sprites/ratcaught.png " ) ;
loadspriteimage ( P_RAT , F_DEAD , " sprites/ratdead.png " ) ;
2008-09-17 12:34:39 +10:00
/* next 3 are auto generated */
imageset [ P_RAT ] . numimages = 8 ;
2008-10-01 17:27:44 +10:00
loadspriteimage ( P_BEE , F_WALK1 , " sprites/newbee.png " ) ;
loadspriteimage ( P_BEE , F_JUMP , " sprites/newbeejump.png " ) ;
loadspriteimage ( P_BEE , F_FALL , " sprites/newbeejump.png " ) ;
loadspriteimage ( P_BEE , F_CAUGHT , " sprites/newbeecaught.png " ) ;
loadspriteimage ( P_BEE , F_DEAD , " sprites/newbeedead.png " ) ;
2008-09-17 12:34:39 +10:00
/* next 3 are auto generated */
imageset [ P_BEE ] . numimages = 8 ;
2008-11-09 16:24:07 +11:00
loadspriteimage ( P_FLY , F_WALK1 , " sprites/fly.png " ) ;
loadspriteimage ( P_FLY , F_JUMP , " sprites/flywalk2.png " ) ;
loadspriteimage ( P_FLY , F_FALL , " sprites/flyjump.png " ) ;
loadspriteimage ( P_FLY , F_CAUGHT , " sprites/flycaught.png " ) ;
loadspriteimage ( P_FLY , F_DEAD , " sprites/flydead.png " ) ;
/* next 3 are auto generated */
imageset [ P_FLY ] . numimages = 8 ;
2008-10-13 12:33:41 +11:00
loadspriteimage ( P_SPIDER , F_WALK1 , " sprites/newspider.png " ) ;
loadspriteimage ( P_SPIDER , F_JUMP , " sprites/newspiderjump.png " ) ;
loadspriteimage ( P_SPIDER , F_FALL , " sprites/newspiderfall.png " ) ;
loadspriteimage ( P_SPIDER , F_CAUGHT , " sprites/newspidercaught.png " ) ;
loadspriteimage ( P_SPIDER , F_DEAD , " sprites/newspiderdead.png " ) ;
2008-09-17 12:34:39 +10:00
/* next 3 are auto generated */
imageset [ P_SPIDER ] . numimages = 8 ;
2008-10-10 21:06:40 +11:00
loadspriteimage ( P_FISH , F_WALK1 , " sprites/fish.png " ) ;
loadspriteimage ( P_FISH , F_JUMP , " sprites/fishjump.png " ) ;
loadspriteimage ( P_FISH , F_FALL , " sprites/fishjump.png " ) ;
loadspriteimage ( P_FISH , F_CAUGHT , " sprites/fishcaught.png " ) ;
loadspriteimage ( P_FISH , F_DEAD , " sprites/fishdead.png " ) ;
/* next 3 are auto generated */
imageset [ P_FISH ] . numimages = 8 ;
2008-10-10 10:12:51 +11:00
loadspriteimage ( P_BLACKCLOUD , F_WALK1 , " sprites/blackcloud.png " ) ;
imageset [ P_BLACKCLOUD ] . numimages = 1 ;
2008-10-07 16:53:06 +11:00
loadspriteimage ( P_PINKCLOUD , F_WALK1 , " sprites/pinkcloud.png " ) ;
imageset [ P_PINKCLOUD ] . numimages = 1 ;
2008-09-17 12:34:39 +10:00
2008-10-13 11:43:01 +11:00
loadspriteimage ( P_TICK , F_WALK1 , " sprites/tick.png " ) ;
loadspriteimage ( P_TICK , F_JUMP , " sprites/tickjump.png " ) ;
loadspriteimage ( P_TICK , F_FALL , " sprites/tickjump.png " ) ;
loadspriteimage ( P_TICK , F_CAUGHT , " sprites/tickcaught.png " ) ;
loadspriteimage ( P_TICK , F_DEAD , " sprites/tickdead.png " ) ;
imageset [ P_TICK ] . numimages = 8 ;
2008-09-26 19:51:17 +10:00
2008-10-24 14:31:25 +11:00
loadspriteimage ( P_PLANT , F_WALK1 , " sprites/plant.png " ) ;
loadspriteimage ( P_PLANT , F_JUMP , " sprites/plantjump.png " ) ;
loadspriteimage ( P_PLANT , F_FALL , " sprites/plantjump.png " ) ;
loadspriteimage ( P_PLANT , F_CAUGHT , " sprites/plant.png " ) ;
loadspriteimage ( P_PLANT , F_DEAD , " sprites/plantdead.png " ) ;
imageset [ P_PLANT ] . numimages = 8 ;
2008-10-07 16:53:06 +11:00
loadspriteimage ( P_KINGRAT , F_WALK1 , " sprites/kingrat.png " ) ;
loadspriteimage ( P_KINGRAT , F_JUMP , " sprites/kingratjump.png " ) ;
loadspriteimage ( P_KINGRAT , F_FALL , " sprites/kingratjump.png " ) ;
loadspriteimage ( P_KINGRAT , F_CAUGHT , " sprites/kingratcaught.png " ) ;
loadspriteimage ( P_KINGRAT , F_DEAD , " sprites/kingratdead.png " ) ;
/* next 3 are auto generated */
imageset [ P_KINGRAT ] . numimages = 8 ;
2008-11-01 08:13:27 +11:00
loadspriteimage ( P_KINGSNAIL , F_WALK1 , " sprites/kingsnail.png " ) ;
loadspriteimage ( P_KINGSNAIL , F_JUMP , " sprites/kingsnailjump.png " ) ;
loadspriteimage ( P_KINGSNAIL , F_FALL , " sprites/kingsnailjump.png " ) ;
2008-11-03 17:06:37 +11:00
loadspriteimage ( P_KINGSNAIL , F_CAUGHT , " sprites/kingsnail_broken.png " ) ;
2008-11-01 08:13:27 +11:00
loadspriteimage ( P_KINGSNAIL , F_DEAD , " sprites/kingsnaildead.png " ) ;
/* next 3 are auto genesnailed */
imageset [ P_KINGSNAIL ] . numimages = 8 ;
2008-11-03 17:06:37 +11:00
loadspriteimage ( P_KSSHELL , F_WALK1 , " sprites/kingsnail_shell.png " ) ;
imageset [ P_KSSHELL ] . numimages = 1 ;
// manually do flipped one
imageset [ P_KSSHELL ] . img [ MAXFRAMES ] = rotozoomSurfaceXY ( imageset [ P_KSSHELL ] . img [ 0 ] , 0 , - 1 , 1 , 0 ) ;
2008-10-09 14:32:15 +11:00
loadspriteimage ( P_SNAIL , F_WALK1 , " sprites/snail.png " ) ;
loadspriteimage ( P_SNAIL , F_JUMP , " sprites/snailwalk2.png " ) ;
loadspriteimage ( P_SNAIL , F_FALL , " sprites/snailwalk2.png " ) ;
loadspriteimage ( P_SNAIL , F_CAUGHT , " sprites/snailcaught.png " ) ;
loadspriteimage ( P_SNAIL , F_DEAD , " sprites/snaildead.png " ) ;
/* next 3 are auto generated */
imageset [ P_SNAIL ] . numimages = 8 ;
loadspriteimage ( P_SLUG , F_WALK1 , " sprites/slug.png " ) ;
loadspriteimage ( P_SLUG , F_JUMP , " sprites/slugwalk.png " ) ;
loadspriteimage ( P_SLUG , F_FALL , " sprites/slugjump.png " ) ;
loadspriteimage ( P_SLUG , F_CAUGHT , " sprites/slugcaught.png " ) ;
loadspriteimage ( P_SLUG , F_DEAD , " sprites/slugdead.png " ) ;
/* next 3 are auto generated */
imageset [ P_SLUG ] . numimages = 8 ;
2008-09-26 19:51:17 +10:00
/* fruits / powerups */
2008-10-01 17:27:44 +10:00
loadspriteimage ( P_CHEESE , F_WALK1 , " sprites/cheese.png " ) ;
2008-09-17 12:34:39 +10:00
imageset [ P_CHEESE ] . numimages = 1 ;
2008-10-01 17:27:44 +10:00
loadspriteimage ( P_ICECREAM , F_WALK1 , " sprites/icecream.png " ) ;
2008-09-17 12:34:39 +10:00
imageset [ P_ICECREAM ] . numimages = 1 ;
2008-10-01 17:27:44 +10:00
loadspriteimage ( P_CHIPS , F_WALK1 , " sprites/chips.png " ) ;
2008-09-17 12:34:39 +10:00
imageset [ P_CHIPS ] . numimages = 1 ;
2008-10-01 17:27:44 +10:00
loadspriteimage ( P_BURGER , F_WALK1 , " sprites/burger.png " ) ;
2008-09-17 12:34:39 +10:00
imageset [ P_BURGER ] . numimages = 1 ;
2008-10-01 17:27:44 +10:00
loadspriteimage ( P_SPEED , F_WALK1 , " sprites/speed.png " ) ;
2008-09-17 12:34:39 +10:00
imageset [ P_SPEED ] . numimages = 1 ;
2008-11-06 13:15:49 +11:00
// don't load image for P_RANDOM
imageset [ P_RANDOM ] . numimages = 0 ;
2008-10-01 17:27:44 +10:00
loadspriteimage ( P_NUMNETS , F_WALK1 , " sprites/numnets.png " ) ;
2008-09-17 12:34:39 +10:00
imageset [ P_NUMNETS ] . numimages = 1 ;
2008-10-01 17:27:44 +10:00
loadspriteimage ( P_BIGNET , F_WALK1 , " sprites/bignet.png " ) ;
2008-09-17 12:34:39 +10:00
imageset [ P_BIGNET ] . numimages = 1 ;
2008-10-03 17:37:05 +10:00
loadspriteimage ( P_GEMBOOST , F_WALK1 , " sprites/gemboost.png " ) ;
imageset [ P_GEMBOOST ] . numimages = 1 ;
2008-10-13 11:43:01 +11:00
loadspriteimage ( P_MASK , 0 , " sprites/mask.png " ) ;
loadspriteimage ( P_MASK , 1 , " sprites/maskleft.png " ) ;
imageset [ P_MASK ] . numimages = 2 ;
2008-10-20 07:45:38 +11:00
2008-10-13 11:43:01 +11:00
loadspriteimage ( P_MASKPOWERUP , F_WALK1 , " sprites/maskpowerup.png " ) ;
imageset [ P_MASKPOWERUP ] . numimages = 1 ;
2008-10-03 17:37:05 +10:00
2008-10-01 17:27:44 +10:00
loadspriteimage ( P_HELP , F_WALK1 , " sprites/help.png " ) ;
2008-09-17 12:34:39 +10:00
imageset [ P_HELP ] . numimages = 1 ;
2008-10-03 17:37:05 +10:00
loadspriteimage ( P_HELMET , F_WALK1 , " sprites/helmet.png " ) ;
imageset [ P_HELMET ] . numimages = 1 ;
2008-09-26 19:51:17 +10:00
loadspriteimage ( P_FLOWERYELLOW , F_WALK1 , " sprites/flower-yellow.png " ) ;
imageset [ P_FLOWERRED ] . numimages = 1 ;
2008-09-17 21:16:19 +10:00
loadspriteimage ( P_FLOWERRED , F_WALK1 , " sprites/flower-red.png " ) ;
imageset [ P_FLOWERRED ] . numimages = 1 ;
2008-09-26 19:51:17 +10:00
loadspriteimage ( P_FLOWERPURPLE , F_WALK1 , " sprites/flower-purple.png " ) ;
imageset [ P_FLOWERPURPLE ] . numimages = 1 ;
2008-09-27 16:02:42 +10:00
loadspriteimage ( P_GEMYELLOW , F_WALK1 , " sprites/gem-yellow.png " ) ;
imageset [ P_GEMYELLOW ] . numimages = 1 ;
loadspriteimage ( P_GEMRED , F_WALK1 , " sprites/gem-red.png " ) ;
imageset [ P_GEMRED ] . numimages = 1 ;
loadspriteimage ( P_GEMPURPLE , F_WALK1 , " sprites/gem-purple.png " ) ;
imageset [ P_GEMPURPLE ] . numimages = 1 ;
2008-09-28 13:18:36 +10:00
loadspriteimage ( P_POWERUPPOS , F_WALK1 , " sprites/poweruppos.png " ) ;
imageset [ P_POWERUPPOS ] . numimages = 1 ;
loadspriteimage ( P_BOXING , F_WALK1 , " sprites/boxing.png " ) ;
imageset [ P_BOXING ] . numimages = 1 ;
2008-09-28 13:43:03 +10:00
loadspriteimage ( P_GLOVE , F_WALK1 , " sprites/glove.png " ) ;
2008-09-28 13:18:36 +10:00
imageset [ P_GLOVE ] . numimages = 1 ;
2008-10-23 12:18:49 +11:00
// manually do flipped images
imageset [ P_GLOVE ] . img [ MAXFRAMES ] = rotozoomSurfaceXY ( imageset [ P_GLOVE ] . img [ 0 ] , 0 , - 1 , 1 , 0 ) ;
2008-09-28 13:18:36 +10:00
loadspriteimage ( P_DIAMOND , F_WALK1 , " sprites/diamond.png " ) ;
imageset [ P_DIAMOND ] . numimages = 1 ;
2008-09-28 14:09:12 +10:00
loadspriteimage ( P_FTODIAMOND , F_WALK1 , " sprites/flowertodiamond.png " ) ;
imageset [ P_FTODIAMOND ] . numimages = 1 ;
loadspriteimage ( P_FTOGEM , F_WALK1 , " sprites/flowertogem.png " ) ;
imageset [ P_FTOGEM ] . numimages = 1 ;
2008-09-28 14:42:09 +10:00
loadspriteimage ( P_BOMB , F_WALK1 , " sprites/bomb.png " ) ;
imageset [ P_BOMB ] . numimages = 1 ;
2008-10-10 13:46:56 +11:00
loadspriteimage ( P_STARPOWERUP , F_WALK1 , " sprites/star.png " ) ;
imageset [ P_STARPOWERUP ] . numimages = 1 ;
2008-10-15 14:20:10 +11:00
// Don't load image for P_MOVINGCARD or P_FIVECARDS
2008-10-10 14:53:59 +11:00
2008-10-10 13:46:56 +11:00
for ( i = 0 ; i < STARFRAMES ; i + + ) {
char name [ SMALLBUFLEN ] ;
sprintf ( name , " sprites/star%d.png " , i ) ;
loadspriteimage ( P_STAR , i , name ) ;
}
imageset [ P_STAR ] . numimages = STARFRAMES ;
2008-10-10 14:53:59 +11:00
loadspriteimage ( P_UFO , F_WALK1 , " sprites/ufo.png " ) ;
imageset [ P_UFO ] . numimages = 1 ;
loadspriteimage ( P_METEOR , F_WALK1 , " sprites/meteor.png " ) ;
imageset [ P_METEOR ] . numimages = 1 ;
2008-10-10 13:46:56 +11:00
2008-10-10 12:30:40 +11:00
loadspriteimage ( P_LIFE , F_WALK1 , " sprites/extralife.png " ) ;
2008-10-10 11:51:40 +11:00
imageset [ P_LIFE ] . numimages = 1 ;
2008-10-10 10:49:43 +11:00
loadspriteimage ( P_PHONE , F_WALK1 , " sprites/phone.png " ) ;
imageset [ P_PHONE ] . numimages = 1 ;
2008-10-10 11:51:40 +11:00
loadspriteimage ( P_HONEY , F_WALK1 , " sprites/honey.png " ) ;
imageset [ P_HONEY ] . numimages = 1 ;
2008-09-28 15:19:23 +10:00
loadspriteimage ( P_SHIELD , F_WALK1 , " sprites/shield.png " ) ;
imageset [ P_SHIELD ] . numimages = 1 ;
2008-09-30 17:42:09 +10:00
loadspriteimage ( P_MACEPOWERUP , F_WALK1 , " sprites/macepowerup.png " ) ;
imageset [ P_MACEPOWERUP ] . numimages = 1 ;
loadspriteimage ( P_MACE , F_WALK1 , " sprites/mace.png " ) ;
imageset [ P_MACE ] . numimages = 1 ;
2008-10-03 17:37:05 +10:00
loadspriteimage ( P_TROPHY , F_WALK1 , " sprites/trophy.png " ) ;
imageset [ P_TROPHY ] . numimages = 1 ;
loadspriteimage ( P_RINGSILVER , F_WALK1 , " sprites/ring-silver.png " ) ;
imageset [ P_RINGSILVER ] . numimages = 1 ;
loadspriteimage ( P_RINGGOLD , F_WALK1 , " sprites/ring-gold.png " ) ;
imageset [ P_RINGGOLD ] . numimages = 1 ;
loadspriteimage ( P_BELL , F_WALK1 , " sprites/bell.png " ) ;
imageset [ P_BELL ] . numimages = 1 ;
loadspriteimage ( P_CLOCK , F_WALK1 , " sprites/clock.png " ) ;
imageset [ P_CLOCK ] . numimages = 1 ;
2008-10-03 21:11:07 +10:00
loadspriteimage ( P_SNOWMAN , F_WALK1 , " sprites/snowman.png " ) ;
imageset [ P_SNOWMAN ] . numimages = 1 ;
2008-10-13 11:43:01 +11:00
loadspriteimage ( P_TAP , F_WALK1 , " sprites/tap.png " ) ;
imageset [ P_TAP ] . numimages = 1 ;
2008-10-07 16:53:06 +11:00
loadspriteimage ( P_SPRAY , F_WALK1 , " sprites/spray.png " ) ;
imageset [ P_SPRAY ] . numimages = 1 ;
loadspriteimage ( P_CANNONPOWERUP , F_WALK1 , " sprites/cannonpowerup.png " ) ;
imageset [ P_CANNONPOWERUP ] . numimages = 1 ;
loadspriteimage ( P_CANNON , F_WALK1 , " sprites/cannon.png " ) ;
imageset [ P_CANNON ] . numimages = 1 ;
2008-10-18 14:18:24 +11:00
loadspriteimage ( P_CLOVER , F_WALK1 , " sprites/clover.png " ) ;
imageset [ P_CLOVER ] . numimages = 1 ;
2008-10-18 15:16:06 +11:00
loadspriteimage ( P_ACCORDION , F_WALK1 , " sprites/accordion.png " ) ;
imageset [ P_ACCORDION ] . numimages = 1 ;
2008-10-18 15:49:08 +11:00
loadspriteimage ( P_WINGBOOTS , F_WALK1 , " sprites/wingboots.png " ) ;
imageset [ P_WINGBOOTS ] . numimages = 1 ;
2008-10-30 10:00:12 +11:00
loadspriteimage ( P_GUN , F_WALK1 , " sprites/gunner.png " ) ;
imageset [ P_GUN ] . numimages = 1 ;
2008-10-30 12:06:25 +11:00
loadspriteimage ( P_ZAPPOWERUP , F_WALK1 , " sprites/zapper.png " ) ;
imageset [ P_ZAPPOWERUP ] . numimages = 1 ;
2008-11-06 20:15:09 +11:00
// moving platforms
loadspriteimage ( P_PLATFORM , F_WALK1 , " sprites/platform.png " ) ;
imageset [ P_PLATFORM ] . numimages = 1 ;
2008-10-30 12:06:25 +11:00
loadspriteimage ( P_ZAPPER , 0 , " sprites/zap1.png " ) ;
loadspriteimage ( P_ZAPPER , 1 , " sprites/zap2.png " ) ;
loadspriteimage ( P_ZAPPER , 2 , " sprites/zap3.png " ) ;
loadspriteimage ( P_ZAPPER , 3 , " sprites/zap2.png " ) ;
loadspriteimage ( P_ZAPPER , 4 , " sprites/zap1.png " ) ;
imageset [ P_ZAPPER ] . numimages = 5 ;
2008-10-20 07:45:38 +11:00
// wings
loadspriteimage ( P_WINGLEFT , 0 , " sprites/wingleft0.png " ) ; // standing
loadspriteimage ( P_WINGLEFT , 1 , " sprites/wingleft1.png " ) ; // jumping
loadspriteimage ( P_WINGLEFT , 2 , " sprites/wingleft2.png " ) ; // jumping
loadspriteimage ( P_WINGLEFT , 3 , " sprites/wingleft3.png " ) ; // swimming
imageset [ P_WINGLEFT ] . numimages = 4 ;
loadspriteimage ( P_WINGRIGHT , 0 , " sprites/wingright0.png " ) ; // standing
loadspriteimage ( P_WINGRIGHT , 1 , " sprites/wingright1.png " ) ; // jumping
loadspriteimage ( P_WINGRIGHT , 2 , " sprites/wingright2.png " ) ; // jumping
imageset [ P_WINGRIGHT ] . numimages = 3 ;
// manually do flipped images
for ( i = 0 ; i < 3 ; i + + ) {
imageset [ P_WINGLEFT ] . img [ MAXFRAMES + i ] = rotozoomSurfaceXY ( imageset [ P_WINGLEFT ] . img [ i ] , 0 , - 1 , 1 , 0 ) ;
imageset [ P_WINGRIGHT ] . img [ MAXFRAMES + i ] = rotozoomSurfaceXY ( imageset [ P_WINGRIGHT ] . img [ i ] , 0 , - 1 , 1 , 0 ) ;
}
// and one more for WINGLEFT...
imageset [ P_WINGLEFT ] . img [ MAXFRAMES + 3 ] = rotozoomSurfaceXY ( imageset [ P_WINGLEFT ] . img [ 3 ] , 0 , - 1 , 1 , 0 ) ;
2008-10-18 16:10:10 +11:00
loadspriteimage ( P_SKULL , F_WALK1 , " sprites/skull.png " ) ;
imageset [ P_SKULL ] . numimages = 1 ;
2008-10-10 16:29:35 +11:00
loadspriteimage ( P_BIGSPEED , F_WALK1 , " sprites/bigspeed.png " ) ;
imageset [ P_BIGSPEED ] . numimages = 1 ;
2008-11-05 08:07:52 +11:00
loadspriteimage ( P_BIGNUMNETS , F_WALK1 , " sprites/bignumnets.png " ) ;
imageset [ P_BIGNUMNETS ] . numimages = 1 ;
2008-10-03 17:37:05 +10:00
// puffs and mace smashes
2008-09-27 16:02:42 +10:00
for ( i = 0 ; i < PUFFFRAMES ; i + + ) {
char name [ SMALLBUFLEN ] ;
sprintf ( name , " sprites/puff%d.png " , i ) ;
loadspriteimage ( P_PUFF , i , name ) ;
2008-10-03 17:37:05 +10:00
sprintf ( name , " sprites/puff%d.png " , i ) ;
loadspriteimage ( P_SMASH , i , name ) ;
2008-09-27 16:02:42 +10:00
}
imageset [ P_PUFF ] . numimages = PUFFFRAMES ;
2008-10-03 17:37:05 +10:00
imageset [ P_SMASH ] . numimages = PUFFFRAMES ;
2008-10-15 06:36:51 +11:00
// playing card bonuses
//loadspriteimage(P_CARDHK,F_WALK1, "sprites/cardhk.png");
// load card font
sprintf ( tempfile , " %s/cardfont.ttf " , datadir ) ;
cardfont = TTF_OpenFont ( tempfile , CARDFONTSIZE ) ;
if ( ! cardfont ) {
printf ( " Error opening font '%s': %s \n " , tempfile , TTF_GetError ( ) ) ;
exit ( 1 ) ;
}
for ( i = 1 ; i < = 13 ; i + + ) {
SDL_Surface * letter ;
SDL_Rect area ;
char str [ 2 ] ;
// HEARTS
loadspriteimage ( P_FIRSTHEART + i - 1 , F_WALK1 , " sprites/cardh.png " ) ;
sprintf ( str , " %s " , getcardletter ( i ) ) ;
letter = TTF_RenderText_Blended ( cardfont , str , red ) ;
area . x = CARDFONTX ; area . y = CARDFONTY ; area . w = 0 ; area . h = 0 ;
if ( i = = 10 ) area . x - = 3 ;
SDL_BlitSurface ( letter , NULL , imageset [ P_FIRSTHEART + i - 1 ] . img [ F_WALK1 ] , & area ) ;
imageset [ P_FIRSTHEART + i - 1 ] . numimages = 1 ;
SDL_FreeSurface ( letter ) ;
// DIAMONDS
loadspriteimage ( P_FIRSTDIAMOND + i - 1 , F_WALK1 , " sprites/cardd.png " ) ;
sprintf ( str , " %s " , getcardletter ( i ) ) ;
letter = TTF_RenderText_Blended ( cardfont , str , red ) ;
area . x = CARDFONTX ; area . y = CARDFONTY ; area . w = 0 ; area . h = 0 ;
if ( i = = 10 ) area . x - = 3 ;
SDL_BlitSurface ( letter , NULL , imageset [ P_FIRSTDIAMOND + i - 1 ] . img [ F_WALK1 ] , & area ) ;
imageset [ P_FIRSTDIAMOND + i - 1 ] . numimages = 1 ;
SDL_FreeSurface ( letter ) ;
// SPADES
loadspriteimage ( P_FIRSTSPADE + i - 1 , F_WALK1 , " sprites/cards.png " ) ;
sprintf ( str , " %s " , getcardletter ( i ) ) ;
letter = TTF_RenderText_Blended ( cardfont , str , black ) ;
area . x = CARDFONTX ; area . y = CARDFONTY ; area . w = 0 ; area . h = 0 ;
if ( i = = 10 ) area . x - = 3 ;
SDL_BlitSurface ( letter , NULL , imageset [ P_FIRSTSPADE + i - 1 ] . img [ F_WALK1 ] , & area ) ;
imageset [ P_FIRSTSPADE + i - 1 ] . numimages = 1 ;
SDL_FreeSurface ( letter ) ;
// CLUBS
loadspriteimage ( P_FIRSTCLUB + i - 1 , F_WALK1 , " sprites/cardc.png " ) ;
sprintf ( str , " %s " , getcardletter ( i ) ) ;
letter = TTF_RenderText_Blended ( cardfont , str , black ) ;
area . x = CARDFONTX ; area . y = CARDFONTY ; area . w = 0 ; area . h = 0 ;
if ( i = = 10 ) area . x - = 3 ;
SDL_BlitSurface ( letter , NULL , imageset [ P_FIRSTCLUB + i - 1 ] . img [ F_WALK1 ] , & area ) ;
imageset [ P_FIRSTCLUB + i - 1 ] . numimages = 1 ;
SDL_FreeSurface ( letter ) ;
}
2008-10-10 13:46:56 +11:00
2008-10-03 17:37:05 +10:00
// sparkles
for ( i = 0 ; i < SPARKLEFRAMES ; i + + ) {
char name [ SMALLBUFLEN ] ;
sprintf ( name , " sprites/sparkle%d.png " , i ) ;
loadspriteimage ( P_SPARKLE , i , name ) ;
}
imageset [ P_SPARKLE ] . numimages = SPARKLEFRAMES ;
2008-09-27 16:02:42 +10:00
2008-10-09 14:32:15 +11:00
loadspriteimage ( P_BUBBLE , F_WALK1 , " sprites/bubble.png " ) ;
imageset [ P_BUBBLE ] . numimages = 1 ;
2008-09-17 12:34:39 +10:00
/* bullets */
2008-10-01 17:27:44 +10:00
loadspriteimage ( P_SPIT , F_WALK1 , " sprites/spit.png " ) ;
2008-09-17 12:34:39 +10:00
imageset [ P_SPIT ] . numimages = 1 ;
/* generate rotated/flipped images */
for ( p = 0 ; p < MAXPTYPES ; p + + ) {
2008-10-01 17:27:44 +10:00
int fr ;
int angle = 90 ;
2008-10-03 17:37:05 +10:00
/* rotated death images */
2008-10-10 10:12:51 +11:00
if ( ! isfruit ( p ) & & ! isbullet ( p ) & & ! iseffect ( p ) & & p ! = P_BLACKCLOUD ) {
2008-10-01 17:27:44 +10:00
for ( fr = F_DEAD2 ; fr < = F_DEAD4 ; fr + + ) {
if ( ! imageset [ p ] . img [ fr ] ) {
tempimg = rotozoomSurface ( imageset [ p ] . img [ F_DEAD ] , angle , 1 , 0 ) ;
2008-10-15 06:36:51 +11:00
if ( tempimg = = NULL ) {
printf ( " error rotozooming sprite %d, deadimage %d \n " , p , fr ) ;
exit ( 1 ) ;
}
2008-10-01 17:27:44 +10:00
imageset [ p ] . img [ fr ] = SDL_DisplayFormat ( tempimg ) ;
2008-10-23 17:10:35 +11:00
SDL_FreeSurface ( tempimg ) ;
2008-10-01 17:27:44 +10:00
}
angle + = 90 ;
}
2008-09-17 12:34:39 +10:00
}
for ( i = 0 ; i < imageset [ p ] . numimages ; i + + ) {
SDL_Surface * origi ;
2008-10-10 10:12:51 +11:00
if ( ! isfruit ( p ) & & ! iseffect ( p ) & & p ! = P_BLACKCLOUD ) {
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
SDL_SetColorKey ( imageset [ p ] . img [ i ] ,
SDL_SRCCOLORKEY , SDL_MapRGB ( screen - > format , 0 , 0 , 0 ) ) ;
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
origi = imageset [ p ] . img [ i ] ;
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
/* flipped image */
imageset [ p ] . img [ MAXFRAMES + i ] =
rotozoomSurfaceXY ( imageset [ p ] . img [ i ] , 0 , - 1 , 1 , 0 ) ;
SDL_SetColorKey ( imageset [ p ] . img [ MAXFRAMES + i ] ,
SDL_SRCCOLORKEY , SDL_MapRGB ( screen - > format , 0 , 0 , 0 ) ) ;
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
/* angry image */
2008-10-01 17:27:44 +10:00
2008-10-07 16:53:06 +11:00
// create semi-transparent red square (white for bosses)
if ( isboss ( p ) ) {
reds = SDL_CreateRGBSurface ( SDL_SWSURFACE ,
origi - > w ,
origi - > h ,
origi - > format - > BitsPerPixel , origi - > format - > Rmask ,
origi - > format - > Gmask , origi - > format - > Bmask , 0 ) ;
SDL_FillRect ( reds , NULL , SDL_MapRGB ( reds - > format , 255 , 255 , 255 ) ) ;
SDL_SetAlpha ( reds , SDL_SRCALPHA , 100 ) ;
} else {
reds = SDL_CreateRGBSurface ( SDL_SWSURFACE ,
origi - > w ,
origi - > h ,
origi - > format - > BitsPerPixel , origi - > format - > Rmask ,
origi - > format - > Gmask , origi - > format - > Bmask , 0 ) ;
SDL_FillRect ( reds , NULL , SDL_MapRGB ( reds - > format , 255 , 0 , 0 ) ) ;
SDL_SetAlpha ( reds , SDL_SRCALPHA , 100 ) ;
}
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
// take a copy of the original image
imageset [ p ] . img [ MAXFRAMES * 2 + i ] = rotozoomSurfaceXY ( origi , 0 , 1 , 1 , 0 ) ;
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
// paste the transparent one on top of it
SDL_BlitSurface ( reds , NULL , imageset [ p ] . img [ MAXFRAMES * 2 + i ] , NULL ) ;
SDL_FreeSurface ( reds ) ;
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
// Convert the reddened image to the screen format
temps = SDL_DisplayFormat ( imageset [ p ] . img [ MAXFRAMES * 2 + i ] ) ;
SDL_FreeSurface ( imageset [ p ] . img [ MAXFRAMES * 2 + i ] ) ;
imageset [ p ] . img [ MAXFRAMES * 2 + i ] = temps ;
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
// Make the background red bits completely transparent
2008-10-07 16:53:06 +11:00
if ( isboss ( p ) ) {
SDL_SetColorKey ( imageset [ p ] . img [ MAXFRAMES * 2 + i ] ,
SDL_SRCCOLORKEY , SDL_MapRGB ( imageset [ p ] . img [ MAXFRAMES * 2 + i ] - > format , 99 , 97 , 99 ) ) ;
} else {
///SDL_Color tempcol;
///getpixelrgb(imageset[p].img[MAXFRAMES*2+i], 0, 0, &tempcol);
//printf("for spriteid %d, rgb is %d,%d,%d\n",p,tempcol.r,tempcol.g,tempcol.b);
SDL_SetColorKey ( imageset [ p ] . img [ MAXFRAMES * 2 + i ] ,
SDL_SRCCOLORKEY , SDL_MapRGB ( imageset [ p ] . img [ MAXFRAMES * 2 + i ] - > format , 99 , 0 , 0 ) ) ;
}
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
/* flipped angry image */
imageset [ p ] . img [ MAXFRAMES * 3 + i ] = rotozoomSurfaceXY ( imageset [ p ] . img [ MAXFRAMES * 2 + i ] , 0 , - 1 , 1 , 0 ) ;
2008-10-01 17:27:44 +10:00
2008-10-03 17:37:05 +10:00
/* flipped angry image */
/*
reds = SDL_CreateRGBSurface ( SDL_SWSURFACE ,
origi - > w ,
origi - > h ,
origi - > format - > BitsPerPixel , origi - > format - > Rmask ,
origi - > format - > Gmask , origi - > format - > Bmask , 0 ) ;
SDL_FillRect ( reds , NULL , SDL_MapRGB ( reds - > format , 255 , 0 , 0 ) ) ;
SDL_SetAlpha ( reds , SDL_SRCALPHA , 100 ) ;
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
imageset [ p ] . img [ MAXFRAMES * 3 + i ] = rotozoomSurfaceXY ( origi , 0 , - 1 , 1 , 0 ) ;
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
SDL_BlitSurface ( reds , NULL , imageset [ p ] . img [ MAXFRAMES * 3 + i ] , NULL ) ;
SDL_FreeSurface ( reds ) ;
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
temps = SDL_DisplayFormat ( imageset [ p ] . img [ MAXFRAMES * 3 + i ] ) ;
SDL_FreeSurface ( imageset [ p ] . img [ MAXFRAMES * 3 + i ] ) ;
imageset [ p ] . img [ MAXFRAMES * 3 + i ] = temps ;
2008-09-17 12:34:39 +10:00
2008-10-03 17:37:05 +10:00
SDL_SetColorKey ( imageset [ p ] . img [ MAXFRAMES * 3 + i ] ,
SDL_SRCCOLORKEY , SDL_MapRGB ( imageset [ p ] . img [ MAXFRAMES * 3 + i ] - > format , 101 , 0 , 0 ) ) ;
*/
}
2008-09-17 12:34:39 +10:00
}
}
return B_FALSE ;
}
void drawsprite ( sprite_t * s ) {
SDL_Rect area ;
2008-10-15 06:36:51 +11:00
int frame = 0 ;
2008-09-17 12:34:39 +10:00
2008-10-30 10:00:12 +11:00
// don't show caught mosnters in gunner mode
if ( ( s ! = player ) & & ( s - > caughtby = = player ) & & ( player - > powerup = = PW_GUNNER ) ) {
return ;
}
2008-09-28 13:18:36 +10:00
if ( ( s = = player ) & & ( levelcomplete = = LV_NEXTLEV ) ) {
frame = F_SHOOT ;
2008-10-07 16:53:06 +11:00
if ( curlevel - > exitdir = = D_RIGHT ) {
player - > dir = 1 ;
} else if ( curlevel - > exitdir = = D_LEFT ) {
player - > dir = - 1 ;
}
2008-09-28 13:18:36 +10:00
} else {
/* select frame */
if ( isfruit ( s - > id ) ) {
frame = F_WALK1 ;
} else if ( isbullet ( s - > id ) ) {
frame = F_WALK1 ;
} else if ( iseffect ( s - > id ) ) {
2008-10-03 17:37:05 +10:00
if ( ( s - > id = = P_PUFF ) | | ( s - > id = = P_SMASH ) | | ( s - > id = = P_SPARKLE ) ) {
if ( s - > timer1 > = imageset [ s - > id ] . numimages ) {
frame = imageset [ s - > id ] . numimages - 1 ;
2008-09-28 13:18:36 +10:00
} else if ( s - > timer1 < 0 ) {
// don't draw
return ;
} else {
frame = s - > timer1 ;
}
} else if ( s - > id = = P_GLOVE ) {
frame = F_WALK1 ;
2008-11-03 17:06:37 +11:00
} else if ( s - > id = = P_KSSHELL ) {
frame = F_WALK1 ;
2008-09-30 17:42:09 +10:00
} else if ( s - > id = = P_MACE ) {
frame = F_WALK1 ;
2008-10-07 16:53:06 +11:00
} else if ( s - > id = = P_CANNON ) {
frame = F_WALK1 ;
2008-10-30 12:06:25 +11:00
} else if ( s - > id = = P_ZAPPER ) {
if ( s - > timer1 > = imageset [ s - > id ] . numimages ) {
// just in case
frame = 0 ;
} else {
frame = s - > timer1 ;
}
2008-10-09 14:32:15 +11:00
} else if ( s - > id = = P_BUBBLE ) {
frame = F_WALK1 ;
2008-10-10 14:53:59 +11:00
} else if ( s - > id = = P_METEOR ) {
frame = F_WALK1 ;
2008-10-10 13:46:56 +11:00
} else if ( s - > id = = P_STAR ) {
frame = s - > timer1 ;
2008-10-13 11:43:01 +11:00
} else if ( s - > id = = P_MASK ) {
// only draw this if the player is swimming
if ( player - > swimming ) {
if ( player - > dir > 0 ) {
frame = 0 ;
} else {
frame = 1 ;
}
} else {
return ;
}
2008-10-15 14:20:10 +11:00
} else if ( s - > id = = P_MOVINGCARD ) {
// not really needed but included here for neatness
frame = F_WALK1 ;
} else if ( s - > id = = P_FIVECARDS ) {
// not really needed but included here for neatness
frame = F_WALK1 ;
2008-09-28 13:18:36 +10:00
}
2008-10-10 13:46:56 +11:00
2008-09-28 13:18:36 +10:00
} else if ( s - > dead ) {
if ( s = = player ) {
frame = F_DEAD ;
2008-10-07 16:53:06 +11:00
} else if ( s = = boss ) {
frame = F_DEAD ;
2008-10-09 14:32:15 +11:00
} else if ( s - > id = = P_SNAIL ) {
frame = F_DEAD ;
2008-09-27 16:02:42 +10:00
} else {
2008-09-28 13:18:36 +10:00
frame = F_DEAD + ( ( timer / 2 ) % 4 ) ;
2008-09-27 16:02:42 +10:00
}
2008-11-03 17:06:37 +11:00
} else if ( s - > id = = P_KINGSNAIL ) {
// frame based on state
switch ( s - > timer1 ) {
case KSS_WALK1 :
case KSS_WALK2 :
default :
if ( ( timer / 12 ) % 2 = = 0 ) {
frame = F_WALK1 ;
} else {
frame = F_JUMP ;
}
break ;
case KSS_PAUSE1 :
case KSS_PAUSE2 :
case KSS_PAUSE3 :
frame = F_WALK1 ;
break ;
case KSS_SHOOT :
case KSS_REGEN :
if ( s - > timer3 < 100 ) {
frame = F_CAUGHT ; // ie. broken shell
} else {
frame = F_WALK1 ;
}
break ;
case KSS_JUMPING :
frame = F_JUMP ;
break ;
}
2008-09-28 13:18:36 +10:00
} else if ( s - > caughtby ) {
frame = F_CAUGHT ;
} else if ( s - > climbing ) {
2008-09-30 17:42:09 +10:00
//frame = F_CLIMB1 + ((timer/12) % 2);
if ( s - > moved ) {
if ( ( timer / 12 ) % 2 = = 0 ) {
frame = F_CLIMB1 ;
} else {
frame = F_CLIMB2 ;
}
} else {
frame = F_CLIMB1 ;
}
2008-10-03 17:37:05 +10:00
} else if ( ( s - > swimming ) & & ( s = = player ) & & ! s - > slamming ) {
if ( ( timer / 12 ) % 2 = = 0 ) {
frame = F_SWIM1 ;
} else {
frame = F_SWIM2 ;
}
2008-09-28 13:18:36 +10:00
} else if ( s - > netting ) {
frame = F_SHOOT ;
2008-10-03 21:11:07 +10:00
} else if ( s - > iced ) {
frame = F_WALK1 ;
2008-09-28 13:18:36 +10:00
} else if ( s - > jumping ) {
2008-10-09 14:32:15 +11:00
if ( ( s - > id = = P_SNAIL ) & & ( s - > recoiling ) ) {
// when a snail is "jumping" it is actually recoiling
// and should look like a shell
frame = F_DEAD ;
} else if ( s - > id = = P_SLUG ) {
frame = F_FALL ;
} else {
frame = F_JUMP ;
}
2008-09-28 13:18:36 +10:00
} else if ( s - > falling ) {
2008-10-09 14:32:15 +11:00
if ( ( s - > id = = P_SNAIL ) & & ( s - > recoiling ) ) {
frame = F_DEAD ;
2008-11-09 16:31:24 +11:00
} else if ( s - > id = = P_FLY ) {
// same as flying
// toggle between flying frames
if ( ( timer / 3 ) % 2 = = 0 ) {
frame = F_WALK1 ;
} else {
frame = F_FALL ;
}
2008-10-09 14:32:15 +11:00
} else {
frame = F_FALL ;
}
2008-09-28 13:18:36 +10:00
} else if ( s - > slamming ) {
double slamdegs = s - > slamangle / ( M_PI / 180 ) ;
if ( slamdegs < 36 ) {
frame = F_SLAM1 ;
} else if ( slamdegs < 72 ) {
frame = F_SLAM2 ;
} else if ( slamdegs < 108 ) {
frame = F_SLAM3 ;
} else if ( slamdegs < 144 ) {
frame = F_SLAM4 ;
} else {
frame = F_SLAM5 ;
}
} else if ( ! s - > teleporting ) {
if ( ( s - > id = = P_SPIDER ) & & ( s - > ys ! = - 99 ) ) {
frame = F_FALL ;
} else {
2008-11-09 16:24:07 +11:00
// DEFAULT FOR EVERYTHING
2008-10-03 21:11:07 +10:00
// walking / sliding
if ( s - > moved = = MV_WALK ) {
2008-11-09 16:24:07 +11:00
// toggle between walking frames
2008-09-28 13:18:36 +10:00
if ( ( timer / 12 ) % 2 = = 0 ) {
frame = F_WALK1 ;
} else {
frame = F_JUMP ;
}
2008-11-09 16:24:07 +11:00
} else if ( s - > moved = = MV_FLY ) {
int animspeed ;
// fly animates faster
if ( ( s - > id = = P_FLY ) & & ( s - > flies ) ) {
animspeed = 3 ;
} else {
animspeed = 12 ;
}
// toggle between flying frames
if ( ( timer / animspeed ) % 2 = = 0 ) {
frame = F_WALK1 ;
} else {
frame = F_FALL ;
}
2008-10-03 21:11:07 +10:00
} else if ( s - > moved = = MV_ICE ) {
frame = F_FALL ;
2008-09-17 12:34:39 +10:00
} else {
2008-09-28 13:18:36 +10:00
frame = F_WALK1 ;
2008-09-17 12:34:39 +10:00
}
}
2008-09-28 13:18:36 +10:00
}
2008-09-17 12:34:39 +10:00
}
/* x-flip if required */
2008-10-10 10:12:51 +11:00
if ( ! isfruit ( s - > id ) & & ! iseffect ( s - > id ) & & ( s - > id ! = P_BLACKCLOUD ) ) {
2008-10-03 17:37:05 +10:00
if ( s - > dir = = - 1 ) {
frame + = MAXFRAMES ;
}
2008-11-03 17:06:37 +11:00
} else if ( ( s - > id = = P_GLOVE ) | | ( s - > id = = P_KSSHELL ) ) {
2008-10-23 12:18:49 +11:00
if ( s - > dir = = - 1 ) {
frame + = MAXFRAMES ;
}
2008-10-20 07:45:38 +11:00
} else if ( ( s - > id = = P_WINGLEFT ) | | ( s - > id = = P_WINGRIGHT ) ) {
if ( player - > dir = = - 1 ) {
frame + = MAXFRAMES ;
}
2008-09-17 12:34:39 +10:00
}
/* make red if required */
2008-10-10 10:12:51 +11:00
if ( s - > angry & & s - > id ! = P_BLACKCLOUD ) {
2008-10-27 16:36:25 +11:00
if ( s ! = player ) {
frame + = ( MAXFRAMES * 2 ) ;
}
2008-09-17 12:34:39 +10:00
}
2008-10-15 14:20:10 +11:00
if ( s - > id = = P_MOVINGCARD ) {
// image comes from timer1
s - > img = imageset [ s - > timer1 ] . img [ F_WALK1 ] ;
} else if ( s - > id = = P_FIVECARDS ) {
// do nothing - img already there!
2008-11-06 13:15:49 +11:00
} else if ( s - > id = = P_RANDOM ) {
// image based on timer1
s - > img = imageset [ s - > timer1 ] . img [ F_WALK1 ] ;
2008-10-15 14:20:10 +11:00
} else if ( ( s - > id ! = P_BLACKCLOUD ) & & ( s - > id ! = P_PINKCLOUD ) & & ( ! s - > teleporting ) ) {
2008-11-09 16:24:07 +11:00
// ALL OTHERS:
2008-10-15 14:20:10 +11:00
// select image based on sprite id
2008-09-17 12:34:39 +10:00
s - > img = imageset [ s - > id ] . img [ frame ] ;
}
2008-10-30 12:06:25 +11:00
// zapper lightning bolt
if ( ( s - > id = = P_ZAPPER ) & & ( s - > timer4 > 0 ) ) {
if ( s - > zapping ) {
SDL_Color col ;
double zapx , zapy ;
switch ( timer % 4 ) {
case 0 : col . r = 255 ; col . g = 255 ; col . b = 255 ; break ;
case 1 : col . r = 0 ; col . g = 0 ; col . b = 0 ; break ;
case 2 : col . r = 0 ; col . g = 255 ; col . b = 255 ; break ;
default :
case 3 : col . r = 0 ; col . g = 0 ; col . b = 0 ; break ;
}
// draw lines to zap position
zapx = s - > zapping - > x ;
zapy = s - > zapping - > y ;
drawline16 ( screen , s - > x , s - > y - ( s - > img - > h / 2 ) , zapx , zapy , col ) ;
drawline16 ( screen , s - > x + 1 , s - > y - ( s - > img - > h / 2 ) , zapx , zapy , col ) ;
drawline16 ( screen , s - > x - 1 , s - > y - ( s - > img - > h / 2 ) , zapx , zapy , col ) ;
drawline16 ( screen , s - > x , s - > y + 1 - ( s - > img - > h / 2 ) , zapx , zapy , col ) ;
drawline16 ( screen , s - > x , s - > y - 1 - ( s - > img - > h / 2 ) , zapx , zapy , col ) ;
} else { // the thing we were zapping died!
s - > timer4 = 0 ;
}
}
2008-09-17 12:34:39 +10:00
/* spider's climbing web */
2008-10-03 21:11:07 +10:00
if ( ( s - > id = = P_SPIDER ) & & ( ( s - > ys ! = - 99 ) | | s - > falling ) & & ! s - > dead & & ! s - > caughtby & & ! s - > iced ) {
2008-09-17 12:34:39 +10:00
tiletype_t * tt ;
int x = s - > x ;
int y = s - > y - s - > img - > h / 2 ;
int tx = 0 , ty = 0 ;
int done = B_FALSE ;
for ( y = s - > y ; ! done ; y - = TILEH ) {
tt = gettileat ( x , y , & tx , & ty ) ;
if ( ( tt = = NULL ) | | ( tt - > solid ) ) {
done = B_TRUE ;
}
2008-10-23 16:57:46 +11:00
if ( y < 0 ) { // nothing above us!
// die!
s - > dead = D_FINAL ;
puffin ( - 1 , s - > x , s - > y , " spiderdeath " , 0 ) ;
return ;
}
2008-09-17 12:34:39 +10:00
}
drawline16 ( screen , s - > x , s - > y - ( s - > img - > h / 2 ) , s - > x , ty * TILEH + TILEH - 1 , white ) ;
}
2008-10-09 14:32:15 +11:00
// override
if ( ( s - > id = = P_SNAIL ) & & ( s - > recoiling ) ) {
frame = F_DEAD ;
}
2008-09-17 12:34:39 +10:00
2008-10-15 06:36:51 +11:00
s - > frame = frame ;
2008-09-17 12:34:39 +10:00
area . x = s - > x - ( s - > img - > w / 2 ) ;
area . y = s - > y - ( s - > img - > h ) ;
area . w = 0 ;
area . h = 0 ;
2008-10-30 12:06:25 +11:00
// don't blink invuln things while showing help text
2008-10-20 10:45:15 +11:00
if ( ( s - > invuln ) & & ( levelcomplete ! = LV_HELPFREEZE ) ) {
2008-10-20 07:45:38 +11:00
if ( timer % 2 = = 0 ) {
//SDL_BlitSurface(s->img, NULL, screen, &area);
if ( s = = player ) {
drawplayer ( s , & area ) ;
} else {
2008-10-09 14:32:15 +11:00
doblit ( s - > img , screen , & area ) ;
2008-10-07 16:53:06 +11:00
}
2008-10-20 07:45:38 +11:00
}
2008-10-30 12:06:25 +11:00
} else if ( ( s - > doomcount > 0 ) & & ( s - > doomcount < = 150 ) & & ( levelcomplete ! = LV_HELPFREEZE ) ) {
if ( ( timer / 2 ) % 2 = = 0 ) {
if ( s = = player ) {
drawplayer ( s , & area ) ;
} else {
doblit ( s - > img , screen , & area ) ;
}
}
2008-10-20 07:45:38 +11:00
} else if ( s = = boss & & s - > dead ) {
if ( ( timer / 10 ) % 2 = = 0 ) {
2008-10-09 14:32:15 +11:00
//SDL_BlitSurface(s->img, NULL, screen, &area);
doblit ( s - > img , screen , & area ) ;
2008-09-17 12:34:39 +10:00
}
2008-10-20 07:45:38 +11:00
} else {
if ( s = = player ) {
drawplayer ( s , & area ) ;
} else {
doblit ( s - > img , screen , & area ) ;
2008-11-03 17:06:37 +11:00
// king snail regenerating shell...
if ( ( s - > id = = P_KINGSNAIL ) & & ( s - > timer1 = = KSS_REGEN ) ) {
SDL_Surface * shellimg , * srcimg ;
SDL_Rect newarea ;
double pct ;
// shell image -left or right?
if ( s - > dir = = 1 ) {
srcimg = imageset [ P_KSSHELL ] . img [ 0 ] ;
} else {
srcimg = imageset [ P_KSSHELL ] . img [ MAXFRAMES ] ;
}
// generate new shell at correct size ...
pct = ( ( double ) s - > timer3 / 100 ) ;
if ( pct > 1 ) pct = 1 ;
shellimg = rotozoomSurfaceXY ( srcimg , 0 , pct , pct , 0 ) ;
// blit it
2008-11-05 07:27:01 +11:00
if ( s - > dir = = 1 ) {
newarea . x = s - > x - ( shellimg - > w / 2 ) - 21 ;
} else {
newarea . x = s - > x - ( shellimg - > w / 2 ) + 21 ;
}
2008-11-03 17:06:37 +11:00
newarea . y = s - > y - ( shellimg - > h / 2 ) - 28 ;
newarea . w = 0 ;
newarea . h = 0 ;
SDL_BlitSurface ( shellimg , NULL , screen , & newarea ) ;
// free it
SDL_FreeSurface ( shellimg ) ;
}
2008-10-20 07:45:38 +11:00
}
}
2008-10-03 21:11:07 +10:00
2008-10-20 07:45:38 +11:00
// ice cube
if ( s - > iced ) {
if ( ! s - > iceimg ) {
double xmod , ymod ;
xmod = ( double ) s - > img - > w / ( double ) icecube - > w ;
ymod = ( double ) s - > img - > h / ( double ) icecube - > h ;
// create image
s - > iceimg = rotozoomSurfaceXY ( icecube , 0 , xmod , ymod , 0 ) ;
2008-10-03 21:11:07 +10:00
}
2008-10-20 07:45:38 +11:00
// draw it
doblit ( s - > iceimg , screen , & area ) ;
//SDL_BlitSurface(s->iceimg, NULL, screen, &area);
}
2008-09-17 12:34:39 +10:00
2008-10-03 21:11:07 +10:00
2008-09-17 12:34:39 +10:00
/* caughtby lines */
if ( ( s - > caughtby ) & & ( s - > caughtstate = = 2 ) ) {
2008-10-09 14:32:15 +11:00
// only if we're on the screen
if ( ( s - > y > = 0 ) & & ( s - > y < = 480 ) ) {
drawline16 ( screen , s - > x , s - > y - s - > img - > h ,
s - > caughtby - > x , s - > caughtby - > y - ( s - > caughtby - > img - > h / 2 ) , white ) ;
drawline16 ( screen , s - > x , s - > y - ( s - > img - > h / 2 ) ,
s - > caughtby - > x , s - > caughtby - > y - ( s - > caughtby - > img - > h / 2 ) , white ) ;
drawline16 ( screen , s - > x , s - > y ,
s - > caughtby - > x , s - > caughtby - > y - ( s - > caughtby - > img - > h / 2 ) , white ) ;
}
2008-09-17 12:34:39 +10:00
}
}
void killsprite ( sprite_t * s ) {
sprite_t * nextone , * lastone ;
2008-10-20 07:45:38 +11:00
# ifndef __EDITOR
2008-09-17 12:34:39 +10:00
sprite_t * s2 ;
2008-10-07 16:53:06 +11:00
// remove boss pointer
if ( boss = = s ) {
boss = NULL ;
}
2008-10-19 09:00:31 +11:00
// remove mask pointer
2008-10-13 11:43:01 +11:00
if ( mask = = s ) {
mask = NULL ;
}
2008-10-23 08:38:56 +11:00
if ( s - > caughtby ) {
s - > caughtby = NULL ;
s - > caughtstate = B_FALSE ;
player - > netcaught - - ;
}
2008-10-30 12:06:25 +11:00
s - > zapping = NULL ;
2008-09-17 12:34:39 +10:00
/* remove references to this sprite before removing it */
for ( s2 = sprite ; s2 ; s2 = s2 - > next ) {
if ( s2 - > owner = = s ) {
s2 - > owner = NULL ;
}
if ( s2 - > bullet = = s ) {
s2 - > bullet = NULL ;
}
2008-10-30 12:06:25 +11:00
if ( s2 - > zapping = = s ) {
s2 - > zapping = NULL ;
}
2008-09-17 12:34:39 +10:00
}
2008-10-03 21:11:07 +10:00
// free ice image
if ( s - > iceimg ) {
SDL_FreeSurface ( s - > iceimg ) ;
}
2008-10-23 17:10:35 +11:00
// free image for certain types
switch ( s - > id ) {
case P_FIVECARDS :
case P_PINKCLOUD :
case P_BLACKCLOUD :
if ( s - > img ) {
SDL_FreeSurface ( s - > img ) ;
}
break ;
2008-10-15 14:20:10 +11:00
}
2008-10-20 07:45:38 +11:00
# endif
2008-10-15 14:20:10 +11:00
2008-09-17 12:34:39 +10:00
nextone = s - > next ;
if ( nextone ! = NULL ) {
nextone - > prev = s - > prev ;
} else { /*last sprite */
lastsprite = s - > prev ;
}
if ( s - > prev = = NULL ) {
/* first sprite */
nextone = sprite - > next ;
free ( sprite ) ;
sprite = nextone ;
} else {
lastone = s - > prev ;
free ( lastone - > next ) ;
lastone - > next = nextone ;
}
}
void flip ( void ) {
# ifdef OPENGL
SDL_UpdateRect ( screen , 0 , 0 , screen - > w , screen - > h ) ;
2008-10-01 22:42:59 +10:00
SDL_GL_SwapBuffers ( ) ;
2008-09-17 12:34:39 +10:00
# else
SDL_Flip ( screen ) ;
# endif
}
2008-09-17 21:16:19 +10:00
// returns 0 if tile isn't animated, else the number of frames
int gettileframecount ( int tid ) {
tiletype_t * tt ;
tt = gettile ( tid ) ;
return tt - > numframes ;
}
2008-09-27 16:02:42 +10:00
// returns gem type for a given flower
int flowertogem ( int id ) {
switch ( id ) {
case P_FLOWERRED :
return P_GEMRED ;
case P_FLOWERYELLOW :
return P_GEMYELLOW ;
case P_FLOWERPURPLE :
return P_GEMPURPLE ;
}
return P_GEMRED ;
}
2008-10-15 06:36:51 +11:00
int iscard ( int id ) {
if ( ( id > = P_FIRSTCARD ) & & ( id < = P_FIRSTCARD + 51 ) ) {
return B_TRUE ;
}
return B_FALSE ;
}
2008-09-27 16:02:42 +10:00
int isflower ( int id ) {
switch ( id ) {
case P_FLOWERRED :
case P_FLOWERYELLOW :
case P_FLOWERPURPLE :
return B_TRUE ;
}
return B_FALSE ;
}
2008-09-17 12:34:39 +10:00
int isfruit ( int id ) {
switch ( id ) {
2008-09-28 13:18:36 +10:00
/* fruits */
2008-09-17 12:34:39 +10:00
case P_CHEESE :
case P_ICECREAM :
case P_CHIPS :
case P_BURGER :
2008-09-28 13:18:36 +10:00
case P_DIAMOND :
2008-10-07 20:18:42 +11:00
return FT_FRUIT ;
2008-11-05 08:13:44 +11:00
/* super powerups */
case P_BIGSPEED :
case P_BIGNUMNETS :
return FT_SUPER ;
2008-10-03 17:37:05 +10:00
/* permenant powerups */
2008-09-17 12:34:39 +10:00
case P_SPEED :
case P_NUMNETS :
case P_BIGNET :
case P_HELP :
2008-10-03 17:37:05 +10:00
case P_GEMBOOST :
case P_BELL :
2008-10-07 20:18:42 +11:00
case P_TROPHY :
2008-10-10 11:51:40 +11:00
case P_HONEY :
2008-10-18 15:23:02 +11:00
case P_HELMET :
2008-10-13 11:43:01 +11:00
case P_MASKPOWERUP :
2008-10-18 15:49:08 +11:00
case P_WINGBOOTS :
2008-10-07 20:18:42 +11:00
return FT_PERM ;
2008-10-03 17:37:05 +10:00
/* one-off level only powerups */
2008-09-28 13:18:36 +10:00
case P_BOXING :
2008-09-30 17:42:09 +10:00
case P_MACEPOWERUP :
2008-09-28 14:09:12 +10:00
case P_FTODIAMOND :
case P_FTOGEM :
2008-09-28 14:42:09 +10:00
case P_BOMB :
2008-10-10 13:46:56 +11:00
case P_STARPOWERUP :
2008-10-10 14:53:59 +11:00
case P_UFO :
2008-10-10 11:51:40 +11:00
case P_LIFE :
2008-10-10 10:49:43 +11:00
case P_PHONE :
2008-09-28 15:19:23 +10:00
case P_SHIELD :
2008-10-03 17:37:05 +10:00
case P_RINGSILVER :
case P_RINGGOLD :
case P_CLOCK :
2008-10-03 21:11:07 +10:00
case P_SNOWMAN :
2008-10-13 11:43:01 +11:00
case P_TAP :
2008-10-07 16:53:06 +11:00
case P_SPRAY :
case P_CANNONPOWERUP :
2008-10-18 14:18:24 +11:00
case P_CLOVER :
2008-10-18 15:16:06 +11:00
case P_ACCORDION :
2008-10-30 10:00:12 +11:00
case P_GUN :
2008-10-30 12:06:25 +11:00
case P_ZAPPOWERUP :
2008-10-18 16:10:10 +11:00
case P_SKULL :
2008-11-06 13:15:49 +11:00
case P_RANDOM :
2008-10-07 20:18:42 +11:00
return FT_TEMP ;
2008-09-28 13:18:36 +10:00
/* flowers */
2008-09-26 19:51:17 +10:00
case P_FLOWERYELLOW :
2008-09-27 16:02:42 +10:00
case P_FLOWERRED :
2008-09-26 19:51:17 +10:00
case P_FLOWERPURPLE :
2008-09-28 13:18:36 +10:00
/* gems */
2008-09-27 16:02:42 +10:00
case P_GEMYELLOW :
case P_GEMRED :
case P_GEMPURPLE :
2008-10-10 12:30:40 +11:00
return FT_GEM ;
2008-09-29 18:32:56 +10:00
/* misc */
case P_POWERUPPOS :
2008-10-07 20:18:42 +11:00
return FT_OTHER ;
2008-09-17 12:34:39 +10:00
}
2008-10-15 14:20:10 +11:00
if ( iscard ( id ) ) return FT_CARD ;
2008-10-15 06:36:51 +11:00
2008-09-17 12:34:39 +10:00
return B_FALSE ;
}
int isbullet ( int id ) {
if ( id = = P_SPIT ) return B_TRUE ;
return B_FALSE ;
}
2008-11-06 20:15:09 +11:00
int isplatform ( int id ) {
switch ( id ) {
case P_PLATFORM :
return B_TRUE ;
}
return B_FALSE ;
}
2008-09-27 16:02:42 +10:00
int iseffect ( int id ) {
2008-10-09 14:32:15 +11:00
switch ( id ) {
case P_PUFF :
case P_SPARKLE :
case P_SMASH :
2008-11-03 17:06:37 +11:00
case P_KSSHELL :
2008-10-09 14:32:15 +11:00
case P_POWERUPPOS :
case P_GLOVE :
case P_MACE :
case P_PINKCLOUD :
case P_CANNON :
2008-10-30 12:06:25 +11:00
case P_ZAPPER :
2008-10-09 14:32:15 +11:00
case P_BUBBLE :
2008-10-10 13:46:56 +11:00
case P_STAR :
2008-10-10 14:53:59 +11:00
case P_METEOR :
2008-10-13 11:43:01 +11:00
case P_MASK :
2008-10-15 14:20:10 +11:00
case P_MOVINGCARD :
case P_FIVECARDS :
2008-10-20 07:45:38 +11:00
// these last two aren't REALLY effects since they never have a sprite allocated
case P_WINGLEFT :
case P_WINGRIGHT :
2008-11-06 20:15:09 +11:00
case P_PLATFORM :
2008-10-09 14:32:15 +11:00
return B_TRUE ;
}
2008-09-27 16:02:42 +10:00
return B_FALSE ;
}
2008-10-03 17:37:05 +10:00
int needscollisions ( int id ) {
if ( id = = P_SMASH ) return B_TRUE ;
2008-10-10 13:46:56 +11:00
if ( id = = P_STAR ) return B_TRUE ;
2008-10-10 14:53:59 +11:00
if ( id = = P_METEOR ) return B_TRUE ;
2008-10-30 12:06:25 +11:00
if ( id = = P_ZAPPER ) return B_TRUE ;
2008-11-06 20:15:09 +11:00
if ( isplatform ( id ) ) return B_TRUE ;
2008-10-03 17:37:05 +10:00
return B_FALSE ;
}
2008-10-01 17:27:44 +10:00
# ifdef OPENGL
inline void drawpixel16 ( SDL_Surface * screen , int x , int y , SDL_Color c )
{
Uint8 * bufp ;
/* check x/y */
if ( x > = screen - > w ) return ;
if ( y > = screen - > h ) return ;
if ( x < 0 ) return ;
if ( y < 0 ) return ;
// bufp = (Uint16 *)screen->pixels + (y*screen->pitch / 2) + x;
bufp = ( Uint8 * ) screen - > pixels + y * screen - > pitch + x * 4 ;
// *bufp = SDL_MapRGB(screen->format, c.r, c.g, c.b);
* ( Uint32 * ) bufp = SDL_MapRGB ( screen - > format , c . r , c . g , c . b ) ;
}
# else
2008-09-17 12:34:39 +10:00
inline void drawpixel16 ( SDL_Surface * screen , int x , int y , SDL_Color c )
{
Uint16 * bufp ;
/* check x/y */
if ( x > = screen - > w ) return ;
if ( y > = screen - > h ) return ;
if ( x < 0 ) return ;
if ( y < 0 ) return ;
bufp = ( Uint16 * ) screen - > pixels + ( y * screen - > pitch / 2 ) + x ;
* bufp = SDL_MapRGB ( screen - > format , c . r , c . g , c . b ) ;
}
2008-10-01 17:27:44 +10:00
# endif
2008-09-17 12:34:39 +10:00
void drawline16 ( SDL_Surface * screen , int x1 , int y1 , int x2 , int y2 , SDL_Color c ) {
int deltax , deltay ;
int numpixels ;
int d ;
int dinc1 , dinc2 , xinc1 , xinc2 , yinc1 , yinc2 ;
int i ;
int x ;
int y ;
int maskcount = 0 ;
int maskindex = 0 ;
deltax = ( x2 - x1 ) ;
if ( deltax < 0 ) deltax = - deltax ;
deltay = ( y2 - y1 ) ;
if ( deltay < 0 ) deltay = - deltay ;
if ( deltax > = deltay ) {
numpixels = deltax + 1 ;
d = ( deltay * 2 ) - deltax ;
dinc1 = deltay < < 1 ;
dinc2 = ( deltay - deltax ) < < 1 ;
xinc1 = 1 ;
xinc2 = 1 ;
yinc1 = 0 ;
yinc2 = 1 ;
} else {
numpixels = deltay + 1 ;
d = ( deltax * 2 ) - deltay ;
dinc1 = deltax < < 1 ;
dinc2 = ( deltax - deltay ) < < 1 ;
xinc1 = 0 ;
xinc2 = 1 ;
yinc1 = 1 ;
yinc2 = 1 ;
}
if ( x1 > x2 ) {
xinc1 = - xinc1 ;
xinc2 = - xinc2 ;
}
if ( y1 > y2 ) {
yinc1 = - yinc1 ;
yinc2 = - yinc2 ;
}
x = x1 ; y = y1 ;
maskcount = 0 ;
maskindex = 0 ;
for ( i = 0 ; i < numpixels ; i + + ) {
drawpixel16 ( screen , x , y , c ) ;
2008-10-10 11:51:40 +11:00
if ( d < 0 ) {
d + = dinc1 ;
x + = xinc1 ;
y + = yinc1 ;
} else {
d + = dinc2 ;
x + = xinc2 ;
y + = yinc2 ;
}
}
}
// draw line with alternating colours
void drawdotline16 ( SDL_Surface * screen , int x1 , int y1 , int x2 , int y2 , SDL_Color c , SDL_Color c2 ) {
int deltax , deltay ;
int numpixels ;
int d ;
int dinc1 , dinc2 , xinc1 , xinc2 , yinc1 , yinc2 ;
int i ;
int x ;
int y ;
int maskcount = 0 ;
int maskindex = 0 ;
deltax = ( x2 - x1 ) ;
if ( deltax < 0 ) deltax = - deltax ;
deltay = ( y2 - y1 ) ;
if ( deltay < 0 ) deltay = - deltay ;
if ( deltax > = deltay ) {
numpixels = deltax + 1 ;
d = ( deltay * 2 ) - deltax ;
dinc1 = deltay < < 1 ;
dinc2 = ( deltay - deltax ) < < 1 ;
xinc1 = 1 ;
xinc2 = 1 ;
yinc1 = 0 ;
yinc2 = 1 ;
} else {
numpixels = deltay + 1 ;
d = ( deltax * 2 ) - deltay ;
dinc1 = deltax < < 1 ;
dinc2 = ( deltax - deltay ) < < 1 ;
xinc1 = 0 ;
xinc2 = 1 ;
yinc1 = 1 ;
yinc2 = 1 ;
}
if ( x1 > x2 ) {
xinc1 = - xinc1 ;
xinc2 = - xinc2 ;
}
if ( y1 > y2 ) {
yinc1 = - yinc1 ;
yinc2 = - yinc2 ;
}
x = x1 ; y = y1 ;
maskcount = 0 ;
maskindex = 0 ;
for ( i = 0 ; i < numpixels ; i + + ) {
if ( i % 2 = = 0 ) {
drawpixel16 ( screen , x , y , c ) ;
} else {
drawpixel16 ( screen , x , y , c2 ) ;
}
2008-09-17 12:34:39 +10:00
if ( d < 0 ) {
d + = dinc1 ;
x + = xinc1 ;
y + = yinc1 ;
} else {
d + = dinc2 ;
x + = xinc2 ;
y + = yinc2 ;
}
}
}
void drawbox16 ( SDL_Surface * screen , int x1 , int y1 , int x2 , int y2 , SDL_Color * c , SDL_Color * fc ) {
if ( fc ! = NULL ) {
/* fill */
if ( ( ( x2 - x1 ) > = 2 ) & & ( ( y2 - y1 ) > = 2 ) ) {
int y ;
for ( y = ( y1 + 1 ) ; y < = ( y2 - 1 ) ; y + + ) {
drawline16 ( screen , x1 + 1 , y , x2 - 1 , y , * fc ) ;
}
}
}
drawline16 ( screen , x1 , y1 , x2 , y1 , * c ) ;
drawline16 ( screen , x1 , y1 , x1 , y2 , * c ) ;
drawline16 ( screen , x1 , y2 , x2 , y2 , * c ) ;
drawline16 ( screen , x2 , y1 , x2 , y2 , * c ) ;
}
int getcolor ( SDL_Surface * dest , int x , int y , SDL_Color * col ) {
Uint32 pixel ;
int bpp = dest - > format - > BytesPerPixel ;
char * ppos ;
unsigned char r , g , b , a ;
ppos = ( char * ) dest - > pixels ;
/* offset y */
ppos + = ( dest - > pitch * y ) ;
/* offset x */
ppos + = ( bpp * x ) ;
memcpy ( & pixel , ppos , bpp ) ;
if ( dest - > format - > BitsPerPixel = = 32 ) {
SDL_GetRGBA ( pixel , dest - > format , & r , & g , & b , & a ) ;
col - > r = r ;
col - > g = g ;
col - > b = b ;
col - > unused = a ;
} else if ( dest - > format - > BitsPerPixel = = 16 ) {
SDL_GetRGB ( pixel , dest - > format , & r , & g , & b ) ;
col - > r = r ;
col - > g = g ;
col - > b = b ;
} else if ( dest - > format - > BitsPerPixel = = 8 ) {
* col = dest - > format - > palette - > colors [ ( Uint8 ) pixel ] ;
}
return 0 ;
}
2008-09-29 18:32:56 +10:00
tiletype_t * gettile ( int uniqid ) {
2008-09-17 12:34:39 +10:00
tiletype_t * t ;
for ( t = tiletype ; t ; t = t - > next ) {
2008-09-29 18:32:56 +10:00
if ( t - > uniqid = = uniqid ) return t ;
2008-09-17 12:34:39 +10:00
}
return & fakeblock ;
}
2008-09-29 18:32:56 +10:00
int getuniq ( int tileid ) {
tiletype_t * t ;
for ( t = tiletype ; t ; t = t - > next ) {
if ( t - > id = = tileid ) return t - > uniqid ;
}
return 0 ;
}
2008-09-17 12:34:39 +10:00
void drawtile ( SDL_Surface * where , int x , int y ) {
SDL_Rect area ;
tiletype_t * tt ;
2008-09-17 21:16:19 +10:00
int frame ;
int offset ;
2008-09-17 12:34:39 +10:00
if ( ( x < 0 ) | | ( y < 0 ) | | ( x > = LEVELW ) | | ( y > = LEVELH ) ) {
return ;
}
area . x = x * TILEW ;
area . y = y * TILEH ;
2008-09-30 17:42:09 +10:00
area . w = TILEW ;
area . h = TILEH ;
2008-09-17 12:34:39 +10:00
/* draw blank tile first */
tt = gettile ( curlevel - > bgtileid ) ;
2008-09-30 17:42:09 +10:00
SDL_BlitSurface ( levelbg , & area , where , & area ) ;
2008-09-17 12:34:39 +10:00
2008-09-17 21:16:19 +10:00
/* now draw real one */
offset = y * LEVELW + x ;
tt = gettile ( curlevel - > map [ offset ] ) ;
frame = curlevel - > tileframe [ offset ] ;
2008-09-17 12:34:39 +10:00
if ( tt - > id ! = curlevel - > bgtileid ) {
2008-09-17 21:16:19 +10:00
SDL_BlitSurface ( tt - > img [ frame ] , NULL , where , & area ) ;
2008-09-17 12:34:39 +10:00
}
2008-09-17 21:16:19 +10:00
2008-09-29 18:32:56 +10:00
/* now draw layer2 if it exists */
if ( curlevel - > map2 [ offset ] ! = T_BLANK ) {
tt = gettile ( curlevel - > map2 [ offset ] ) ;
if ( tt - > id ! = curlevel - > bgtileid ) {
SDL_BlitSurface ( tt - > img [ frame ] , NULL , where , & area ) ;
}
}
2008-09-17 12:34:39 +10:00
}
void initglobals ( void ) {
sprite = NULL ;
2008-09-17 21:16:19 +10:00
level = NULL ;
2008-09-17 12:34:39 +10:00
vidargs = 0 ;
/* timers */
gtime = 0 ;
timer = 0 ;
toggletimer = 0 ;
/* colours */
red . r = 255 ; red . g = 0 ; red . b = 0 ;
black . r = 0 ; black . g = 0 ; black . b = 0 ;
2008-09-30 17:42:09 +10:00
blue . r = 0 ; blue . g = 0 ; blue . b = 255 ;
2008-09-17 12:34:39 +10:00
white . r = 255 ; white . g = 255 ; white . b = 255 ;
green . r = 0 ; green . g = 255 ; green . b = 0 ;
yellow . r = 255 ; yellow . g = 255 ; yellow . b = 0 ;
}
2008-09-17 21:16:19 +10:00
SDL_Surface * loadspriteimage ( int spriteid , int frame , char * filename ) {
2008-10-10 07:51:09 +11:00
char fullfile [ BUFLEN ] ;
sprintf ( fullfile , " %s/%s " , datadir , filename ) ;
2008-10-10 08:04:41 +11:00
imageset [ spriteid ] . img [ frame ] = IMG_Load ( fullfile ) ;
2008-09-17 21:16:19 +10:00
if ( imageset [ spriteid ] . img [ frame ] = = NULL ) {
2008-10-10 08:04:41 +11:00
printf ( " Error loading image file: %s \n " , fullfile ) ;
2008-09-17 21:16:19 +10:00
exit ( 1 ) ;
}
return imageset [ spriteid ] . img [ frame ] ;
}
2008-09-27 16:02:42 +10:00
int candoslopes ( int sid ) {
switch ( sid ) {
case P_SNAKE :
2008-10-09 14:32:15 +11:00
case P_SNAIL :
case P_SLUG :
2008-09-27 16:02:42 +10:00
return B_FALSE ;
}
return B_TRUE ;
}
2008-09-27 20:50:19 +10:00
int ismonster ( int id ) {
2008-10-07 20:18:42 +11:00
switch ( id ) {
case P_RAT :
case P_BEE :
2008-11-09 16:24:07 +11:00
case P_FLY :
2008-10-07 20:18:42 +11:00
case P_SPIDER :
case P_SNAKE :
2008-10-13 11:43:01 +11:00
case P_TICK :
2008-10-24 14:31:25 +11:00
case P_PLANT :
2008-10-09 14:32:15 +11:00
case P_SNAIL :
case P_SLUG :
2008-10-10 21:06:40 +11:00
case P_FISH :
2008-10-07 20:18:42 +11:00
return MT_MONSTER ;
case P_BLACKCLOUD :
case P_KINGRAT :
2008-11-01 08:13:27 +11:00
case P_KINGSNAIL :
2008-10-07 20:18:42 +11:00
return MT_BOSS ;
}
2008-09-27 20:50:19 +10:00
return B_FALSE ;
}
2008-09-28 13:18:36 +10:00
void puffin ( int willbecome , int x , int y , char * name , int delay ) {
sprite_t * ss ;
ss = addsprite ( P_PUFF , x , y , " puff " ) ;
ss - > timer3 = willbecome ;
ss - > timer1 = - delay ;
strncpy ( ss - > name , name , MIDBUFLEN ) ;
}
/*
void removetext ( void ) {
SDL_Rect sarea ;
text_t * t ;
for ( t = text ; t ; t = t - > next ) {
sarea . x = 0 ;
sarea . y = 0 ;
sarea . w = t - > bgarea . w ;
sarea . h = t - > bgarea . h ;
SDL_BlitSurface ( t - > bg , & sarea , screen , & t - > bgarea ) ;
}
}
*/
void killtext ( text_t * t ) {
text_t * nextone , * lastone ;
if ( t - > bg ) {
SDL_FreeSurface ( t - > bg ) ;
t - > bg = NULL ;
}
if ( t - > img ) {
SDL_FreeSurface ( t - > img ) ;
t - > img = NULL ;
}
nextone = t - > next ;
if ( nextone ! = NULL ) {
nextone - > prev = t - > prev ;
} else { /*last text */
lasttext = t - > prev ;
}
if ( t - > prev = = NULL ) {
/* first text */
nextone = text - > next ;
free ( text ) ;
text = nextone ;
} else {
lastone = t - > prev ;
free ( lastone - > next ) ;
lastone - > next = nextone ;
}
/* if we're killing text during LV_INIT, it must have been
the level announcement . That means that we can start
moving .
*/
2008-10-03 17:37:05 +10:00
if ( levelcomplete = = LV_INIT ) {
levelcomplete = LV_INPROGRESS ;
}
2008-09-28 13:18:36 +10:00
}
2008-09-28 14:09:12 +10:00
// returns score of given fruit type
int getpoints ( int id ) {
int points ;
switch ( id ) {
case P_CHEESE :
2008-10-03 17:37:05 +10:00
points = 1000 ;
2008-09-28 14:09:12 +10:00
break ;
case P_ICECREAM :
2008-10-03 17:37:05 +10:00
points = 1500 ;
2008-09-28 14:09:12 +10:00
break ;
case P_CHIPS :
2008-10-03 17:37:05 +10:00
points = 2000 ;
2008-09-28 14:09:12 +10:00
break ;
case P_BURGER :
2008-10-03 17:37:05 +10:00
points = 2500 ;
2008-09-28 14:09:12 +10:00
break ;
case P_DIAMOND :
2008-10-03 17:37:05 +10:00
points = 3000 ;
2008-09-28 14:09:12 +10:00
break ;
case P_FLOWERYELLOW :
points = 5 ;
break ;
case P_FLOWERRED :
points = 10 ;
break ;
case P_FLOWERPURPLE :
points = 30 ;
break ;
case P_GEMYELLOW :
points = 50 ;
break ;
case P_GEMRED :
points = 75 ;
break ;
case P_GEMPURPLE :
points = 100 ;
break ;
default :
points = 0 ;
break ;
}
return points ;
}
2008-09-30 17:42:09 +10:00
2008-10-07 16:53:06 +11:00
int savelevellist ( void ) {
2008-10-10 07:51:09 +11:00
char filename [ BUFLEN ] ;
2008-10-07 16:53:06 +11:00
FILE * f ;
int i ;
2008-10-10 07:51:09 +11:00
sprintf ( filename , " %s/levels.dat " , datadir ) ;
f = fopen ( filename , " w " ) ;
2008-10-07 16:53:06 +11:00
if ( ! f ) {
printf ( " error writing to levels.dat \n " ) ;
return B_FALSE ;
}
for ( i = 1 ; i < numlevels ; i + + ) {
fprintf ( f , " %d,%s,%s \n " , levelentry [ i ] . id , levelentry [ i ] . filename , levelentry [ i ] . desc ) ;
}
fclose ( f ) ;
return B_FALSE ;
}
2008-09-30 17:42:09 +10:00
int loadlevellist ( void ) {
int lev ;
2008-10-10 07:51:09 +11:00
char filename [ BUFLEN ] ;
2008-09-30 17:42:09 +10:00
FILE * f ;
char buf [ BUFLEN ] ;
char * p ;
2008-10-10 07:51:09 +11:00
sprintf ( filename , " %s/levels.dat " , datadir ) ;
f = fopen ( filename , " r " ) ;
2008-10-10 10:12:51 +11:00
if ( ! f ) {
printf ( " Error opening levels data file \n " ) ;
exit ( 1 ) ;
}
2008-09-30 17:42:09 +10:00
// format is:
//
2008-10-01 17:27:44 +10:00
// id,filename,description,
2008-09-30 17:42:09 +10:00
lev = 1 ;
2008-10-07 16:53:06 +11:00
maxlevid = - 99 ;
2008-09-30 17:42:09 +10:00
fgets ( buf , BUFLEN , f ) ;
while ( ! feof ( f ) ) {
p = strtok ( buf , " , " ) ;
2008-10-01 17:27:44 +10:00
if ( ! p ) {
printf ( " invalid level id - line %d \n " , lev ) ;
return B_TRUE ;
}
levelentry [ lev ] . id = atoi ( p ) ;
2008-10-07 16:53:06 +11:00
// track max levelid
if ( levelentry [ lev ] . id > maxlevid ) {
maxlevid = levelentry [ lev ] . id ;
}
2008-09-30 17:42:09 +10:00
p = strtok ( NULL , " , " ) ;
if ( ! p ) {
printf ( " invalid level filename - line %d \n " , lev ) ;
return B_TRUE ;
}
2008-10-07 16:53:06 +11:00
strncpy ( levelentry [ lev ] . filename , p , MIDBUFLEN ) ;
2008-09-30 17:42:09 +10:00
p = strtok ( NULL , " , " ) ;
if ( ! p ) {
printf ( " invalid level description - line %d \n " , lev ) ;
return B_TRUE ;
}
p [ strlen ( p ) - 1 ] = ' \0 ' ; // strip newline
2008-10-07 16:53:06 +11:00
//LEVELENTry[lev].desc = strdup(p);
strncpy ( levelentry [ lev ] . desc , p , MIDBUFLEN ) ;
2008-09-30 17:42:09 +10:00
lev + + ;
fgets ( buf , BUFLEN , f ) ;
}
fclose ( f ) ;
2008-10-01 17:27:44 +10:00
numlevels = lev ;
2008-09-30 17:42:09 +10:00
2008-10-01 17:27:44 +10:00
printf ( " Read %d levels. \n " , numlevels ) ;
2008-09-30 17:42:09 +10:00
return B_FALSE ;
}
2008-10-03 17:37:05 +10:00
int randompowerup ( void ) {
int num ;
2008-11-06 13:15:49 +11:00
num = rand ( ) % 34 ;
2008-10-30 12:06:25 +11:00
2008-10-03 17:37:05 +10:00
switch ( num ) {
case 0 :
default :
return P_SPEED ;
case 1 :
return P_BIGNET ;
case 2 :
return P_NUMNETS ;
case 3 :
return P_BOXING ;
case 4 :
return P_FTODIAMOND ;
case 5 :
return P_FTOGEM ;
case 6 :
return P_BOMB ;
case 7 :
return P_SHIELD ;
case 8 :
return P_MACEPOWERUP ;
case 9 :
return P_HELMET ;
case 10 :
return P_GEMBOOST ;
case 11 :
return P_TROPHY ;
case 12 :
return P_RINGSILVER ;
case 13 :
return P_RINGGOLD ;
case 14 :
return P_BELL ;
case 15 :
return P_CLOCK ;
2008-10-03 21:11:07 +10:00
case 16 :
return P_SNOWMAN ;
2008-10-07 16:53:06 +11:00
case 17 :
return P_SPRAY ;
case 18 :
return P_CANNONPOWERUP ;
2008-10-10 10:49:43 +11:00
case 19 :
return P_PHONE ;
2008-10-10 11:51:40 +11:00
case 20 :
return P_HONEY ;
case 21 :
return P_LIFE ;
2008-10-10 13:46:56 +11:00
case 22 :
return P_STARPOWERUP ;
2008-10-10 14:53:59 +11:00
case 23 :
return P_UFO ;
2008-10-13 11:43:01 +11:00
case 24 :
return P_TAP ;
case 25 :
return P_MASKPOWERUP ;
2008-10-15 14:20:10 +11:00
case 26 :
2008-10-31 09:58:10 +11:00
if ( ! gotcard ) {
gotcard = B_TRUE ;
return getrandomcard ( ) ;
} else {
return P_DIAMOND ;
}
2008-10-18 14:18:24 +11:00
case 27 :
return P_CLOVER ;
2008-10-18 15:16:06 +11:00
case 28 :
return P_ACCORDION ;
2008-10-18 15:49:08 +11:00
case 29 :
return P_WINGBOOTS ;
2008-10-18 16:10:10 +11:00
case 30 :
return P_SKULL ;
2008-10-30 10:00:12 +11:00
case 31 :
return P_GUN ;
2008-10-30 12:06:25 +11:00
case 32 :
return P_ZAPPOWERUP ;
2008-11-06 13:15:49 +11:00
case 33 :
return P_RANDOM ;
2008-10-03 17:37:05 +10:00
}
}
// returns true if the given powerup id is a permenant one
int ispermenant ( int pid ) {
switch ( pid ) {
case P_SPEED :
case P_NUMNETS :
case P_BIGNET :
2008-10-13 11:43:01 +11:00
case P_MASKPOWERUP :
2008-10-03 17:37:05 +10:00
case P_HELP :
case P_TROPHY :
case P_HELMET :
case P_BELL :
case P_GEMBOOST :
return B_TRUE ;
}
return B_FALSE ;
}
2008-10-07 16:53:06 +11:00
int isbosslevel ( int lev ) {
if ( lev % 20 = = 0 ) {
return B_TRUE ;
}
return B_FALSE ;
}
int isboss ( int monid ) {
switch ( monid ) {
case P_KINGRAT :
2008-11-01 08:13:27 +11:00
case P_KINGSNAIL :
2008-10-07 16:53:06 +11:00
return B_TRUE ;
default :
return B_FALSE ;
}
}
2008-10-23 12:18:49 +11:00
int isnettable ( sprite_t * s ) {
if ( ismonster ( s - > id ) ) {
if ( ismonster ( s - > id ) ) {
switch ( s - > id ) {
case P_BLACKCLOUD :
case P_KINGRAT :
2008-11-01 08:13:27 +11:00
case P_KINGSNAIL :
2008-10-23 12:18:49 +11:00
return B_FALSE ;
default :
return B_TRUE ;
}
2008-10-07 16:53:06 +11:00
}
}
return B_FALSE ;
}
// return starting health for a given boss type
int getbosshealth ( int mid ) {
switch ( mid ) {
case P_KINGRAT :
2008-10-10 19:59:03 +11:00
return 8 ;
2008-11-01 08:13:27 +11:00
case P_KINGSNAIL :
return 10 ;
2008-10-07 16:53:06 +11:00
}
return 0 ;
}
void getpixelrgb ( SDL_Surface * where , int x , int y , SDL_Color * clr ) {
Uint32 col ;
//determine position
char * pPosition = ( char * ) where - > pixels ;
//offset by y
pPosition + = ( where - > pitch * y ) ;
//offset by x
pPosition + = ( where - > format - > BytesPerPixel * x ) ;
//copy pixel data
memcpy ( & col , pPosition , where - > format - > BytesPerPixel ) ;
//convert color
SDL_GetRGB ( col , where - > format , & clr - > r , & clr - > g , & clr - > b ) ;
//*r = color.r;
//*g = color.g;
//*b = color.b;
}
2008-10-07 20:18:42 +11:00
void setfruitinfo ( void ) {
setinfo ( P_CHEESE , " Cheese " , " " , " cheese.png " ) ;
setinfo ( P_ICECREAM , " Ice Cream " , " " , " icecream.png " ) ;
setinfo ( P_CHIPS , " Chips " , " " , " chips.png " ) ;
setinfo ( P_BURGER , " Burger " , " " , " burger.png " ) ;
setinfo ( P_DIAMOND , " Diamond " , " " , " diamond.png " ) ;
setinfo ( P_FLOWERYELLOW , " Yellow Flower " , " " , " flower-yellow.png " ) ;
setinfo ( P_FLOWERRED , " Red Flower " , " " , " flower-red.png " ) ;
setinfo ( P_FLOWERPURPLE , " Purple Flower " , " " , " flower-purple.png " ) ;
setinfo ( P_GEMYELLOW , " Yellow Gem " , " " , " gem-yellow.png " ) ;
setinfo ( P_GEMRED , " Red Gem " , " " , " gem-red.png " ) ;
setinfo ( P_GEMPURPLE , " Purple Gem " , " " , " gem-purple.png " ) ;
2008-10-17 13:05:54 +11:00
setinfo ( P_FIRSTCARD , " Card " , " Keep a look out for these useful items. Collect a full poker hand for a secret bonus! " , " cardh.png " ) ;
2008-10-07 20:18:42 +11:00
setinfo ( P_SPEED , " Speed Up " , " Makes you walk faster. " , " speed.png " ) ;
2008-10-10 19:59:03 +11:00
setinfo ( P_NUMNETS , " More Nets " , " Increases the number of monsters you can catch simultaneously. " , " numnets.png " ) ;
2008-10-07 20:18:42 +11:00
setinfo ( P_BIGNET , " Big Net " , " Makes your nets reach further. " , " bignet.png " ) ;
setinfo ( P_HELP , " Help " , " Gives useful game information or hints. " , " help.png " ) ;
setinfo ( P_GEMBOOST , " Gem Boost " , " Increases the length of gem streams. " , " gemboost.png " ) ;
setinfo ( P_BELL , " Powerup Bell " , " Rings if a permenant powerup is going to appear on the level " , " bell.png " ) ;
setinfo ( P_TROPHY , " Trophy " , " Gives the player all powerups " , " trophy.png " ) ;
setinfo ( P_HELMET , " Helmet " , " Gives you a suit of armour which will protect you from death. " , " helmet.png " ) ;
2008-10-10 16:29:35 +11:00
setinfo ( P_BIGSPEED , " Big Speed Up " , " Makes you walk faster, permenantly! " , " bigspeed.png " ) ;
2008-11-05 08:07:52 +11:00
setinfo ( P_BIGNUMNETS , " Big More Nets " , " Permenantly gives you two nets, even after death " , " bignumnets.png " ) ;
2008-10-13 11:43:01 +11:00
setinfo ( P_MASKPOWERUP , " Scuba Mask " , " Allows you to move fast underwater. " , " maskpowerup.png " ) ;
2008-10-20 10:45:15 +11:00
setinfo ( P_WINGBOOTS , " Winged Boots " , " These magical boots cause you to grow wings, allowing to you jump again while in mid-air! " , " wingboots.png " ) ;
2008-10-07 20:18:42 +11:00
2008-10-10 19:59:03 +11:00
setinfo ( P_BOXING , " Boxing Glove " , " Your net will punch monsters, killing them instantly. " , " boxing.png " ) ;
2008-10-07 20:18:42 +11:00
setinfo ( P_MACEPOWERUP , " Mace " , " Slamming your net will cause a lethal explosion! " , " macepowerup.png " ) ;
setinfo ( P_FTODIAMOND , " Flowers-to-diamonds " , " Transforms all flowers on the level into diamonds. " , " flowertodiamond.png " ) ;
setinfo ( P_FTOGEM , " Flowers-to-gems " , " Transforms all flowers on the level into gems, and turns itself into an extra-long stream of gems. " , " flowertogem.png " ) ;
setinfo ( P_BOMB , " Bomb " , " Explodes and kills all monsters on the level. " , " bomb.png " ) ;
setinfo ( P_SHIELD , " Shield " , " Temporary invulnerability " , " shield.png " ) ;
setinfo ( P_RINGSILVER , " Silver Ring " , " Until the end of the level, you gain points for jumping. " , " ring-silver.png " ) ;
setinfo ( P_RINGGOLD , " Gold Ring " , " Until the end of the level, you gain points for walking. " , " ring-gold.png " ) ;
setinfo ( P_CLOCK , " Stopwatch " , " Stops time for 10 seconds " , " clock.png " ) ;
setinfo ( P_SNOWMAN , " Snowman " , " Freezes the level, turning everything to ice - touch a monster to shatter it! " , " snowman.png " ) ;
setinfo ( P_SPRAY , " Fly Spray " , " Sickens all monsters, causing them to slow down to half speed. " , " spray.png " ) ;
setinfo ( P_CANNONPOWERUP , " Fusion Cannon " , " A powerful weapon which will shoot out laser beams in all directions! " , " cannonpowerup.png " ) ;
2008-10-20 11:42:16 +11:00
setinfo ( P_PHONE , " Phone " , " Calls in your helper cloud and immediately skips two levels (but note that this cannot skip a boss level). " , " phone.png " ) ;
2008-10-10 11:51:40 +11:00
setinfo ( P_HONEY , " Honey " , " Coats your net in a layer of sticky honey, allowing it to pick up fruits from afar. " , " honey.png " ) ;
2008-10-10 16:29:35 +11:00
setinfo ( P_STARPOWERUP , " Shuriken " , " Shoots deadly razor blades in all directions. " , " star.png " ) ;
setinfo ( P_LIFE , " Life " , " Awards the player an extra life. " , " extralife.png " ) ;
setinfo ( P_UFO , " UFO " , " Calls in a powerful meteor strike! " , " ufo.png " ) ;
2008-10-20 11:39:51 +11:00
setinfo ( P_TAP , " Tap " , " The leaky tap will flood the level with water for 20 seconds, allowing you to access hard to reach areas. " , " tap.png " ) ;
2008-10-18 15:16:06 +11:00
setinfo ( P_ACCORDION , " Accordion " , " Makes your nets enormous " , " accordion.png " ) ;
2008-10-30 10:00:12 +11:00
setinfo ( P_GUN , " Gunner " , " Temporarily equips you with a super powerful machine gun! " , " gunner.png " ) ;
2008-10-30 12:06:25 +11:00
setinfo ( P_ZAPPOWERUP , " Bug Zapper " , " Zaps nearby enemies with miniature bolts of lightning " , " zapper.png " ) ;
2008-10-18 16:10:10 +11:00
setinfo ( P_SKULL , " Skull " , " Avoid these at all costs! The skull will cause you to lose all net powerups. " , " skull.png " ) ;
2008-10-18 14:18:24 +11:00
setinfo ( P_CLOVER , " 4-Leaf Clover " , " Increases your luck... " , " clover.png " ) ;
2008-10-15 06:36:51 +11:00
2008-11-06 13:15:49 +11:00
setinfo ( P_RANDOM , " Random " , " Gives you a random effect... " , " random.png " ) ;
2008-10-07 20:18:42 +11:00
setinfo ( P_RAT , " Rat " , " The weakest of the monsters, the rat will simply walk back and forth waiting to be caught. Beward an angry rat though, as it will try to fall or jump in order to catch you! " , " rat.png " ) ;
setinfo ( P_BEE , " Bee " , " Bees, while still relatively weak, gain an advantage over bats in that they are able to fly. They move in a simple diagonal pattern, changing direction when they get near a wall or spikes. Bees will speed up when angry. " , " newbee.png " ) ;
2008-10-10 21:06:40 +11:00
setinfo ( P_FISH , " Pirahna " , " These fish at at home in the water and unhampered by slowness while swimming. " , " fish.png " ) ;
2008-10-07 20:18:42 +11:00
setinfo ( P_SPIDER , " Spider " , " Spiders will lurk quietly on the ceiling, crawling back and forth. If they notice a player nearby however they will swiftly pounce down onto their prey! " , " spider.png " ) ;
setinfo ( P_SNAKE , " Snake " , " The snake moves in a similar fashion to the rat with one important exception - upon seeing a player they will spit a glob of deadly venom at them! " , " snake.png " ) ;
2008-11-09 16:24:07 +11:00
setinfo ( P_FLY , " Fly " , " Annoying pests at the best of times, flies pose additional danger to dwarves. They fly around more erratically than bees and after landing can scurry quickly back and forth. " , " fly.png " ) ;
2008-10-07 20:18:42 +11:00
2008-10-13 11:43:01 +11:00
setinfo ( P_TICK , " Tick " , " The tick is small but intelligent - even in its regular placid state it will move in the same manner as an angry rat. Because of their small size, they are also difficult to arget with a slam! " , " tick.png " ) ;
2008-10-24 14:31:25 +11:00
setinfo ( P_PLANT , " Plant " , " Evil venus fly trap plants will lie in wait and devour any player foolish enough to wander into their clutches. " , " plant.png " ) ;
2008-10-07 20:18:42 +11:00
setinfo ( P_BLACKCLOUD , " Cloud of Doom " , " This unkillable cloud will appear if you spend too much time on one level. Beware, as the only way to defeat the cloud of doom is to complete the level before it grows too large to handle! " , " cloud.png " ) ;
setinfo ( P_KINGRAT , " King Rat " , " This mighty creature is the ruler of the rats, and impervious to the player's net. It can only be harmed by slamming another monster into it! King Rat will roam the level searching for a player, and upon locating them will charge at high speed. " , " kingrat.png " ) ;
2008-11-01 08:13:27 +11:00
setinfo ( P_KINGSNAIL , " King Snail " , " The absolute ruler of the snail kingdom is far too large and heavy to catch in a net. In addition, its shell provides protection against all attacks, leaving only its head vulnerable. While King Snail is too proud to chase down enemies itself, it can use its snail army to destroy its foes. " , " kingsnail.png " ) ;
2008-10-09 14:32:15 +11:00
setinfo ( P_SNAIL , " Snail " , " Snails are slow moving but tough - when slammed they will not die, but simply lose their shell and become a slug. " , " snail.png " ) ;
setinfo ( P_SLUG , " Slug " , " Slugs are faster moving than snails and capable of launching themselves through the air at their prey! " , " slug.png " ) ;
2008-10-07 20:18:42 +11:00
}
void setinfo ( int id , char * name , char * desc , char * file ) {
spriteinfo [ id ] . name = strdup ( name ) ;
spriteinfo [ id ] . desc = strdup ( desc ) ;
spriteinfo [ id ] . file = strdup ( file ) ;
}
// dump html doco
void dumpinfo ( void ) {
int i ;
// header
2008-10-30 13:46:39 +11:00
//printf("<html>\n");
//printf("<body bgcolor=\"#AAAAAA\">\n");
2008-10-10 19:59:03 +11:00
printf ( " <center><h2>Power-Ups</h2> \n " ) ;
2008-10-07 20:18:42 +11:00
printf ( " <table border=1> \n " ) ;
// fruits
2008-11-05 08:14:56 +11:00
printf ( " <tr bgcolor= \" #ffff00 \" ><th colspan=2>Fruits</th></tr> \n " ) ;
2008-10-07 20:18:42 +11:00
for ( i = 0 ; i < MAXPTYPES ; i + + ) {
2008-10-10 12:30:40 +11:00
if ( ( isfruit ( i ) = = FT_FRUIT ) | | ( isfruit ( i ) = = FT_GEM ) ) {
2008-10-31 09:16:01 +11:00
printf ( " <tr><td align=center><img src= \" img/%s \" ><br>%s</td><td>Worth %d points.</td></tr> \n " ,
2008-10-07 20:18:42 +11:00
spriteinfo [ i ] . file , spriteinfo [ i ] . name , getpoints ( i ) ) ;
}
}
// perm powerup
2008-11-05 08:16:24 +11:00
printf ( " <tr bgcolor= \" #ffff00 \" ><th colspan=2>Permenant Powerups</th></tr> \n " ) ;
2008-10-07 20:18:42 +11:00
for ( i = 0 ; i < MAXPTYPES ; i + + ) {
if ( isfruit ( i ) = = FT_PERM ) {
2008-10-31 09:16:01 +11:00
printf ( " <tr><td align=center><img src= \" img/%s \" ><br>%s</td><td>%s</td></tr> \n " ,
2008-10-07 20:18:42 +11:00
spriteinfo [ i ] . file , spriteinfo [ i ] . name , spriteinfo [ i ] . desc ) ;
}
}
2008-10-17 13:05:54 +11:00
// card
2008-10-31 09:16:01 +11:00
printf ( " <tr><td align=center><img src= \" img/%s \" ><br>%s</td><td>%s</td></tr> \n " ,
2008-10-17 13:05:54 +11:00
spriteinfo [ P_FIRSTCARD ] . file , spriteinfo [ P_FIRSTCARD ] . name , spriteinfo [ P_FIRSTCARD ] . desc ) ;
2008-10-07 20:18:42 +11:00
// temp powerup
2008-11-05 08:16:24 +11:00
printf ( " <tr bgcolor= \" #ffff00 \" ><th colspan=2>Temporary Powerups</th></tr> \n " ) ;
2008-10-07 20:18:42 +11:00
for ( i = 0 ; i < MAXPTYPES ; i + + ) {
if ( isfruit ( i ) = = FT_TEMP ) {
2008-11-06 13:15:49 +11:00
if ( i = = P_RANDOM ) {
printf ( " <tr><td align=center><font color= \" ff00ff \" ><b><big>?</big></b></font><br>%s</td><td>%s</td></tr> \n " ,
spriteinfo [ i ] . name , spriteinfo [ i ] . desc ) ;
} else {
printf ( " <tr><td align=center><img src= \" img/%s \" ><br>%s</td><td>%s</td></tr> \n " ,
spriteinfo [ i ] . file , spriteinfo [ i ] . name , spriteinfo [ i ] . desc ) ;
}
2008-10-07 20:18:42 +11:00
}
}
2008-11-05 08:13:44 +11:00
// super powerup
2008-11-05 08:16:24 +11:00
printf ( " <tr bgcolor= \" #ffff00 \" ><th colspan=2>Super Powerups</th></tr> \n " ) ;
2008-11-05 08:13:44 +11:00
for ( i = 0 ; i < MAXPTYPES ; i + + ) {
if ( isfruit ( i ) = = FT_SUPER ) {
printf ( " <tr><td align=center><img src= \" img/%s \" ><br>%s</td><td>%s</td></tr> \n " ,
spriteinfo [ i ] . file , spriteinfo [ i ] . name , spriteinfo [ i ] . desc ) ;
}
}
2008-10-07 20:18:42 +11:00
printf ( " </table> \n " ) ;
printf ( " <center><h2>Creatures</h2></center> \n " ) ;
printf ( " <table border=1> \n " ) ;
// monsters
2008-11-06 13:25:38 +11:00
printf ( " <tr bgcolor= \" #ffff00 \" ><th colspan=2>Monsters</th></tr> \n " ) ;
2008-10-07 20:18:42 +11:00
for ( i = 0 ; i < MAXPTYPES ; i + + ) {
if ( ismonster ( i ) = = MT_MONSTER ) {
2008-10-31 09:16:01 +11:00
printf ( " <tr><td align=center><img src= \" img/%s \" ><br>%s</td><td>%s</td></tr> \n " ,
2008-10-07 20:18:42 +11:00
spriteinfo [ i ] . file , spriteinfo [ i ] . name , spriteinfo [ i ] . desc ) ;
}
}
// bosses
2008-11-06 13:25:38 +11:00
printf ( " <tr bgcolor= \" #ffff00 \" ><th colspan=2>Bosses</th></tr> \n " ) ;
2008-10-07 20:18:42 +11:00
for ( i = 0 ; i < MAXPTYPES ; i + + ) {
if ( ismonster ( i ) = = MT_BOSS ) {
2008-10-31 09:16:01 +11:00
printf ( " <tr><td align=center><img src= \" img/%s \" ><br>%s</td><td>%s</td></tr> \n " ,
2008-10-07 20:18:42 +11:00
spriteinfo [ i ] . file , spriteinfo [ i ] . name , spriteinfo [ i ] . desc ) ;
}
}
2008-10-10 19:59:03 +11:00
printf ( " </center> \n " ) ;
2008-10-30 13:46:39 +11:00
//printf("</body></html>\n");
2008-10-07 20:18:42 +11:00
}
2008-10-09 14:32:15 +11:00
void doblit ( SDL_Surface * src , SDL_Surface * dst , SDL_Rect * dstarea ) {
SDL_Rect srcarea ;
if ( ( dstarea - > y > 0 ) & & ( dstarea - > y < = ( 480 - src - > h ) ) ) {
// completely onscreen
SDL_BlitSurface ( src , NULL , dst , dstarea ) ;
} else if ( dstarea - > y > ( 480 - src - > h ) ) {
// off the bottom
srcarea . x = 0 ;
srcarea . y = 0 ;
srcarea . w = src - > w ;
srcarea . h = 480 - dstarea - > y ;
if ( srcarea . h > 0 ) {
SDL_BlitSurface ( src , & srcarea , dst , dstarea ) ;
}
} else if ( dstarea - > y < 0 ) {
// off the top
srcarea . x = 0 ;
srcarea . w = src - > w ;
srcarea . y = - dstarea - > y ;
srcarea . h = src - > h - srcarea . y ;
if ( srcarea . y > 0 ) {
dstarea - > y = 0 ;
dstarea - > h = srcarea . h ;
dstarea - > w = srcarea . w ;
SDL_BlitSurface ( src , & srcarea , dst , dstarea ) ;
}
}
}
2008-10-15 06:36:51 +11:00
char * getcardletter ( int num ) {
switch ( num ) {
case 0 :
return " X " ;
case 1 :
return " A " ;
case 2 :
return " 2 " ;
case 3 :
return " 3 " ;
case 4 :
return " 4 " ;
case 5 :
return " 5 " ;
case 6 :
return " 6 " ;
case 7 :
return " 7 " ;
case 8 :
return " 8 " ;
case 9 :
return " 9 " ;
case 10 :
return " 10 " ;
case 11 :
return " J " ;
case 12 :
return " Q " ;
case 13 :
return " K " ;
}
return " ? " ;
}
// returns a random card sprite id
int getrandomcard ( void ) {
2008-10-15 14:20:10 +11:00
int i ;
2008-10-15 06:36:51 +11:00
int cardid ;
2008-10-15 14:20:10 +11:00
int gotit ;
//cardid = P_FIRSTCARD + (rand() % 52);
gotit = B_TRUE ;
while ( gotit ) {
// give current card
cardid = deck [ curcard ] ;
// move to next card
curcard + + ;
if ( curcard > = DECKSIZE ) {
shufflecards ( ) ;
curcard = 0 ;
}
// make sure the player doesn't have it!
gotit = B_FALSE ;
if ( player ) {
for ( i = 0 ; i < player - > numcards ; i + + ) {
if ( player - > card [ i ] = = cardid ) {
gotit = B_TRUE ;
}
}
}
2008-10-18 05:39:22 +11:00
// are we forcing it to be good?
2008-10-18 14:18:24 +11:00
if ( ( forcegoodcard ) & & ( player - > numcards > 0 ) ) {
2008-10-18 05:39:22 +11:00
int okay = B_FALSE ;
int csuit , cval ;
for ( i = 0 ; i < player - > numcards ; i + + ) {
cval = getcardvalue ( player - > card [ i ] ) ;
csuit = getcardsuit ( player - > card [ i ] ) ;
if ( csuit = = getcardsuit ( cardid ) ) okay = B_TRUE ;
if ( cval = = ( getcardvalue ( cardid ) ) ) okay = B_TRUE ;
if ( cval = = ( getcardvalue ( cardid ) + 1 ) ) okay = B_TRUE ;
if ( cval = = ( getcardvalue ( cardid ) - 1 ) ) okay = B_TRUE ;
}
// if not a good card, go to next one
if ( ! okay ) {
gotit = B_TRUE ;
}
}
2008-10-15 14:20:10 +11:00
}
2008-10-15 15:51:17 +11:00
//printf("returning cardid %d\n",cardid);
2008-10-15 14:20:10 +11:00
2008-10-15 06:36:51 +11:00
return cardid ;
}
char * getcardname ( int id ) {
switch ( id ) {
case P_CARDH1 :
return " Ace of Hearts " ;
case P_CARDH2 :
return " Two of Hearts " ;
case P_CARDH3 :
return " Three of Hearts " ;
case P_CARDH4 :
return " Four of Hearts " ;
case P_CARDH5 :
return " Five of Hearts " ;
case P_CARDH6 :
return " Six of Hearts " ;
case P_CARDH7 :
return " Seven of Hearts " ;
case P_CARDH8 :
return " Eight of Hearts " ;
case P_CARDH9 :
return " Nine of Hearts " ;
case P_CARDH10 :
return " Ten of Hearts " ;
case P_CARDHJ :
return " Jack of Hearts " ;
case P_CARDHQ :
return " Queen of Hearts " ;
case P_CARDHK :
return " King of Hearts " ;
case P_CARDD1 :
return " Ace of Diamonds " ;
case P_CARDD2 :
return " Two of Diamonds " ;
case P_CARDD3 :
return " Three of Diamonds " ;
case P_CARDD4 :
return " Four of Diamonds " ;
case P_CARDD5 :
return " Five of Diamonds " ;
case P_CARDD6 :
return " Six of Diamonds " ;
case P_CARDD7 :
return " Seven of Diamonds " ;
case P_CARDD8 :
return " Eight of Diamonds " ;
case P_CARDD9 :
return " Nine of Diamonds " ;
case P_CARDD10 :
return " Ten of Diamonds " ;
case P_CARDDJ :
return " Jack of Diamonds " ;
case P_CARDDQ :
return " Queen of Diamonds " ;
case P_CARDDK :
return " King of Diamonds " ;
case P_CARDS1 :
return " Ace of Spades " ;
case P_CARDS2 :
return " Two of Spades " ;
case P_CARDS3 :
return " Three of Spades " ;
case P_CARDS4 :
return " Four of Spades " ;
case P_CARDS5 :
return " Five of Spades " ;
case P_CARDS6 :
return " Six of Spades " ;
case P_CARDS7 :
return " Seven of Spades " ;
case P_CARDS8 :
return " Eight of Spades " ;
case P_CARDS9 :
return " Nine of Spades " ;
case P_CARDS10 :
return " Ten of Spades " ;
case P_CARDSJ :
return " Jack of Spades " ;
case P_CARDSQ :
return " Queen of Spades " ;
case P_CARDSK :
return " King of Spades " ;
case P_CARDC1 :
return " Ace of Clubs " ;
case P_CARDC2 :
return " Two of Clubs " ;
case P_CARDC3 :
return " Three of Clubs " ;
case P_CARDC4 :
return " Four of Clubs " ;
case P_CARDC5 :
return " Five of Clubs " ;
case P_CARDC6 :
return " Six of Clubs " ;
case P_CARDC7 :
return " Seven of Clubs " ;
case P_CARDC8 :
return " Eight of Clubs " ;
case P_CARDC9 :
return " Nine of Clubs " ;
case P_CARDC10 :
return " Ten of Clubs " ;
case P_CARDCJ :
return " Jack of Clubs " ;
case P_CARDCQ :
return " Queen of Clubs " ;
case P_CARDCK :
return " King of Clubs " ;
}
return " Unknown Card " ;
}
2008-10-15 14:20:10 +11:00
void shufflecards ( void ) {
int ii , i , n , thiscard ;
// generate initial list of cards
for ( i = 0 ; i < DECKSIZE ; i + + ) {
deck [ i ] = P_FIRSTCARD + i ;
}
// shuffle them
for ( ii = 0 ; ii < SHUFFLEQUALITY ; ii + + ) {
for ( i = 0 ; i < DECKSIZE ; i + + ) {
// 50% chance of moving to the end
if ( rand ( ) % 2 ) {
thiscard = deck [ i ] ;
for ( n = i ; n < ( DECKSIZE - 1 ) ; n + + ) {
deck [ n ] = deck [ n + 1 ] ;
}
deck [ DECKSIZE - 1 ] = thiscard ;
}
}
}
curcard = 0 ;
}
2008-10-16 14:16:47 +11:00
int getworld ( int lev ) {
int wnum ;
wnum = ( ( lev - 1 ) / 20 ) + 1 ;
return wnum ;
}
int getlevel ( int lev ) {
int wnum ;
wnum = ( lev % 20 ) ;
if ( wnum = = 0 ) return 20 ;
return wnum ;
}
2008-10-18 05:39:22 +11:00
int getcardsuit ( int cardid ) {
if ( ( cardid > = P_FIRSTHEART ) & & ( cardid < = ( P_FIRSTHEART + 12 ) ) ) {
return CS_HEART ;
} else if ( ( cardid > = P_FIRSTDIAMOND ) & & ( cardid < = ( P_FIRSTDIAMOND + 12 ) ) ) {
return CS_DIAMOND ;
} else if ( ( cardid > = P_FIRSTSPADE ) & & ( cardid < = ( P_FIRSTSPADE + 12 ) ) ) {
return CS_SPADE ;
} else {
return CS_CLUB ;
}
}
int getcardvalue ( int cardid ) {
int points ;
points = cardid ;
switch ( getcardsuit ( cardid ) ) {
case CS_HEART :
points - = P_FIRSTHEART ;
break ;
case CS_DIAMOND :
points - = P_FIRSTDIAMOND ;
break ;
case CS_SPADE :
points - = P_FIRSTSPADE ;
break ;
case CS_CLUB :
default :
points - = P_FIRSTCLUB ;
break ;
}
return ( points + 1 ) ;
}
2008-10-20 07:45:38 +11:00
// draw player, and wings if required
void drawplayer ( sprite_t * s , SDL_Rect * where ) {
# ifndef __EDITOR
SDL_Rect wingarea ;
int wingframe ;
2008-10-28 07:22:33 +11:00
int drawwings ;
2008-10-20 07:45:38 +11:00
# endif
# ifndef __EDITOR
2008-10-28 07:22:33 +11:00
2008-10-30 10:00:12 +11:00
if ( player - > powerup = = PW_GUNNER ) {
// just draw crosshairs
// box
drawbox16 ( screen , s - > x - ( TILEW / 2 ) , s - > y - ( TILEH / 2 ) , s - > x + ( TILEW / 2 ) , s - > y + ( TILEH / 2 ) , & green , NULL ) ;
// littlebox
drawbox16 ( screen , s - > x - 1 , s - > y - 1 , s - > x + 1 , s - > y + 1 , & green , NULL ) ;
// lines
drawline16 ( screen , s - > x , 0 , s - > x , s - > y - ( TILEH / 2 ) , green ) ; // top
drawline16 ( screen , s - > x , s - > y + ( TILEH / 2 ) , s - > x , 480 - 1 , green ) ; // bottom
drawline16 ( screen , 0 , s - > y , s - > x - ( TILEW / 2 ) , s - > y , green ) ; // left
drawline16 ( screen , s - > x + ( TILEW / 2 ) , s - > y , 640 - 1 , s - > y , green ) ; // right
return ;
}
// only draw wings in certain states
2008-10-28 07:22:33 +11:00
switch ( levelcomplete ) {
case LV_NEXTLEV :
case LV_CLOUDLOOP :
drawwings = B_FALSE ;
break ;
default :
drawwings = B_TRUE ;
break ;
}
2008-10-23 12:38:18 +11:00
if ( ( s - > doublejump ) & & ( levelcomplete ! = LV_NEXTLEV ) ) {
2008-10-20 07:45:38 +11:00
// draw wings behind the sprite
if ( s - > jumping | | s - > falling ) {
2008-10-20 10:45:15 +11:00
// flapping wings - freeze while showing help text
if ( ( ( timer / 12 ) % 2 = = 0 ) | | ( levelcomplete = = LV_HELPFREEZE ) ) {
2008-10-20 07:45:38 +11:00
wingframe = 1 ;
} else {
wingframe = 2 ;
}
} else {
// still wings
wingframe = 0 ;
}
2008-10-26 14:31:16 +11:00
wingarea . x = s - > x - ( imageset [ P_WINGRIGHT ] . img [ wingframe ] - > w / 2 ) ;
wingarea . y = s - > y - ( imageset [ P_WINGRIGHT ] . img [ wingframe ] - > h ) ;
2008-10-20 07:45:38 +11:00
if ( wingframe = = 0 ) { // still
2008-10-26 14:31:16 +11:00
wingarea . x + = ( 4 * s - > dir ) ;
2008-10-20 07:45:38 +11:00
wingarea . y + = 2 ;
} else if ( ( wingframe > = 1 ) & & ( wingframe < = 2 ) ) { // flapping
2008-10-26 14:31:16 +11:00
wingarea . x + = ( 11 * s - > dir ) ;
2008-10-20 07:45:38 +11:00
wingarea . y - = 9 ;
}
// when climbing, show "left" wing twice instead
// when swimming, only show left wing
if ( ! s - > climbing & & ! s - > swimming ) {
2008-10-26 14:31:16 +11:00
if ( s - > dir = = - 1 ) wingframe + = MAXFRAMES ;
2008-10-20 07:45:38 +11:00
doblit ( imageset [ P_WINGRIGHT ] . img [ wingframe ] , screen , & wingarea ) ;
}
}
# endif
2008-10-23 12:38:18 +11:00
if ( ( levelcomplete = = LV_CLOUDLOOP ) | | ( levelcomplete = = LV_NEXTLEV ) ) {
2008-10-26 14:31:16 +11:00
s - > img = imageset [ s - > id ] . img [ F_SHOOT ] ;
2008-10-23 12:38:18 +11:00
}
2008-10-20 07:45:38 +11:00
// draw the sprite
doblit ( s - > img , screen , where ) ;
# ifndef __EDITOR
2008-10-23 12:38:18 +11:00
if ( ( s - > doublejump ) & & ( levelcomplete ! = LV_NEXTLEV ) ) {
2008-10-20 07:45:38 +11:00
// draw wings in front of the sprite
if ( s - > swimming ) {
wingframe = 3 ;
} else if ( s - > jumping | | s - > falling ) {
// flapping wings
if ( ( timer / 12 ) % 2 = = 0 ) {
wingframe = 1 ;
} else {
wingframe = 2 ;
}
} else {
// still wings
wingframe = 0 ;
}
2008-10-26 14:31:16 +11:00
wingarea . x = s - > x - ( imageset [ P_WINGLEFT ] . img [ wingframe ] - > w / 2 ) ;
wingarea . y = s - > y - ( imageset [ P_WINGLEFT ] . img [ wingframe ] - > h ) ;
2008-10-20 07:45:38 +11:00
if ( wingframe = = 0 ) { // still
if ( s - > climbing ) {
wingarea . x - = 4 ;
wingarea . y + = 2 ;
} else {
2008-10-26 14:31:16 +11:00
wingarea . x - = ( 6 * s - > dir ) ;
2008-10-20 07:45:38 +11:00
wingarea . y + = 2 ;
}
} else if ( ( wingframe > = 1 ) & & ( wingframe < = 2 ) ) { // flapping
2008-10-26 14:31:16 +11:00
wingarea . x - = ( 11 * s - > dir ) ;
2008-10-20 07:45:38 +11:00
wingarea . y - = 9 ;
} else if ( wingframe = = 3 ) {
wingarea . y - = 9 ;
2008-10-26 14:31:16 +11:00
wingarea . x - = ( 6 * s - > dir ) ;
2008-10-20 07:45:38 +11:00
}
2008-10-26 14:31:16 +11:00
if ( s - > dir = = - 1 ) wingframe + = MAXFRAMES ;
2008-10-20 07:45:38 +11:00
doblit ( imageset [ P_WINGLEFT ] . img [ wingframe ] , screen , & wingarea ) ;
if ( s - > climbing ) {
// draw the other wing
wingarea . x + = 8 ;
// reverse it
2008-10-26 14:31:16 +11:00
if ( s - > dir = = - 1 ) wingframe - = MAXFRAMES ;
2008-10-20 07:45:38 +11:00
else wingframe + = MAXFRAMES ;
doblit ( imageset [ P_WINGLEFT ] . img [ wingframe ] , screen , & wingarea ) ;
}
}
# endif
}
2008-10-20 09:58:54 +11:00
void resethurryup ( level_t * lev ) {
nexthurryup = gtime + lev - > hurryuptime ;
if ( gamemode = = GM_EASY ) {
nexthurryup + = 15 ;
}
}