diff --git a/tb1_linux/Makefile b/tb1_linux/Makefile index 7247f06..beaf72f 100644 --- a/tb1_linux/Makefile +++ b/tb1_linux/Makefile @@ -18,58 +18,58 @@ tb1: tb1.o ./svmwgraph/libsvmwgraph.a about.o credits.o graphic_tools.o \ cd svmwgraph && make tb1.o: tb1.c - $(CC) -c tb1.c $(INCLUDE) + $(CC) $(CFLAGS) -c tb1.c $(INCLUDE) about.o: about.c - $(CC) -c about.c $(INCLUDE) - + $(CC) $(CFLAGS) -c about.c $(INCLUDE) + credits.o: credits.c - $(CC) -c credits.c $(INCLUDE) + $(CC) $(CFLAGS) -c credits.c $(INCLUDE) graphic_tools.o: graphic_tools.c - $(CC) -c graphic_tools.c $(INCLUDE) + $(CC) $(CFLAGS) -c graphic_tools.c $(INCLUDE) help.o: help.c - $(CC) -c help.c $(INCLUDE) + $(CC) $(CFLAGS) -c help.c $(INCLUDE) hiscore.o: hiscore.c - $(CC) -c hiscore.c $(INCLUDE) + $(CC) $(CFLAGS) -c hiscore.c $(INCLUDE) level_1.o: level_1.c - $(CC) -c level_1.c $(INCLUDE) + $(CC) $(CFLAGS) -c level_1.c $(INCLUDE) level2_engine.o: level2_engine.c - $(CC) -c level2_engine.c $(INCLUDE) + $(CC) $(CFLAGS) -c level2_engine.c $(INCLUDE) #level_2.o: level_2.c # $(CC) -c level_2.c $(INCLUDE) level_3.o: level_3.c - $(CC) -c level_3.c $(INCLUDE) + $(CC) $(CFLAGS) -c level_3.c $(INCLUDE) loadsave.o: loadsave.c - $(CC) -c loadsave.c $(INCLUDE) + $(CC) $(CFLAGS) -c loadsave.c $(INCLUDE) options.o: options.c - $(CC) -c options.c $(INCLUDE) + $(CC) $(CFLAGS) -c options.c $(INCLUDE) playgame.o: playgame.c - $(CC) -c playgame.c $(INCLUDE) + $(CC) $(CFLAGS) -c playgame.c $(INCLUDE) quit.o: quit.c - $(CC) -c quit.c $(INCLUDE) + $(CC) $(CFLAGS) -c quit.c $(INCLUDE) sidebar.o: sidebar.c - $(CC) -c sidebar.c $(INCLUDE) + $(CC) $(CFLAGS) -c sidebar.c $(INCLUDE) sound.o: sound.c - $(CC) -c sound.c $(INCLUDE) $(SDL_MIXER_FLAGS) + $(CC) $(CFLAGS) -c sound.c $(INCLUDE) $(SDL_MIXER_FLAGS) story.o: story.c - $(CC) -c story.c $(INCLUDE) + $(CC) $(CFLAGS) -c story.c $(INCLUDE) tblib.o: tblib.c - $(CC) -c tblib.c $(INCLUDE) + $(CC) $(CFLAGS) -c tblib.c $(INCLUDE) clean: rm -f tb1 *.o *~ diff --git a/tb1_linux/Makefile.inc b/tb1_linux/Makefile.inc index 0f97663..cf26e1c 100644 --- a/tb1_linux/Makefile.inc +++ b/tb1_linux/Makefile.inc @@ -8,6 +8,8 @@ # CC= gcc +CFLAGS = -O2 -Wall -g + # # Uncomment the following for SDL_mixer sound # @@ -26,9 +28,9 @@ SDL_INCLUDE= `sdl-config --cflags` # # Uncomment the following for ncurses # -#CURSES_TARGET= curses_svmwgraph.o -#CURSES_FLAGS= -DCURSES_TARGET=1 -#CURSES_LIBS= -lncurses +CURSES_TARGET= curses_svmwgraph.o +CURSES_FLAGS= -DCURSES_TARGET=1 +CURSES_LIBS= -lncurses # # On machines w/ curses instead of ncurses [i.e. solaris, Irix, etc] @@ -42,14 +44,14 @@ SDL_INCLUDE= `sdl-config --cflags` # # Uncomment the following for opengGL # -#OPENGL_TARGET= opengl_svmwgraph.o -#OPENGL_FLAGS=-DOPENGL_TARGET -#OPENGL_LIBS= -L/usr/X11R6/lib -lX11 -lICE -lXmu -lGL -lGLU +OPENGL_TARGET= opengl_svmwgraph.o +OPENGL_FLAGS=-DOPENGL_TARGET +OPENGL_LIBS= -lX11 -lICE -lGL -lGLU ############################## # DO NOT EDIT BELOW THIS LINE ############################## -INCLUDE_GLOBAL= -Wall -O2 $(SDL_INCLUDE) +INCLUDE_GLOBAL= $(SDL_INCLUDE) LIBS_GLOBAL= -lm $(SDL_MIXER_LIBS) $(SDL_LIBS) $(CURSES_LIBS) $(OPENGL_LIBS) diff --git a/tb1_linux/level2_engine.c b/tb1_linux/level2_engine.c index 176988a..d6a1069 100644 --- a/tb1_linux/level2_engine.c +++ b/tb1_linux/level2_engine.c @@ -1,936 +1,935 @@ -#include -#include /* strncmp */ -#include /* usleep */ -#include /* free */ -#include /* gettimeofday */ - -#include "./svmwgraph/svmwgraph.h" -#include "tb1_state.h" -#include "tblib.h" -#include "graphic_tools.h" -#include "sidebar.h" -#include "sound.h" -#include "help.h" -#include "loadsave.h" - -#define ROW_WIDTH 12 -#define COL_HEIGHT 20 - -/* #define DEBUG 1 */ - -struct sprite_type { - int initialized; - int type; - int shoots; - int explodes; - vmwSprite *data; -}; - -struct level2_data { - int xsize,ysize,rows,cols; - int numsprites; - struct sprite_type **sprites; - int level_length,level_width; - unsigned char **level_data; -}; - - -#define SPRITE_BACKGROUND 0 -#define SPRITE_ENEMY_SHOOT 1 -#define SPRITE_ENEMY_REFLECT 2 -#define SPRITE_ENEMY_WEAPON 3 -#define SPRITE_OBSTRUCTION 4 -#define SPRITE_EXPLOSION 5 -#define SPRITE_WEAPON 6 -#define SPRITE_POWERUP 7 - - -struct text_mapping_type { - char name[30]; - int size; - int type; -} text_mapping[] = { {"BACKGROUND", 10, SPRITE_BACKGROUND}, - {"ENEMY_SHOOT", 11, SPRITE_ENEMY_SHOOT}, - {"ENEMY_REFLECT", 13, SPRITE_ENEMY_REFLECT}, - {"ENEMY_WEAPON", 12, SPRITE_ENEMY_WEAPON}, - {"OBSTRUCTION", 11, SPRITE_OBSTRUCTION}, - {"EXPLOSION", 9, SPRITE_EXPLOSION}, - {"WEAPON", 6, SPRITE_WEAPON}, - {"POWERUP", 7, SPRITE_POWERUP}, - {"DONE", 4, 0xff}, - { } -}; - -int belongs_on_map(int type) { - - switch (type) { - case SPRITE_BACKGROUND: - case SPRITE_ENEMY_SHOOT: - case SPRITE_ENEMY_REFLECT: - case SPRITE_OBSTRUCTION: return 1; - default: return 0; - } - return 0; -} - - -int map_string_to_type(char *string) { - - int i=0; - - while(text_mapping[i].type!=0xff) { - if (!strncmp(text_mapping[i].name,string,text_mapping[i].size)) { -// printf("%s %i\n",string,text_mapping[i].type); - return text_mapping[i].type; - } - i++; - } - return -1; -} - -struct level2_data *parse_data_file(char *filename) { - - - FILE *fff; - char tempst[255],sprite_file[255],throwaway[255]; - char type[255]; - int number,shoots,explodes,count,i,numsprites,tempint; - struct level2_data *data; - - fff=fopen(filename,"r"); - if (fff==NULL) { - printf("Cannot open %s\n",filename); - return NULL; - } - - data=(struct level2_data *)malloc(sizeof(struct level2_data)); - - /* Pass 1 */ - do { - fgets(tempst,254,fff); - - switch (tempst[0]) { - - case '%': - if (!strncmp(tempst,"%SPRITEFILE",11)) { - sscanf(tempst,"%s %s",throwaway,sprite_file); - } - if (!strncmp(tempst,"%SPRITEXSIZE",11)) { - sscanf(tempst,"%s %d",throwaway,&data->xsize); - } - if (!strncmp(tempst,"%SPRITEYSIZE",11)) { - sscanf(tempst,"%s %d",throwaway,&data->ysize); - } - if (!strncmp(tempst,"%SPRITEROWS",11)) { - sscanf(tempst,"%s %d",throwaway,&data->rows); - } - if (!strncmp(tempst,"%SPRITECOLS",11)) { - sscanf(tempst,"%s %d",throwaway,&data->cols); - } - } - - } while (!feof(fff)); - - /* Pass 2 */ - - numsprites=(data->rows) * (data->cols); - data->numsprites=numsprites; - - data->sprites=calloc( numsprites, sizeof(struct sprite_type*)); - for (i=0; i< numsprites;i++) { - data->sprites[i]=calloc(1,sizeof(struct sprite_type)); - data->sprites[i]->initialized=0; - } - - rewind(fff); - do { - fgets(tempst,254,fff); - switch(tempst[0]) { - - case '%': if (!strncmp(tempst,"%SPRITE ",8)) { - count=sscanf(tempst,"%s %d %s %d %d", - throwaway,&number,type,&shoots,&explodes); - - if (count > 2) { - data->sprites[number]->type=map_string_to_type(type); - data->sprites[number]->initialized=1; - } - if (count > 3) { - data->sprites[number]->shoots=shoots; - } - if (count > 4) { - data->sprites[number]->explodes=explodes; - } - } - if (!strncmp(tempst,"%DATALENGTH",10)) { - sscanf(tempst,"%s %d",throwaway,&data->level_length); - } - if (!strncmp(tempst,"%DATAWIDTH",9)) { - sscanf(tempst,"%s %d",throwaway,&data->level_width); - } - - break; - - - } - } while (!feof(fff)); - - - /* Pass 3 */ - data->level_data=calloc(data->level_length, sizeof(char *)); - - data->level_data[0]=calloc(data->level_length * data->level_width,sizeof(char)); - for(i=1;ilevel_length;i++) { - data->level_data[i]=data->level_data[0]+ (i*data->level_width*sizeof(char)); - } - - rewind(fff); - - - do { - fgets(tempst,254,fff); - } while (strncmp(tempst,"%DATABEGIN",10)); - - i=0; - while(ilevel_length*data->level_width) { - /* Grrrrr */ -// fscanf(fff,"%d",(int *)data->level_data[0]); - fscanf(fff,"%d",&tempint); - *(data->level_data[0]+i)=(char)tempint; - i++; - } -#ifdef DEBUG - print_level(data); - - printf("Sprite File: %s\n",sprite_file); - printf("Sprite size: %ix%i\n",data->xsize,data->ysize); - printf("Sprite array: %ix%i\n",data->rows,data->cols); - printf("Level length: %i\n",data->level_length); -#endif - fclose(fff); - return data; -} - -int free_level2_data(struct level2_data *data) { - /* IMPLEMENT THIS */ - return 0; -} - - - /* Define this to get a frames per second readout */ -/* #define DEBUG_ON */ - - /* The sounds */ - -#define NUM_SAMPLES 8 -#define SND_AHH 0 -#define SND_CC 1 -#define SND_KAPOW 2 -#define SND_SCREAM 3 -#define SND_BONK 4 -#define SND_CLICK 5 -#define SND_OW 6 -#define SND_ZRRP 7 - -struct enemy_info_type { - int out; - int x,y; - int yspeed; - int type; - -}; - -struct bullet_info_type { - int out,x,y; -}; - -struct obstruction_type { - int valid; - int type,shoots; - int exploding; - int explodeprogress; - int howmanyhits; - int lastshot; -}; - - -#define BULLETS_MAX 3 -#define ENEMIES_MAX 25 - - struct enemy_info_type *enemies; - - struct bullet_info_type *bullets; - int bullets_out=0; - -void leveltwoengine(tb1_state *game_state, char *shipfile, char *levelfile, - char *spritefile,char *level_num, char *level_desc, - void *close_function) -{ - int ch,i,temp_y; - char tempst[BUFSIZ]; - int game_paused=0; - int shipx=36,shipy; - int whatdelay=1; - int levelover=0,j,offscreen_row=0; - struct timeval timing_info; - struct timezone dontcare; - - long oldsec,oldusec,time_spent; - int howmuchscroll=200; /* there is a reason for this */ - struct obstruction_type obstruction[12][20]; - int shipadd=0,shipframe=1; - int our_row,rows_goneby=0,rows_offset=0; - int grapherror; - int done_waiting,type; - - vmwFont *tb1_font; - vmwVisual *virtual_1; - vmwVisual *virtual_2; - - vmwSprite *ship_shape[3]; - - - struct level2_data *data; - - /* For convenience */ - tb1_font=game_state->graph_state->default_font; - virtual_1=game_state->virtual_1; - virtual_2=game_state->virtual_2; - - /* Set this up for Save Game */ - game_state->begin_score=game_state->score; - game_state->begin_shields=game_state->shields; - - /* Load Sprite Data */ - grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1, - tb1_data_file(shipfile, - game_state->path_to_data), - game_state->graph_state); - - ship_shape[0]=vmwGetSprite(0,0,48,30,virtual_1); - ship_shape[1]=vmwGetSprite(0,32,48,30,virtual_1); - ship_shape[2]=vmwGetSprite(0,64,48,30,virtual_1); - - - /* Load Level Data */ - data=parse_data_file(tb1_data_file(levelfile,game_state->path_to_data)); - - vmwLoadPicPacked(0,0,virtual_1,1,1, - tb1_data_file(spritefile,game_state->path_to_data), - game_state->graph_state); - - for(j=0;jrows;j++) - for(i=0;icols;i++) - data->sprites[j*10+i]->data=vmwGetSprite(1+i*21,1+j*11,20,10,virtual_1); - - - /* Initialize Bullets */ - bullets=calloc(BULLETS_MAX,sizeof(struct bullet_info_type)); - for (i=0;igraph_state,virtual_1); - vmwClearKeyboardBuffer(); - pauseawhile(5); - - /* Setup and draw the sidebar */ - setupsidebar(game_state,virtual_2); - vmwFlipVirtual(virtual_1,virtual_2,320,200); - sprintf(tempst,"%d",game_state->level); - vmwDrawBox(251,52,63,7,0,virtual_2); - vmwTextXY(tempst,307,51,12,0,0,tb1_font,virtual_2); - - change_shields(game_state); - - - /* Ready the timing loop */ - gettimeofday(&timing_info,&dontcare); - oldsec=timing_info.tv_sec; oldusec=timing_info.tv_usec; - - - /* Get the initial background ready */ - /* We copy the last 40 rows into vaddr_2 */ - /* as we are scrolling bottom_up */ - offscreen_row=data->level_length-(COL_HEIGHT*2); - for(i=0;isprites[(int) *(data->level_data[offscreen_row+j]+i)]->data, - i*20,j*10,virtual_2); - } - } - offscreen_row-=20; - - /* Get the initial obstructions ready */ - /* Get them from the last 20 rows */ - our_row=data->level_length-20; - for(j=0;j<20;j++) { - for(i=0;i<12;i++) { - - type=data->sprites[*(data->level_data[our_row]+i)]->type; - - if ((type==SPRITE_OBSTRUCTION) || - (type==SPRITE_ENEMY_SHOOT) || - (type==SPRITE_ENEMY_REFLECT)) { - - obstruction[i][j].shoots=data->sprites[*(data->level_data[our_row]+i)]->shoots; - obstruction[i][j].valid=1; - obstruction[i][j].type=type; - obstruction[i][j].exploding=0; - obstruction[i][j].lastshot=0; - - } - } - } - - /* howmuchscroll is originally 200, as we start at the bottom */ - vmwArbitraryCrossBlit(virtual_2,0,0+howmuchscroll,240,200, - virtual_1,0,0); - - - - /************************************************************/ - /* MAIN LEVEL 2 GAME LOOP */ - /************************************************************/ - - while (!levelover) { - - ch=0; - - /* Scroll the Background */ - howmuchscroll--; - rows_offset++; - - /* If used up all the buffered background, draw some more */ - if (howmuchscroll<0) { - howmuchscroll=200+howmuchscroll; - /* Copy half of old downward */ - vmwArbitraryCrossBlit(virtual_2,0,0,240,200,virtual_2,0,200); - /* Load 20 rows of data preceding it */ - for(i=0;i<12;i++) { - for(j=0;j<20;j++) { - vmwPutSprite(data->sprites[(int) *(data->level_data[offscreen_row+j]+i)]->data, - i*20,j*10,virtual_2); - } - } - offscreen_row-=20; - } - - - /* Setup Obstructions */ - if (rows_offset==10) { - - rows_offset=0; - - /* move all rows down by one, dropping old off end */ - memmove(&obstruction[0][1],&obstruction[0][0], - 19*12*sizeof(struct obstruction_type)); - - our_row--; - - for(i=0;i<12;i++) { - type=data->sprites[*(data->level_data[our_row]+i)]->type; - if ((type==SPRITE_OBSTRUCTION) || - (type==SPRITE_ENEMY_SHOOT) || - (type==SPRITE_ENEMY_REFLECT)) { - - obstruction[i][0].shoots=data->sprites[*(data->level_data[our_row]+i)]->shoots; - obstruction[i][0].valid=1; - obstruction[i][0].type=type; - obstruction[i][0].exploding=0; - obstruction[i][0].lastshot=0; - } - else { - obstruction[i][0].valid=0; - } - } - } - - - - /* Flip the far background to regular background */ - vmwArbitraryCrossBlit(virtual_2,0,0+howmuchscroll,240,200, - virtual_1,0,0); - - /***Collision Check***/ - for(i=0;i= j*20) && - ( bullets[i].x <= j*20+17)) { - - if (obstruction[j][temp_y].type!=SPRITE_ENEMY_REFLECT) { - if ((game_state->sound_possible)&&(game_state->sound_enabled)) - playGameFX(SND_KAPOW); - obstruction[j][temp_y].exploding=1; - obstruction[j][temp_y].explodeprogress=0; - bullets[i].out=0; - bullets_out--; - game_state->score+=10; - changescore(game_state); - } - - else { - int k=0; - - while(enemies[k].out) k++; - if (k50) { - int k=0; - - obstruction[i][j].lastshot=rand()%10; - while(enemies[k].out) k++; - if (k155) && (passive[i].kind!=10)) { - if ((collision(passive[i].x,passive[i].y,10,5,shipx+16,165,5,5))|| - (collision(passive[i].x,passive[i].y,10,5,shipx+6,175,18,8))) { - if ((game_state->sound_possible)&&(game_state->sound_enabled)) - playGameFX(SND_BONK); - passive[i].dead=1; - game_state->shields--; - if(game_state->shields<0) levelover=1; -// vmwPutSprite(shape_table[34], -// passive[i].x,passive[i].y+howmuchscroll, -// virtual_1); - change_shields(game_state); - } - } - } - /* See if hit by lasers */ - for (i=0;i<10;i++) - if (enemy[i].out) { - if ((collision(enemy[i].x,enemy[i].y,2,5,shipx+16,165,5,5)) || - (collision(enemy[i].x,enemy[i].y,2,5,shipx+6,175,18,8))) { - if ((game_state->sound_possible)&&(game_state->sound_enabled)) - playGameFX(SND_BONK); - enemy[i].out=0; - game_state->shields--; - if (game_state->shields<0) levelover=1; - change_shields(game_state); - } - } - -#endif - - - /***DO EXPLOSIONS***/ - for(i=0;i<12;i++) { - for(j=0;j<20;j++) { - if (obstruction[i][j].valid) { - if (obstruction[i][j].exploding) { - obstruction[i][j].explodeprogress++; - - vmwPutSprite(data->sprites[35+(obstruction[i][j].explodeprogress)/2]->data, - // shape_table[35+passive[i].explodeprogress], - i*20,j*10+howmuchscroll+rows_offset, - virtual_2); - if (obstruction[i][j].explodeprogress>6) { - obstruction[i][j].valid=0; - vmwPutSprite(data->sprites[34]->data, - i*20,j*10+howmuchscroll+rows_offset, - virtual_2); - } - - } - - } - } - } - - /***MOVE BULLETS***/ - for(i=0;isprites[20]->data, - - bullets[i].x, - bullets[i].y,virtual_1); - } - } - - } - -#if 0 - /***MOVE ENEMIES***/ - for(j=0;j<40;j++) { - if (!passive[j].dead) { - if (speed_factor==1) passive[j].y++; - else passive[j].y+=speed_factor; - if (passive[j].y>190) passive[j].dead=1; - } - if (passive[j].lastshot>0) passive[j].lastshot--; - if ((!passive[j].dead) && (passive[j].shooting) - && (!passive[j].lastshot) && (passive[j].y>0)) { - k=0; - while ((enemy[k].out) && (k<10)) k++; - if (k<9) { - passive[j].lastshot=30; - enemy[k].out=1; - enemy[k].y=passive[j].y; - enemy[k].x=passive[j].x+5; - enemy[k].yspeed=5; - enemy[k].kind=25; - if (passive[j].kind==11) enemy[k].kind=26; - } - } - } -#endif - /* Draw Enemies */ - for(j=0;j189) enemies[j].out=0; - else { - vmwPutSprite(data->sprites[enemies[j].type]->data, - enemies[j].x,enemies[j].y, - virtual_1); - enemies[j].y+=enemies[j].yspeed; - } - - } - } - - - /***READ KEYBOARD***/ - if ((ch=vmwGetInput())!=0) { - switch(ch) { - case VMW_ESCAPE: levelover=1; break; - case VMW_RIGHT: if (shipadd>=0) shipadd+=3; else shipadd=0; break; - case VMW_LEFT: if (shipadd<=0) shipadd-=3; else shipadd=0; break; - case VMW_F1: game_paused=1; help(game_state); break; - case '+': whatdelay++; break; - case 'P': case 'p': game_paused=1; - coolbox(65,85,175,110,1,virtual_1); - vmwTextXY("GAME PAUSED",79,95,4,7, - 0,tb1_font,virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - while (vmwGetInput()==0) usleep(30000); - break; - case '-': whatdelay--; break; - case 'S': - case 's': game_state->sound_enabled=!(game_state->sound_enabled); break; - case VMW_F2: game_paused=1; - savegame(game_state); - break; - case ' ': - i=0; - while(bullets[i].out) i++; - if (isound_possible)&&(game_state->sound_enabled)) - playGameFX(SND_CC); - bullets[i].x=shipx+21; - bullets[i].y=165; - - vmwPutSprite(data->sprites[20]->data, - bullets[i].x, - bullets[i].y,virtual_1); - } - - break; - } - - } - - - - /***MOVE SHIP***/ - - shipx+=shipadd; - - rows_goneby++; - - - /* Keep ship on screen */ - if (shipx<1) shipx=1; - if (shipx>190) shipx=190; - switch(shipframe) { - case 1: vmwPutSprite(ship_shape[0], - shipx,165,virtual_1); break; - case 3: vmwPutSprite(ship_shape[1], - shipx,165,virtual_1); break; - case 2: - case 4: vmwPutSprite(ship_shape[2], - shipx,165,virtual_1); break; - } - shipframe++; - if (shipframe==5) shipframe=1; - - /* Flip Pages */ - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - - - /* If time passed was too little, wait a bit */ - /* 33,333 would frame rate to 30Hz */ - /* Linux w 100Hz scheduling only gives +- 10000 accuracy */ - done_waiting=0; - while (!done_waiting) { - - gettimeofday(&timing_info,&dontcare); - time_spent=timing_info.tv_usec-oldusec; - - /* Assume we don't lag more than a second */ - /* Seriously, if we lag more than 10ms we are screwed anyway */ - if (time_spent<0) time_spent+=1000000; - if (time_spent<30000) usleep(100); - else (done_waiting=1); - } - oldusec=timing_info.tv_usec; - oldsec=timing_info.tv_sec; - - /* If game is paused, don't keep track of time */ - - if (game_paused) { - gettimeofday(&timing_info,&dontcare); - oldusec=timing_info.tv_usec; - oldsec=timing_info.tv_sec; - game_paused=0; - } - - - /* The leve is over */ - /* FIXME autocalculate rather than 1950 */ - - if (rows_goneby>1950) { -// printf("%i\n",rows_goneby); -// coolbox(35,85,215,110,1,virtual_1); -// vmwTextXY("TO BE CONTINUED...",55,95,4,7,0,tb1_font,virtual_1); -// vmwBlitMemToDisplay(game_state->graph_state,virtual_1); -// pauseawhile(10); - - - - vmwClearKeyboardBuffer(); - pauseawhile(5); - vmwLoadPicPacked(0,0,game_state->virtual_3,0,1, - tb1_data_file("level1/viewscr.tb1",game_state->path_to_data), - game_state->graph_state); - vmwClearScreen(game_state->virtual_1,0); - vmwArbitraryCrossBlit(game_state->virtual_3,0,79,58,37, - game_state->virtual_1,10,10); - vmwClearKeyboardBuffer(); - vmwSmallTextXY("UNIDENTIFIED SPACECRAFT!",70,10,2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("DO YOU WISH TO DEACTIVATE ",70,20,2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("THIS SHIP'S SECURITY SYSTEMS? (Y/N)",70,30,2,0,1,tb1_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - vmwClearKeyboardBuffer(); - - ch='!'; - while ((ch!='Y') && (ch!='y') && (ch!='N') && (ch!='n')) { - while(!(ch=vmwGetInput())) usleep(1000); - } - - if ((ch=='N') || (ch=='n')) { - vmwArbitraryCrossBlit(game_state->virtual_3,0,79,58,37, - game_state->virtual_1,10,50); - vmwSmallTextXY("NO? AFFIRMATIVE. ",70,50,9,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("ARMING REMOTE DESTRUCTION RAY.",70,60,9,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("GOOD-BYE.",70,70,9,0,1,tb1_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - pauseawhile(4); - } - - - if ((ch=='Y') || (ch=='y')) { - vmwArbitraryCrossBlit(game_state->virtual_3,0,79,58,37, - game_state->virtual_1,10,50); - vmwSmallTextXY("'Y'=CORRECT PASSWORD. ",70,50,2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("WELCOME SUPREME TENTACLEE COMMANDER.",70,60,2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("INITIATING TRACTOR BEAM AND AUTOMATIC",70,70,2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("LANDING PROCEDURE.",70,80,2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("WE WILL BE DEPARTING FOR THE PLANET",70,90,2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("EERM IN THREE MICROCYCLE UNITS.",70,100,2,0,1,tb1_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - pauseawhile(5); - - game_state->level=3; - vmwClearKeyboardBuffer(); - - vmwArbitraryCrossBlit(game_state->virtual_3,0,42,58,37, - game_state->virtual_1,10,110); - - vmwSmallTextXY("Wha? Wait!",70,110,9,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("What's happening?",70,120,9,0,1,tb1_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - pauseawhile(6); - } - - vmwLoadPicPacked(0,0,game_state->virtual_3,0,1, - tb1_data_file("level3/tbtract.tb1",game_state->path_to_data), - game_state->graph_state); - - - vmwArbitraryCrossBlit(game_state->virtual_3,0,0,240,50, - game_state->virtual_2,0,0); - vmwClearScreen(game_state->virtual_1,0); - - setupsidebar(game_state,virtual_1); - - - for(howmuchscroll=50;howmuchscroll>0;howmuchscroll--) { - vmwArbitraryCrossBlit(virtual_2,0,howmuchscroll,240,200,virtual_1,0,0); - usleep(30000); - vmwPutSprite(ship_shape[0],shipx,165,virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - } - - if ((ch=='N') || (ch=='n')) { - vmwClearKeyboardBuffer(); - vmwLine(7,6,shipx+10,180,4,virtual_1); - vmwLine(shipx+37,180,231,6,4,virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - pauseawhile(1); - vmwClearKeyboardBuffer(); - for(i=shipx;igraph_state,virtual_1); - pauseawhile(2); - vmwArbitraryCrossBlit(virtual_2,0,howmuchscroll,240,200,virtual_1,0,0); - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - pauseawhile(2); - } - - - else { - if (shipx-95==0) shipadd=0; - if (shipx-95>0) shipadd=1; - if (shipx-95<0) shipadd=-1; - shipy=165; - while ((shipx!=95) || (shipy>10)) { - if (shipx!=95) shipx-=shipadd; - if (shipy>10) shipy--; - vmwArbitraryCrossBlit(virtual_2,0,howmuchscroll,240,200,virtual_1,0,0); - - vmwLine(7,6,shipx+12,shipy+15,2,virtual_1); - vmwLine(shipx+37,shipy+15,231,6,2,virtual_1); - vmwPutSprite(ship_shape[0],shipx,shipy,virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - usleep(30000); - } - vmwClearKeyboardBuffer(); - pauseawhile(8); - vmwClearScreen(virtual_1,0); - } -/* - while keypressed do ch:=readkey; - if level=4 then begin - vmwSmallTextXY('THE PLANET EERM?',20,20,10,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY('XENOCIDE FLEET?',20,30,10,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY('WHAT'S GOING ON?',20,40,10,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY('A MAJOR GOVERNMENT CONSPIRACY? MASS HALUCINATIONS?',20,50,10,0,1,tb1_font,game_state->virtual_1); - - vmwSmallTextXY('WATCH FOR TOM BOMBEM LEVEL 3 (CURRENTLY IN THE DESIGN PHASE).',10,70,12,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY('ALL THESE QUESTIONS WILL BE ANSWERED!',10,80,12,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY('ALSO MORE FEATURES WILL BE ADDED:',10,90,12,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY(' BETTER GRAPHICS, SOUND AND SPEED.',10,100,12,0,1,tb1_font,game_state->virtual_1); - - vmwSmallTextXY('TO HASTEN COMPLETION, SEND QUESTIONS/COMMENTS/DONATIONS TO ',9,120,9,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY('THE AUTHOR (SEE THE REGISTER MESSAGE FOR RELEVANT ADDRESSES).',9,130,9,0,1,tb1_font,game_state->virtual_1); - - vmwSmallTextXY('THANK YOU FOR PLAYING TOM BOMBEM',80,150,14,0,1,tb1_font,game_state->virtual_1); - unfade; - pauseawhile(1800); - end; */ - levelover=1; - } - } - -} - - - -void littleopener2(tb1_state *game_state) { - - vmwDrawBox(0,0,319,199,0,game_state->virtual_1); - vmwLoadPicPacked(0,0,game_state->virtual_1,1,1, - tb1_data_file("level2/tbl2ship.tb1",game_state->path_to_data), - game_state->graph_state); - vmwTextXY("Hmmmm... ",10,10,4,0,0,game_state->graph_state->default_font, - game_state->virtual_1); - vmwTextXY("This Might Be Harder Than I Thought.",10,20,4,0,0, - game_state->graph_state->default_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - pauseawhile(13); - vmwDrawBox(0,0,319,199,0,game_state->virtual_1); - -} +#include +#include /* strncmp */ +#include /* usleep */ +#include /* free */ +#include /* gettimeofday */ + +#include "./svmwgraph/svmwgraph.h" +#include "tb1_state.h" +#include "tblib.h" +#include "graphic_tools.h" +#include "sidebar.h" +#include "sound.h" +#include "help.h" +#include "loadsave.h" + +#define ROW_WIDTH 12 +#define COL_HEIGHT 20 + +/* #define DEBUG 1 */ + +struct sprite_type { + int initialized; + int type; + int shoots; + int explodes; + vmwSprite *data; +}; + +struct level2_data { + int xsize,ysize,rows,cols; + int numsprites; + struct sprite_type **sprites; + int level_length,level_width; + unsigned char **level_data; +}; + + +#define SPRITE_BACKGROUND 0 +#define SPRITE_ENEMY_SHOOT 1 +#define SPRITE_ENEMY_REFLECT 2 +#define SPRITE_ENEMY_WEAPON 3 +#define SPRITE_OBSTRUCTION 4 +#define SPRITE_EXPLOSION 5 +#define SPRITE_WEAPON 6 +#define SPRITE_POWERUP 7 + + +struct text_mapping_type { + char name[30]; + int size; + int type; +} text_mapping[] = { {"BACKGROUND", 10, SPRITE_BACKGROUND}, + {"ENEMY_SHOOT", 11, SPRITE_ENEMY_SHOOT}, + {"ENEMY_REFLECT", 13, SPRITE_ENEMY_REFLECT}, + {"ENEMY_WEAPON", 12, SPRITE_ENEMY_WEAPON}, + {"OBSTRUCTION", 11, SPRITE_OBSTRUCTION}, + {"EXPLOSION", 9, SPRITE_EXPLOSION}, + {"WEAPON", 6, SPRITE_WEAPON}, + {"POWERUP", 7, SPRITE_POWERUP}, + {"DONE", 4, 0xff}, + { } +}; + +int belongs_on_map(int type) { + + switch (type) { + case SPRITE_BACKGROUND: + case SPRITE_ENEMY_SHOOT: + case SPRITE_ENEMY_REFLECT: + case SPRITE_OBSTRUCTION: return 1; + default: return 0; + } + return 0; +} + + +int map_string_to_type(char *string) { + + int i=0; + + while(text_mapping[i].type!=0xff) { + if (!strncmp(text_mapping[i].name,string,text_mapping[i].size)) { +// printf("%s %i\n",string,text_mapping[i].type); + return text_mapping[i].type; + } + i++; + } + return -1; +} + +struct level2_data *parse_data_file(char *filename) { + + + FILE *fff; + char tempst[255],sprite_file[255],throwaway[255]; + char type[255]; + int number,shoots,explodes,count,i,numsprites,tempint; + struct level2_data *data; + + fff=fopen(filename,"r"); + if (fff==NULL) { + printf("Cannot open %s\n",filename); + return NULL; + } + + data=(struct level2_data *)malloc(sizeof(struct level2_data)); + + /* Pass 1 */ + do { + fgets(tempst,254,fff); + + switch (tempst[0]) { + + case '%': + if (!strncmp(tempst,"%SPRITEFILE",11)) { + sscanf(tempst,"%s %s",throwaway,sprite_file); + } + if (!strncmp(tempst,"%SPRITEXSIZE",11)) { + sscanf(tempst,"%s %d",throwaway,&data->xsize); + } + if (!strncmp(tempst,"%SPRITEYSIZE",11)) { + sscanf(tempst,"%s %d",throwaway,&data->ysize); + } + if (!strncmp(tempst,"%SPRITEROWS",11)) { + sscanf(tempst,"%s %d",throwaway,&data->rows); + } + if (!strncmp(tempst,"%SPRITECOLS",11)) { + sscanf(tempst,"%s %d",throwaway,&data->cols); + } + } + + } while (!feof(fff)); + + /* Pass 2 */ + + numsprites=(data->rows) * (data->cols); + data->numsprites=numsprites; + + data->sprites=calloc( numsprites, sizeof(struct sprite_type*)); + for (i=0; i< numsprites;i++) { + data->sprites[i]=calloc(1,sizeof(struct sprite_type)); + data->sprites[i]->initialized=0; + } + + rewind(fff); + do { + fgets(tempst,254,fff); + switch(tempst[0]) { + + case '%': if (!strncmp(tempst,"%SPRITE ",8)) { + count=sscanf(tempst,"%s %d %s %d %d", + throwaway,&number,type,&shoots,&explodes); + + if (count > 2) { + data->sprites[number]->type=map_string_to_type(type); + data->sprites[number]->initialized=1; + } + if (count > 3) { + data->sprites[number]->shoots=shoots; + } + if (count > 4) { + data->sprites[number]->explodes=explodes; + } + } + if (!strncmp(tempst,"%DATALENGTH",10)) { + sscanf(tempst,"%s %d",throwaway,&data->level_length); + } + if (!strncmp(tempst,"%DATAWIDTH",9)) { + sscanf(tempst,"%s %d",throwaway,&data->level_width); + } + + break; + + + } + } while (!feof(fff)); + + + /* Pass 3 */ + data->level_data=calloc(data->level_length, sizeof(char *)); + + data->level_data[0]=calloc(data->level_length * data->level_width,sizeof(char)); + for(i=1;ilevel_length;i++) { + data->level_data[i]=data->level_data[0]+ (i*data->level_width*sizeof(char)); + } + + rewind(fff); + + + do { + fgets(tempst,254,fff); + } while (strncmp(tempst,"%DATABEGIN",10)); + + i=0; + while(ilevel_length*data->level_width) { + /* Grrrrr */ +// fscanf(fff,"%d",(int *)data->level_data[0]); + fscanf(fff,"%d",&tempint); + *(data->level_data[0]+i)=(char)tempint; + i++; + } +#ifdef DEBUG + print_level(data); + + printf("Sprite File: %s\n",sprite_file); + printf("Sprite size: %ix%i\n",data->xsize,data->ysize); + printf("Sprite array: %ix%i\n",data->rows,data->cols); + printf("Level length: %i\n",data->level_length); +#endif + fclose(fff); + return data; +} + +int free_level2_data(struct level2_data *data) { + /* IMPLEMENT THIS */ + return 0; +} + + + /* Define this to get a frames per second readout */ +/* #define DEBUG_ON */ + + /* The sounds */ + +#define NUM_SAMPLES 8 +#define SND_AHH 0 +#define SND_CC 1 +#define SND_KAPOW 2 +#define SND_SCREAM 3 +#define SND_BONK 4 +#define SND_CLICK 5 +#define SND_OW 6 +#define SND_ZRRP 7 + +struct enemy_info_type { + int out; + int x,y; + int yspeed; + int type; + +}; + +struct bullet_info_type { + int out,x,y; +}; + +struct obstruction_type { + int valid; + int type,shoots; + int exploding; + int explodeprogress; + int howmanyhits; + int lastshot; +}; + + +#define BULLETS_MAX 3 +#define ENEMIES_MAX 25 + + struct enemy_info_type *enemies; + + struct bullet_info_type *bullets; + int bullets_out=0; + +void leveltwoengine(tb1_state *game_state, char *shipfile, char *levelfile, + char *spritefile,char *level_num, char *level_desc, + void *close_function) +{ + int ch,i,temp_y; + char tempst[BUFSIZ]; + int game_paused=0; + int shipx=36,shipy; + int whatdelay=1; + int levelover=0,j,offscreen_row=0; + struct timeval timing_info; + struct timezone dontcare; + + long oldusec,time_spent;//oldsec + int howmuchscroll=200; /* there is a reason for this */ + struct obstruction_type obstruction[12][20]; + int shipadd=0,shipframe=1; + int our_row,rows_goneby=0,rows_offset=0; + int grapherror; + int done_waiting,type; + + vmwFont *tb1_font; + vmwVisual *virtual_1; + vmwVisual *virtual_2; + + vmwSprite *ship_shape[3]; + + + struct level2_data *data; + + /* For convenience */ + tb1_font=game_state->graph_state->default_font; + virtual_1=game_state->virtual_1; + virtual_2=game_state->virtual_2; + + /* Set this up for Save Game */ + game_state->begin_score=game_state->score; + game_state->begin_shields=game_state->shields; + + /* Load Sprite Data */ + grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1, + tb1_data_file(shipfile, + game_state->path_to_data), + game_state->graph_state); + if (grapherror) { + return; + } + + ship_shape[0]=vmwGetSprite(0,0,48,30,virtual_1); + ship_shape[1]=vmwGetSprite(0,32,48,30,virtual_1); + ship_shape[2]=vmwGetSprite(0,64,48,30,virtual_1); + + + /* Load Level Data */ + data=parse_data_file(tb1_data_file(levelfile,game_state->path_to_data)); + + vmwLoadPicPacked(0,0,virtual_1,1,1, + tb1_data_file(spritefile,game_state->path_to_data), + game_state->graph_state); + + for(j=0;jrows;j++) + for(i=0;icols;i++) + data->sprites[j*10+i]->data=vmwGetSprite(1+i*21,1+j*11,20,10,virtual_1); + + + /* Initialize Bullets */ + bullets=calloc(BULLETS_MAX,sizeof(struct bullet_info_type)); + for (i=0;igraph_state,virtual_1); + vmwClearKeyboardBuffer(); + pauseawhile(5); + + /* Setup and draw the sidebar */ + setupsidebar(game_state,virtual_2); + vmwFlipVirtual(virtual_1,virtual_2,320,200); + sprintf(tempst,"%d",game_state->level); + vmwDrawBox(251,52,63,7,0,virtual_2); + vmwTextXY(tempst,307,51,12,0,0,tb1_font,virtual_2); + + change_shields(game_state); + + /* Ready the timing loop */ + gettimeofday(&timing_info,&dontcare); + //oldsec=timing_info.tv_sec; + oldusec=timing_info.tv_usec; + + /* Get the initial background ready */ + /* We copy the last 40 rows into vaddr_2 */ + /* as we are scrolling bottom_up */ + offscreen_row=data->level_length-(COL_HEIGHT*2); + for(i=0;isprites[(int) *(data->level_data[offscreen_row+j]+i)]->data, + i*20,j*10,virtual_2); + } + } + offscreen_row-=20; + + /* Get the initial obstructions ready */ + /* Get them from the last 20 rows */ + our_row=data->level_length-20; + for(j=0;j<20;j++) { + for(i=0;i<12;i++) { + + type=data->sprites[*(data->level_data[our_row]+i)]->type; + + if ((type==SPRITE_OBSTRUCTION) || + (type==SPRITE_ENEMY_SHOOT) || + (type==SPRITE_ENEMY_REFLECT)) { + + obstruction[i][j].shoots=data->sprites[*(data->level_data[our_row]+i)]->shoots; + obstruction[i][j].valid=1; + obstruction[i][j].type=type; + obstruction[i][j].exploding=0; + obstruction[i][j].lastshot=0; + + } + } + } + + /* howmuchscroll is originally 200, as we start at the bottom */ + vmwArbitraryCrossBlit(virtual_2,0,0+howmuchscroll,240,200, + virtual_1,0,0); + + + + /************************************************************/ + /* MAIN LEVEL 2 GAME LOOP */ + /************************************************************/ + + while (!levelover) { + + ch=0; + + /* Scroll the Background */ + howmuchscroll--; + rows_offset++; + + /* If used up all the buffered background, draw some more */ + if (howmuchscroll<0) { + howmuchscroll=200+howmuchscroll; + /* Copy half of old downward */ + vmwArbitraryCrossBlit(virtual_2,0,0,240,200,virtual_2,0,200); + /* Load 20 rows of data preceding it */ + for(i=0;i<12;i++) { + for(j=0;j<20;j++) { + vmwPutSprite(data->sprites[(int) *(data->level_data[offscreen_row+j]+i)]->data, + i*20,j*10,virtual_2); + } + } + offscreen_row-=20; + } + + + /* Setup Obstructions */ + if (rows_offset==10) { + + rows_offset=0; + + /* move all rows down by one, dropping old off end */ + memmove(&obstruction[0][1],&obstruction[0][0], + 19*12*sizeof(struct obstruction_type)); + + our_row--; + + for(i=0;i<12;i++) { + type=data->sprites[*(data->level_data[our_row]+i)]->type; + if ((type==SPRITE_OBSTRUCTION) || + (type==SPRITE_ENEMY_SHOOT) || + (type==SPRITE_ENEMY_REFLECT)) { + + obstruction[i][0].shoots=data->sprites[*(data->level_data[our_row]+i)]->shoots; + obstruction[i][0].valid=1; + obstruction[i][0].type=type; + obstruction[i][0].exploding=0; + obstruction[i][0].lastshot=0; + } + else { + obstruction[i][0].valid=0; + } + } + } + + + + /* Flip the far background to regular background */ + vmwArbitraryCrossBlit(virtual_2,0,0+howmuchscroll,240,200, + virtual_1,0,0); + + /***Collision Check***/ + for(i=0;i= j*20) && + ( bullets[i].x <= j*20+17)) { + + if (obstruction[j][temp_y].type!=SPRITE_ENEMY_REFLECT) { + if ((game_state->sound_possible)&&(game_state->sound_enabled)) + playGameFX(SND_KAPOW); + obstruction[j][temp_y].exploding=1; + obstruction[j][temp_y].explodeprogress=0; + bullets[i].out=0; + bullets_out--; + game_state->score+=10; + changescore(game_state); + } + + else { + int k=0; + + while(enemies[k].out) k++; + if (k50) { + int k=0; + + obstruction[i][j].lastshot=rand()%10; + while(enemies[k].out) k++; + if (k155) && (passive[i].kind!=10)) { + if ((collision(passive[i].x,passive[i].y,10,5,shipx+16,165,5,5))|| + (collision(passive[i].x,passive[i].y,10,5,shipx+6,175,18,8))) { + if ((game_state->sound_possible)&&(game_state->sound_enabled)) + playGameFX(SND_BONK); + passive[i].dead=1; + game_state->shields--; + if(game_state->shields<0) levelover=1; +// vmwPutSprite(shape_table[34], +// passive[i].x,passive[i].y+howmuchscroll, +// virtual_1); + change_shields(game_state); + } + } + } + /* See if hit by lasers */ + for (i=0;i<10;i++) + if (enemy[i].out) { + if ((collision(enemy[i].x,enemy[i].y,2,5,shipx+16,165,5,5)) || + (collision(enemy[i].x,enemy[i].y,2,5,shipx+6,175,18,8))) { + if ((game_state->sound_possible)&&(game_state->sound_enabled)) + playGameFX(SND_BONK); + enemy[i].out=0; + game_state->shields--; + if (game_state->shields<0) levelover=1; + change_shields(game_state); + } + } + +#endif + + + /***DO EXPLOSIONS***/ + for(i=0;i<12;i++) { + for(j=0;j<20;j++) { + if (obstruction[i][j].valid) { + if (obstruction[i][j].exploding) { + obstruction[i][j].explodeprogress++; + + vmwPutSprite(data->sprites[35+(obstruction[i][j].explodeprogress)/2]->data, + // shape_table[35+passive[i].explodeprogress], + i*20,j*10+howmuchscroll+rows_offset, + virtual_2); + if (obstruction[i][j].explodeprogress>6) { + obstruction[i][j].valid=0; + vmwPutSprite(data->sprites[34]->data, + i*20,j*10+howmuchscroll+rows_offset, + virtual_2); + } + + } + + } + } + } + + /***MOVE BULLETS***/ + for(i=0;isprites[20]->data, + + bullets[i].x, + bullets[i].y,virtual_1); + } + } + + } + +#if 0 + /***MOVE ENEMIES***/ + for(j=0;j<40;j++) { + if (!passive[j].dead) { + if (speed_factor==1) passive[j].y++; + else passive[j].y+=speed_factor; + if (passive[j].y>190) passive[j].dead=1; + } + if (passive[j].lastshot>0) passive[j].lastshot--; + if ((!passive[j].dead) && (passive[j].shooting) + && (!passive[j].lastshot) && (passive[j].y>0)) { + k=0; + while ((enemy[k].out) && (k<10)) k++; + if (k<9) { + passive[j].lastshot=30; + enemy[k].out=1; + enemy[k].y=passive[j].y; + enemy[k].x=passive[j].x+5; + enemy[k].yspeed=5; + enemy[k].kind=25; + if (passive[j].kind==11) enemy[k].kind=26; + } + } + } +#endif + /* Draw Enemies */ + for(j=0;j189) enemies[j].out=0; + else { + vmwPutSprite(data->sprites[enemies[j].type]->data, + enemies[j].x,enemies[j].y, + virtual_1); + enemies[j].y+=enemies[j].yspeed; + } + + } + } + + + /***READ KEYBOARD***/ + if ((ch=vmwGetInput())!=0) { + switch(ch) { + case VMW_ESCAPE: levelover=1; break; + case VMW_RIGHT: if (shipadd>=0) shipadd+=3; else shipadd=0; break; + case VMW_LEFT: if (shipadd<=0) shipadd-=3; else shipadd=0; break; + case VMW_F1: game_paused=1; help(game_state); break; + case '+': whatdelay++; break; + case 'P': case 'p': game_paused=1; + coolbox(65,85,175,110,1,virtual_1); + vmwTextXY("GAME PAUSED",79,95,4,7, + 0,tb1_font,virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + while (vmwGetInput()==0) usleep(30000); + break; + case '-': whatdelay--; break; + case 'S': + case 's': game_state->sound_enabled=!(game_state->sound_enabled); break; + case VMW_F2: game_paused=1; + savegame(game_state); + break; + case ' ': + i=0; + while(bullets[i].out) i++; + if (isound_possible)&&(game_state->sound_enabled)) + playGameFX(SND_CC); + bullets[i].x=shipx+21; + bullets[i].y=165; + + vmwPutSprite(data->sprites[20]->data, + bullets[i].x, + bullets[i].y,virtual_1); + } + + break; + } + + } + + + + /***MOVE SHIP***/ + + shipx+=shipadd; + + rows_goneby++; + + + /* Keep ship on screen */ + if (shipx<1) shipx=1; + if (shipx>190) shipx=190; + switch(shipframe) { + case 1: vmwPutSprite(ship_shape[0], + shipx,165,virtual_1); break; + case 3: vmwPutSprite(ship_shape[1], + shipx,165,virtual_1); break; + case 2: + case 4: vmwPutSprite(ship_shape[2], + shipx,165,virtual_1); break; + } + shipframe++; + if (shipframe==5) shipframe=1; + + /* Flip Pages */ + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + + + /* If time passed was too little, wait a bit */ + /* 33,333 would frame rate to 30Hz */ + /* Linux w 100Hz scheduling only gives +- 10000 accuracy */ + done_waiting=0; + while (!done_waiting) { + + gettimeofday(&timing_info,&dontcare); + time_spent=timing_info.tv_usec-oldusec; + + /* Assume we don't lag more than a second */ + /* Seriously, if we lag more than 10ms we are screwed anyway */ + if (time_spent<0) time_spent+=1000000; + if (time_spent<30000) usleep(100); + else (done_waiting=1); + } + + oldusec=timing_info.tv_usec; + //oldsec=timing_info.tv_sec; + + /* If game is paused, don't keep track of time */ + if (game_paused) { + gettimeofday(&timing_info,&dontcare); + oldusec=timing_info.tv_usec; + //oldsec=timing_info.tv_sec; + game_paused=0; + } + + /* The level is over */ + /* FIXME autocalculate rather than 1950 */ + + if (rows_goneby>1950) { +// printf("%i\n",rows_goneby); +// coolbox(35,85,215,110,1,virtual_1); +// vmwTextXY("TO BE CONTINUED...",55,95,4,7,0,tb1_font,virtual_1); +// vmwBlitMemToDisplay(game_state->graph_state,virtual_1); +// pauseawhile(10); + + vmwClearKeyboardBuffer(); + pauseawhile(5); + vmwLoadPicPacked(0,0,game_state->virtual_3,0,1, + tb1_data_file("level1/viewscr.tb1",game_state->path_to_data), + game_state->graph_state); + vmwClearScreen(game_state->virtual_1,0); + vmwArbitraryCrossBlit(game_state->virtual_3,0,79,58,37, + game_state->virtual_1,10,10); + vmwClearKeyboardBuffer(); + vmwSmallTextXY("UNIDENTIFIED SPACECRAFT!",70,10,2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("DO YOU WISH TO DEACTIVATE ",70,20,2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("THIS SHIP'S SECURITY SYSTEMS? (Y/N)",70,30,2,0,1,tb1_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + vmwClearKeyboardBuffer(); + + ch='!'; + while ((ch!='Y') && (ch!='y') && (ch!='N') && (ch!='n')) { + while(!(ch=vmwGetInput())) usleep(1000); + } + + if ((ch=='N') || (ch=='n')) { + vmwArbitraryCrossBlit(game_state->virtual_3,0,79,58,37, + game_state->virtual_1,10,50); + vmwSmallTextXY("NO? AFFIRMATIVE. ",70,50,9,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("ARMING REMOTE DESTRUCTION RAY.",70,60,9,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("GOOD-BYE.",70,70,9,0,1,tb1_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + pauseawhile(4); + } + + + if ((ch=='Y') || (ch=='y')) { + vmwArbitraryCrossBlit(game_state->virtual_3,0,79,58,37, + game_state->virtual_1,10,50); + vmwSmallTextXY("'Y'=CORRECT PASSWORD. ",70,50,2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("WELCOME SUPREME TENTACLEE COMMANDER.",70,60,2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("INITIATING TRACTOR BEAM AND AUTOMATIC",70,70,2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("LANDING PROCEDURE.",70,80,2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("WE WILL BE DEPARTING FOR THE PLANET",70,90,2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("EERM IN THREE MICROCYCLE UNITS.",70,100,2,0,1,tb1_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + pauseawhile(5); + + game_state->level=3; + vmwClearKeyboardBuffer(); + + vmwArbitraryCrossBlit(game_state->virtual_3,0,42,58,37, + game_state->virtual_1,10,110); + + vmwSmallTextXY("Wha? Wait!",70,110,9,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("What's happening?",70,120,9,0,1,tb1_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + pauseawhile(6); + } + + vmwLoadPicPacked(0,0,game_state->virtual_3,0,1, + tb1_data_file("level3/tbtract.tb1",game_state->path_to_data), + game_state->graph_state); + + + vmwArbitraryCrossBlit(game_state->virtual_3,0,0,240,50, + game_state->virtual_2,0,0); + vmwClearScreen(game_state->virtual_1,0); + + setupsidebar(game_state,virtual_1); + + + for(howmuchscroll=50;howmuchscroll>0;howmuchscroll--) { + vmwArbitraryCrossBlit(virtual_2,0,howmuchscroll,240,200,virtual_1,0,0); + usleep(30000); + vmwPutSprite(ship_shape[0],shipx,165,virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + } + + if ((ch=='N') || (ch=='n')) { + vmwClearKeyboardBuffer(); + vmwLine(7,6,shipx+10,180,4,virtual_1); + vmwLine(shipx+37,180,231,6,4,virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + pauseawhile(1); + vmwClearKeyboardBuffer(); + for(i=shipx;igraph_state,virtual_1); + pauseawhile(2); + vmwArbitraryCrossBlit(virtual_2,0,howmuchscroll,240,200,virtual_1,0,0); + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + pauseawhile(2); + } + + + else { + if (shipx-95==0) shipadd=0; + if (shipx-95>0) shipadd=1; + if (shipx-95<0) shipadd=-1; + shipy=165; + while ((shipx!=95) || (shipy>10)) { + if (shipx!=95) shipx-=shipadd; + if (shipy>10) shipy--; + vmwArbitraryCrossBlit(virtual_2,0,howmuchscroll,240,200,virtual_1,0,0); + + vmwLine(7,6,shipx+12,shipy+15,2,virtual_1); + vmwLine(shipx+37,shipy+15,231,6,2,virtual_1); + vmwPutSprite(ship_shape[0],shipx,shipy,virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + usleep(30000); + } + vmwClearKeyboardBuffer(); + pauseawhile(8); + vmwClearScreen(virtual_1,0); + } +/* + while keypressed do ch:=readkey; + if level=4 then begin + vmwSmallTextXY('THE PLANET EERM?',20,20,10,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY('XENOCIDE FLEET?',20,30,10,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY('WHAT'S GOING ON?',20,40,10,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY('A MAJOR GOVERNMENT CONSPIRACY? MASS HALUCINATIONS?',20,50,10,0,1,tb1_font,game_state->virtual_1); + + vmwSmallTextXY('WATCH FOR TOM BOMBEM LEVEL 3 (CURRENTLY IN THE DESIGN PHASE).',10,70,12,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY('ALL THESE QUESTIONS WILL BE ANSWERED!',10,80,12,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY('ALSO MORE FEATURES WILL BE ADDED:',10,90,12,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY(' BETTER GRAPHICS, SOUND AND SPEED.',10,100,12,0,1,tb1_font,game_state->virtual_1); + + vmwSmallTextXY('TO HASTEN COMPLETION, SEND QUESTIONS/COMMENTS/DONATIONS TO ',9,120,9,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY('THE AUTHOR (SEE THE REGISTER MESSAGE FOR RELEVANT ADDRESSES).',9,130,9,0,1,tb1_font,game_state->virtual_1); + + vmwSmallTextXY('THANK YOU FOR PLAYING TOM BOMBEM',80,150,14,0,1,tb1_font,game_state->virtual_1); + unfade; + pauseawhile(1800); + end; */ + levelover=1; + } + } + +} + + + +void littleopener2(tb1_state *game_state) { + + vmwDrawBox(0,0,319,199,0,game_state->virtual_1); + vmwLoadPicPacked(0,0,game_state->virtual_1,1,1, + tb1_data_file("level2/tbl2ship.tb1",game_state->path_to_data), + game_state->graph_state); + vmwTextXY("Hmmmm... ",10,10,4,0,0,game_state->graph_state->default_font, + game_state->virtual_1); + vmwTextXY("This Might Be Harder Than I Thought.",10,20,4,0,0, + game_state->graph_state->default_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + pauseawhile(13); + vmwDrawBox(0,0,319,199,0,game_state->virtual_1); + +} diff --git a/tb1_linux/level_1.c b/tb1_linux/level_1.c index c6fdad7..22ddf9d 100644 --- a/tb1_linux/level_1.c +++ b/tb1_linux/level_1.c @@ -1,837 +1,836 @@ -/* - Level 1 Engine Code for Tom Bombem - * - * November 2000 -- Changed the inner workings of engine. - * Now somewhat different than original feel. - */ - - /* The Includes */ -#include -#include -#include -#include - -#include "svmwgraph/svmwgraph.h" -#include "tb1_state.h" -#include "levels.h" - -#include "sound.h" - -#include "tblib.h" -#include "sidebar.h" -#include "help.h" -#include "loadsave.h" -#include "graphic_tools.h" - - /* Define this to get a frames per second readout */ -/*#define DEBUG_ON */ - - /* The sounds */ - -#define NUM_SAMPLES 8 -#define SND_AHH 0 -#define SND_CC 1 -#define SND_KAPOW 2 -#define SND_SCREAM 3 -#define SND_BONK 4 -#define SND_CLICK 5 -#define SND_OW 6 -#define SND_ZRRP 7 - - -#define NUM_ENEMIES 5 -#define NUM_MISSILES 2 - -struct enemyinfo { - int x,y; - int kind; - int out,exploding,boundarycheck,dead; - int explodeprogress; - int minx,maxx,xspeed,yspeed; - int hitsneeded; -}; - -struct missileinfo { - int out,x,y; -}; - - /* Define how many sound effects there are */ - - - /* Global Variables*/ -struct enemyinfo enemy[NUM_ENEMIES]; -struct missileinfo missile[NUM_MISSILES]; -struct timeval timing_info; -struct timezone dontcare; - -int enemies_out; - -#define LEVEL_OVER 9 - -#define STANDARD 0 -#define DIAGONAL 1 -#define DIAGONAL_NO_WAIT 2 -#define WIGGLING 3 -#define RAINING 4 - -#define SCROLL_A_BIT 7 -#define BEFORE_BOSS 10 -#define BOSS_BEHAVIOR 11 -#define AFTER_BOSS 12 -#define BOSS_DESTROYED 13 -#define INVISIBLE_WAVE 15 -#define THE_END 100 - -typedef struct { - int enemy_type; - int how_many; -}level_one_behavior_t; - - /* This seemed like a good idea to modularize things */ - /* Should make it a file read from disk */ -level_one_behavior_t level_one_wave_behavior[]= - {{STANDARD,5}, - {STANDARD,5}, - {DIAGONAL,5}, - {DIAGONAL_NO_WAIT,5}, - {WIGGLING,8}, - {RAINING,10}, - {WIGGLING,6}, - {RAINING,12}, - {DIAGONAL,5}, - {RAINING,10}, - {WIGGLING,16}, - {DIAGONAL,5}, - {DIAGONAL_NO_WAIT,5}, - {RAINING,3}, - {WIGGLING,10}, - {DIAGONAL,5}, - {SCROLL_A_BIT,100}, - {BEFORE_BOSS,1}, - {SCROLL_A_BIT,100}, - {BOSS_BEHAVIOR,1}, - {BOSS_DESTROYED,100}, - {AFTER_BOSS,1}, - {THE_END,1}}; - - - - /* The little Sequence Before you hit the Boss */ -void beforeboss(tb1_state *game_state) -{ - - vmwClearKeyboardBuffer(); - vmwLoadPicPacked(0,0,game_state->virtual_3,1,1, - tb1_data_file("level1/viewscr.tb1",game_state->path_to_data), - game_state->graph_state); - vmwClearScreen(game_state->virtual_1,0); - vmwArbitraryCrossBlit(game_state->virtual_3,0,5,58,37, - game_state->virtual_1,10,10); - vmwSmallTextXY("HUMAN!",70,10,2,0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwSmallTextXY("WHAT ARE YOU DOING?!",70,20,2, - 0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwSmallTextXY("YOUR SPECIES MUST BE TERMINATED!",70,30,2, - 0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - pauseawhile(5); - - vmwArbitraryCrossBlit(game_state->virtual_3,0,42,58,37, - game_state->virtual_1,10,50); - vmwSmallTextXY("I'M SORRY.",70,50,9,0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwSmallTextXY("WE DIDN'T MEAN TO DESTROY YOUR ENVOY.",70,60,9, - 0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwSmallTextXY("WILL YOU FORGIVE US AND TRY PEACE?",70,70,9, - 0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - pauseawhile(5); - - vmwArbitraryCrossBlit(game_state->virtual_3,0,5,58,37, - game_state->virtual_1,10,90); - vmwSmallTextXY("NO! YOU MUST BE DESTROYED!",70,90,2, - 0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwSmallTextXY("OUR FUNDING ... OUR ENVOY WAS DAMAGED BY",70,100, - 2,0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwSmallTextXY("YOU! VENGEANCE WILL BE OURS! YOUR PUNY",70,110, - 2,0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwSmallTextXY("PRIMITIVE SPACECRAFT WITH ITS INFERIOR",70,120, - 2,0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwSmallTextXY("WEAPONS WOULD HAVE TO SCORE 9 DIRECT HITS",70,130, - 2,0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwSmallTextXY("TO DESTROY MY SHIP! DIE EARTH SCUM!!!!",70,140, - 2,0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - pauseawhile(5); - setupsidebar(game_state,game_state->virtual_2); - vmwFlipVirtual(game_state->virtual_1,game_state->virtual_2,320,200); -} - - /* The Sequence After You Defeat (hopefully) the Boss */ -void afterboss(tb1_state *game_state) -{ - - vmwFont *tb1_font; - - tb1_font=game_state->graph_state->default_font; - - vmwLoadPicPacked(0,0,game_state->virtual_3,1,1, - tb1_data_file("level1/viewscr.tb1",game_state->path_to_data), - game_state->graph_state); - vmwDrawBox(0,0,320,200,0,game_state->virtual_1); - vmwArbitraryCrossBlit(game_state->virtual_3,0,42,58,37, - game_state->virtual_1,10,10); - vmwSmallTextXY("HMM.. THEY DON'T BUILD SUPERIOR",70,10, - 9,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("TECHNOLOGY LIKE THEY USED TO.",70,20, - 9,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("I GUESS I CAN GO HOME NOW.",70,30, - 9,0,1,tb1_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - pauseawhile(5); - - vmwArbitraryCrossBlit(game_state->virtual_3,0,5,58,37, - game_state->virtual_1,10,50); - vmwSmallTextXY("NOT SO FAST! YOU JUST DESTROYED AN ANTIQUATED",70,50, - 2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("DEFENSE SYSTEM THAT WAS PROGRAMMED BY A 16",70,60, - 2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("YEAR OLD! OUR MAIN DEFENSE PROGRAMMER HAS ",70,70, - 2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("MUCH MORE SKILL NOW! UNLESS YOU DESTROY OUR",70,80, - 2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("ENTIRE XENOCIDE... I MEAN PEACE... ENVOY",70,90, - 2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("WE WILL STILL DESTROY YOUR HOME PLANET.",70,100, - 2,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("NICE TRY PUNY EARTHLING!",70,110,2, - 0,1,tb1_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - pauseawhile(7); - - vmwArbitraryCrossBlit(game_state->virtual_3,0,42,58,37, - game_state->virtual_1,10,130); - vmwSmallTextXY("HMM.. I GUESS I BETTER SAVE THE EARTH.",70,130, - 9,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("I'D BETTER SAVE MY GAME TOO.",70,140, - 9,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("D'OH! I''M OUT OF BIG MISSILES! ",70,150, - 9,0,1,tb1_font,game_state->virtual_1); - vmwSmallTextXY("WELL AT LEAST I HAVE SOME SMALLER SPARES.",70,160, - 9,0,1,tb1_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - pauseawhile(5); - game_state->level++; - -} - - - - - /* Defines the behavior of the objects in level 1 */ - /* Should change so it works even if NUM_ENEMIES>5 */ -int add_another_enemy(int start_of_level, - tb1_state *game_state) { - - int what_type,i,need_to_pause=0; - static int wave_pointer=0; - static int wait_full_wave=0; - static int enemies_left_in_wave=0; - static int fighting_boss=0; - - /* If re-initing, then clear some variables */ - /* If we don't do this, the static variables won't get reset */ - /* After Level1 starts over [i.e. you die] */ - if (start_of_level) { - wave_pointer=0; - enemies_out=0; - enemies_left_in_wave=0; - fighting_boss=0; - } - - /* If waiting for empty, then return w/o adding any */ - if ((wait_full_wave) && (enemies_out)) return 0; - else { - wait_full_wave=0; - } - -// if (level_one_wave_behavior[behavior_pointer]!=BOSS_BEHAVIOR) behavior_pointer++; - - /* In order to be called, an enemy was destroyed */ - - /* Are these sanity checks needed? */ - if (enemies_out<0) { - enemies_out=0; - printf("Blargh 0\n"); - } - if (enemies_out>NUM_ENEMIES) { - enemies_out=NUM_ENEMIES; - printf("Blargh 7\n"); - } - - if (enemies_left_in_wave<=0) { - wave_pointer++; - enemies_left_in_wave=level_one_wave_behavior[wave_pointer].how_many; - } - - /* Move on to next behvior */ - - switch(level_one_wave_behavior[wave_pointer].enemy_type) { - - /* STANDARD */ - /* That is, 5 enemies bouncing back/forth, gradually lowering*/ - case STANDARD: - /* We add all 5 at once, so there better not be anything else out */ - if (enemies_out==0) { - enemies_out=5; - enemies_left_in_wave-=5; - wait_full_wave=1; - /* Randomly pick what type they are */ - what_type=(2+rand()%8); - - for(i=0; i<5; i++) { - enemy[i].kind=what_type; - enemy[i].x=i*20; /* Space them in one line */ - enemy[i].y=0; - enemy[i].xspeed=5; - enemy[i].minx=(i*20); /* Make sure they "bounce" */ - enemy[i].maxx=(i*20)+120; /* Properly even when some */ - enemy[i].boundarycheck=1; /* Destroyed */ - enemy[i].yspeed=10; - enemy[i].out=1; - enemy[i].exploding=0; - enemy[i].hitsneeded=1; - enemy[i].dead=0; - } - } - break; - - /* *FALLING STRAIGHT* */ - /* That is, raining down from above */ - case RAINING: - /* Fill up all empty slots? Interesting behavior */ - for(i=0; i<5;i++) { - if ((!enemy[i].out) && ( (rand()%5)==3) ){ - enemies_left_in_wave--; - enemy[i].kind=rand()%8+2; - enemy[i].x=rand()%200+1; - enemy[i].y=0; - enemy[i].xspeed=0; - enemy[i].minx=enemy[i].x; /* Hacky way of making sure they */ - enemy[i].maxx=enemy[i].x; /* Fall vertically */ - enemy[i].boundarycheck=1; - enemy[i].yspeed=5+(wave_pointer/8); /* Fall faster as game */ - /* goes on */ - enemy[i].out=1; - enemy[i].exploding=0; - enemy[i].hitsneeded=1; - enemy[i].dead=0; - enemies_out++; - } - } - break; - - /* *FALLING GRADUALLY SIDEWAYS* */ - /* AKA Wiggling back and forth independently */ - case WIGGLING: - for(i=0;i<5;i++) { - if (!enemy[i].out) { - enemies_left_in_wave--; - enemy[i].kind=rand()%8+2; - enemy[i].y=0; - enemy[i].xspeed=5; - enemy[i].minx=rand()%100; /* Set a random range to "wiggle */ - enemy[i].maxx=rand()%100+120; - enemy[i].x=enemy[i].minx; - enemy[i].boundarycheck=0; - enemy[i].yspeed=1; /* Constantly Fall */ - enemy[i].out=1; - enemy[i].exploding=0; - enemy[i].hitsneeded=1; - enemy[i].dead=0; - enemies_out++; - } - } - break; - - /**ZIG-ZAG**/ - /* That is, fall in a diagonal formation */ - case DIAGONAL: - if (!enemies_out) wait_full_wave=1; - case DIAGONAL_NO_WAIT: - /* Another one of these that we need all to be empty */ - if (!enemies_out) { - enemies_out=5; - enemies_left_in_wave-=5; - what_type=rand()%8+2; - for(i=0;i<5;i++) { - if (!enemy[i].out) { - enemy[i].kind=what_type; - enemy[i].x=i*20; /* Nice diagonal pattern */ - enemy[i].y=i*10; - enemy[i].xspeed=5; - enemy[i].minx=0; - enemy[i].maxx=220; - enemy[i].boundarycheck=0; - enemy[i].yspeed=1; /* Gradually fall */ - enemy[i].out=1; - enemy[i].exploding=0; - enemy[i].hitsneeded=1; - enemy[i].dead=0; - } - } - } - break; - - case SCROLL_A_BIT: - enemies_left_in_wave--; - break; - - case BEFORE_BOSS: - beforeboss(game_state); - enemies_left_in_wave--; - if ((game_state->sound_possible) &&(game_state->music_enabled)) { - loadSound(tb1_data_file("music/boss1.mod",game_state->path_to_data)); - playSound(); - } - - break; - - case BOSS_DESTROYED: - enemies_left_in_wave--; - if ((enemies_left_in_wave>25) && ( !(enemies_left_in_wave%3)) && - (game_state->sound_possible)&&(game_state->sound_enabled)) { - playGameFX(SND_KAPOW); - } - break; - - - case AFTER_BOSS: - stopSound(); - afterboss(game_state); - enemies_left_in_wave--; - break; - - case THE_END: - return LEVEL_OVER; - - /* Beginning of Boss */ - case BOSS_BEHAVIOR: - if ((!enemies_out) && (!fighting_boss)) { - fighting_boss=1; - enemy[0].kind=14; - enemy[1].kind=14; - enemy[2].kind=13; - for(i=0;i<3;i++) { - enemy[i].x=(i*20)+10; - enemy[i].y=0; - enemy[i].xspeed=5; - enemy[i].minx=0; - enemy[i].maxx=220; - enemy[i].boundarycheck=1; - enemy[i].yspeed=0; - enemy[i].out=1; - enemy[i].exploding=0; - enemy[i].hitsneeded=5; - enemy[i].dead=0; - enemies_out++; - } - } break; - default: break; - } - - if (fighting_boss) { - - /* Objects Cast off by the Boss */ - /* Detect if Level One is Over */ - if ((enemy[0].dead) && (enemy[1].dead) && (enemy[2].dead)) { - enemies_left_in_wave--; - fighting_boss=0; - } - else - for(i=3;i<5;i++) { - if ((!enemy[i].out) && (enemy[i-3].out)) { - enemies_out++; - enemy[i].kind=rand()%8+2; - enemy[i].x=enemy[i-3].x; - enemy[i].y=20; - enemy[i].xspeed=0; - enemy[i].minx=enemy[i].x; - enemy[i].maxx=enemy[i].x; - enemy[i].boundarycheck=0; - enemy[i].yspeed=4; - enemy[i].out=1; - enemy[i].exploding=0; - enemy[i].hitsneeded=1; - enemy[i].dead=0; - } - } - } - return need_to_pause; -} - - - - - /* The Main Level One */ -void LevelOneEngine(tb1_state *game_state) { - - int ch=0; - int i,j,grapherror; - char tempst[300]; - int itemp,levelover=0; - int shipx=36,shipadd=0,shipframe=1; - vmwSprite *bigship1,*bigship2,*bigship3; - vmwSprite *shapetable[20]; - long oldsec,oldusec,time_spent=1; - int howmuchscroll=0; - int game_paused=0; - int done_waiting=0; - - vmwVisual *virtual_1,*virtual_2; - vmwFont *tb1_font; - - /* For convenience */ - tb1_font=game_state->graph_state->default_font; - virtual_1=game_state->virtual_1; - virtual_2=game_state->virtual_2; - - /* Set this up for Save Game */ - game_state->begin_score=game_state->score; - game_state->begin_shields=game_state->shields; - - /* Load Ship Sprites */ - grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1, - tb1_data_file("level1/ships.tb1",game_state->path_to_data), - game_state->graph_state); - - bigship1=vmwGetSprite(0,0,48,30,virtual_1); - bigship2=vmwGetSprite(0,32,48,30,virtual_1); - bigship3=vmwGetSprite(0,64,48,30,virtual_1); - - /* Load Inanimate Object Shapes */ - grapherror=vmwLoadPicPacked(0,0,virtual_1,0,1, - tb1_data_file("level1/tbshapes.tb1",game_state->path_to_data), - game_state->graph_state); - - for(j=0;j<2;j++) - for(i=0;i<10;i++) - shapetable[(j*10)+i]=vmwGetSprite(1+(i*19),1+(j*19),18,18,virtual_1); - - /* Set up initial system conditions [ie, no enemies] */ - for(i=0;igraph_state, virtual_1); - - - /* Setup and draw the sidebar */ - setupsidebar(game_state,virtual_2); - - vmwFlipVirtual(virtual_1,virtual_2,320,200); - sprintf(tempst,"%d",game_state->level); -// vmwDrawBox(251,52,62,7,0,virtual_1); - vmwTextXY(tempst,307,51,12,0,0,tb1_font,virtual_1); - - /* Clear the screen and draw the stars */ - vmwDrawBox(0,0,320,400,0,virtual_2); - for(i=0;i<100;i++) { - vmwPutSprite(shapetable[11],rand()%238,rand()%380,virtual_2); - vmwPutSprite(shapetable[12],rand()%238,rand()%380,virtual_2); - } - /* Initialize shield state */ - change_shields(game_state); - - /* Initiate some last variables */ - add_another_enemy(1,game_state); - pauseawhile(5); - - /* Get time values for frame-limiting */ - gettimeofday(&timing_info,&dontcare); - oldsec=timing_info.tv_sec; - oldusec=timing_info.tv_usec; - - /* MAIN GAME LOOP */ - while(!levelover) { - ch=0; - /* Scroll the Stars */ - /* We have a 240x400 field of stars */ - howmuchscroll--; - if (howmuchscroll<0) howmuchscroll=399; - - /* If scroll>199, then we have to split into two copies */ - /* One from scroll to 400 */ - /* Another from 0-(scroll-200) */ - if (howmuchscroll>199) { - vmwArbitraryCrossBlit(virtual_2,0,howmuchscroll,240, - 400-howmuchscroll, - virtual_1,0,0); - vmwArbitraryCrossBlit(virtual_2,0,0,240,howmuchscroll-200, - virtual_1,0,400-howmuchscroll); - } - else { - vmwArbitraryCrossBlit(virtual_2,0,howmuchscroll,240,200, - virtual_1,0,0); - } - - - /* Add new enemies and move to next wave if needed */ - if (enemies_outlevel=2; - levelover=1; - return; - } - } - - - - /* See if the enemies have hit anything/scrolled off screen */ - for(i=0;isound_possible)&&(game_state->sound_enabled)) - playGameFX(SND_KAPOW); - enemy[i].hitsneeded--; - if (enemy[i].hitsneeded<1) enemy[i].dead=1; - else enemy[i].dead=0; - enemy[i].exploding=1; - enemy[i].explodeprogress=0; - missile[itemp].out=0; - game_state->score+=10; - changescore(game_state); - } - } - } - - /* While we are at it, see if scrolled off screen */ - if (enemy[i].y>179) { - enemy[i].out=0; - enemy[i].dead=1; - enemies_out--; - } - } - } - - /* Explode the things that are exploding */ - for(i=0;i1 */ - enemy[i].out=0; - enemy[i].exploding=0; - enemies_out--; - } - else enemy[i].exploding=0; - } - } - - /* Move the Missiles */ - for(i=0;i=enemy[i].maxx)) { - enemy[i].xspeed=-enemy[i].xspeed; - enemy[i].x+=enemy[i].xspeed; - enemy[i].y+=enemy[i].yspeed; - } - - /* See if colliding with spaceship */ - if (enemy[i].y>140) { - if (collision(shipx,165,24,15,enemy[i].x,enemy[i].y,9,9)) { - if ((game_state->sound_possible)&&(game_state->sound_enabled)) - playGameFX(SND_BONK); - enemy[i].hitsneeded--; - if (enemy[i].hitsneeded==0) enemy[i].dead=1; - else enemy[i].dead=0; - enemy[i].exploding=1; - enemy[i].explodeprogress=0; - game_state->shields--; - if (game_state->shields<0) levelover=1; - if (game_state->shields>0) change_shields(game_state); - } - } - } - } - - /* **READ KEYBOARD** */ - if ( (ch=vmwGetInput())!=0) { - switch(ch){ - case VMW_ESCAPE: levelover=1; break; - case VMW_RIGHT: if (shipadd>=0) shipadd+=3; else shipadd=0; break; - case VMW_LEFT: if (shipadd<=0) shipadd-=3; else shipadd=0; break; - case VMW_F1: game_paused=1; help(game_state); break; - case 'P': case 'p': game_paused=1; - coolbox(65,85,175,110,1,virtual_1); - vmwTextXY("GAME PAUSED",79,95,4,7, - 0,tb1_font,virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - while (vmwGetInput()==0) { - usleep(30000); - } - break; - case 'S': - case 's': if (game_state->sound_possible) - game_state->sound_enabled=!(game_state->sound_enabled); break; - case VMW_F2: game_paused=1; - savegame(game_state); - break; - case ' ': for(j=0;j<2;j++) - if (!missile[j].out) { - if ((game_state->sound_possible)&&(game_state->sound_enabled)) - playGameFX(SND_CC); - missile[j].out=1; - missile[j].x=shipx+15; - missile[j].y=165; - vmwPutSprite(shapetable[0], - missile[j].x, - missile[j].y,virtual_1); - j=3; - } - } - } - - /* **MOVE SHIP** */ - shipx+=shipadd; - if (shipx<1) shipx=1; - if (shipx>190) shipx=190; - switch(shipframe) { - - case 1: vmwPutSprite(bigship1,shipx,165,virtual_1); - break; - case 3: vmwPutSprite(bigship2,shipx,165,virtual_1); - break; - case 2: - case 4: vmwPutSprite(bigship3,shipx,165,virtual_1); - break; - } - shipframe++; - if (shipframe==5) shipframe=1; - - /* Flip Pages */ -#ifdef DEBUG_ON - sprintf(tempst,"%li",1000000/time_spent); - vmwTextXY(tempst,10,10,4,7,0,tb1_font,virtual_1); -#endif - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - - /* If time passed was too little, wait a bit */ - /* 33,333 would frame rate to 30Hz */ - /* Linux with 100Hz scheduling only gives +- 10000 accuracy */ - done_waiting=0; - while (!done_waiting){ - - gettimeofday(&timing_info,&dontcare); - time_spent=timing_info.tv_usec-oldusec; - /* Assume we don't lag more than a second */ - /* Seriously, if we lag more than 10ms we are screwed anyway */ - if (time_spent<0) time_spent+=1000000; - if (time_spent<30000) usleep(100); - else (done_waiting=1); - - } - oldusec=timing_info.tv_usec; - oldsec=timing_info.tv_sec; - - /* If game is paused, don't keep track of time */ - - if (game_paused) { - gettimeofday(&timing_info,&dontcare); - oldusec=timing_info.tv_usec; - oldsec=timing_info.tv_sec; - game_paused=0; - } - } - -} - - /* The little opener before Level 1 */ -void LevelOneLittleOpener(tb1_state *game_state) { - - vmwSprite *ship1,*ship2; - int i; - - vmwClearScreen(game_state->virtual_2,0); - - vmwLoadPicPacked(0,0,game_state->virtual_2,1,1, - tb1_data_file("level1/moon2.tb1",game_state->path_to_data), - game_state->graph_state); -// vmwLoadPicPacked(0,0,game_state->virtual_1,1,0, /* Load palette */ -// tb1_data_file("level1/moon2.tb1",game_state->path_to_data)); - - ship1=vmwGetSprite(9,178,15,18,game_state->virtual_2); - ship2=vmwGetSprite(30,178,15,18,game_state->virtual_2); - vmwDrawBox(0,178,319,21,0,game_state->virtual_2); - - for(i=100;i>0;i--) { - vmwFlipVirtual(game_state->virtual_1,game_state->virtual_2,320,200); - vmwPutSprite(ship2,i*2,100,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - usleep(30000); - if (vmwGetInput()) break; - } - vmwFlipVirtual(game_state->virtual_1,game_state->virtual_2,320,200); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - - vmwTextXY(">KCHK< TOM! WHERE ARE YOU GOING?",5,180,15,0,1, - game_state->graph_state->default_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - pauseawhile(3); - vmwDrawBox(0,178,319,21,0,game_state->virtual_1); - vmwTextXY("Ooops. ",5,180,24,0,1,game_state->graph_state->default_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - pauseawhile(3); - for(i=0;i<151;i++) { - vmwFlipVirtual(game_state->virtual_1,game_state->virtual_2,320,200); - vmwPutSprite(ship1,i*2,100,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - usleep(15000); - if (vmwGetInput()) break; - } - vmwFlipVirtual(game_state->virtual_1,game_state->virtual_2,320,200); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - - vmwDrawBox(0,0,320,200,0,game_state->virtual_1); - vmwLoadPicPacked(0,0,game_state->virtual_1,1,0, /* Restore Palette */ - tb1_data_file("tbomb1.tb1",game_state->path_to_data), - game_state->graph_state); - -} +/* + Level 1 Engine Code for Tom Bombem + * + * November 2000 -- Changed the inner workings of engine. + * Now somewhat different than original feel. + */ + + /* The Includes */ +#include +#include +#include +#include + +#include "svmwgraph/svmwgraph.h" +#include "tb1_state.h" +#include "levels.h" + +#include "sound.h" + +#include "tblib.h" +#include "sidebar.h" +#include "help.h" +#include "loadsave.h" +#include "graphic_tools.h" + + /* Define this to get a frames per second readout */ +/*#define DEBUG_ON */ + + /* The sounds */ + +#define NUM_SAMPLES 8 +#define SND_AHH 0 +#define SND_CC 1 +#define SND_KAPOW 2 +#define SND_SCREAM 3 +#define SND_BONK 4 +#define SND_CLICK 5 +#define SND_OW 6 +#define SND_ZRRP 7 + + +#define NUM_ENEMIES 5 +#define NUM_MISSILES 2 + +struct enemyinfo { + int x,y; + int kind; + int out,exploding,boundarycheck,dead; + int explodeprogress; + int minx,maxx,xspeed,yspeed; + int hitsneeded; +}; + +struct missileinfo { + int out,x,y; +}; + + /* Define how many sound effects there are */ + + + /* Global Variables*/ +struct enemyinfo enemy[NUM_ENEMIES]; +struct missileinfo missile[NUM_MISSILES]; +struct timeval timing_info; +struct timezone dontcare; + +int enemies_out; + +#define LEVEL_OVER 9 + +#define STANDARD 0 +#define DIAGONAL 1 +#define DIAGONAL_NO_WAIT 2 +#define WIGGLING 3 +#define RAINING 4 + +#define SCROLL_A_BIT 7 +#define BEFORE_BOSS 10 +#define BOSS_BEHAVIOR 11 +#define AFTER_BOSS 12 +#define BOSS_DESTROYED 13 +#define INVISIBLE_WAVE 15 +#define THE_END 100 + +typedef struct { + int enemy_type; + int how_many; +}level_one_behavior_t; + + /* This seemed like a good idea to modularize things */ + /* Should make it a file read from disk */ +level_one_behavior_t level_one_wave_behavior[]= + {{STANDARD,5}, + {STANDARD,5}, + {DIAGONAL,5}, + {DIAGONAL_NO_WAIT,5}, + {WIGGLING,8}, + {RAINING,10}, + {WIGGLING,6}, + {RAINING,12}, + {DIAGONAL,5}, + {RAINING,10}, + {WIGGLING,16}, + {DIAGONAL,5}, + {DIAGONAL_NO_WAIT,5}, + {RAINING,3}, + {WIGGLING,10}, + {DIAGONAL,5}, + {SCROLL_A_BIT,100}, + {BEFORE_BOSS,1}, + {SCROLL_A_BIT,100}, + {BOSS_BEHAVIOR,1}, + {BOSS_DESTROYED,100}, + {AFTER_BOSS,1}, + {THE_END,1}}; + + + + /* The little Sequence Before you hit the Boss */ +void beforeboss(tb1_state *game_state) +{ + + vmwClearKeyboardBuffer(); + vmwLoadPicPacked(0,0,game_state->virtual_3,1,1, + tb1_data_file("level1/viewscr.tb1",game_state->path_to_data), + game_state->graph_state); + vmwClearScreen(game_state->virtual_1,0); + vmwArbitraryCrossBlit(game_state->virtual_3,0,5,58,37, + game_state->virtual_1,10,10); + vmwSmallTextXY("HUMAN!",70,10,2,0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwSmallTextXY("WHAT ARE YOU DOING?!",70,20,2, + 0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwSmallTextXY("YOUR SPECIES MUST BE TERMINATED!",70,30,2, + 0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + pauseawhile(5); + + vmwArbitraryCrossBlit(game_state->virtual_3,0,42,58,37, + game_state->virtual_1,10,50); + vmwSmallTextXY("I'M SORRY.",70,50,9,0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwSmallTextXY("WE DIDN'T MEAN TO DESTROY YOUR ENVOY.",70,60,9, + 0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwSmallTextXY("WILL YOU FORGIVE US AND TRY PEACE?",70,70,9, + 0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + pauseawhile(5); + + vmwArbitraryCrossBlit(game_state->virtual_3,0,5,58,37, + game_state->virtual_1,10,90); + vmwSmallTextXY("NO! YOU MUST BE DESTROYED!",70,90,2, + 0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwSmallTextXY("OUR FUNDING ... OUR ENVOY WAS DAMAGED BY",70,100, + 2,0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwSmallTextXY("YOU! VENGEANCE WILL BE OURS! YOUR PUNY",70,110, + 2,0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwSmallTextXY("PRIMITIVE SPACECRAFT WITH ITS INFERIOR",70,120, + 2,0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwSmallTextXY("WEAPONS WOULD HAVE TO SCORE 9 DIRECT HITS",70,130, + 2,0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwSmallTextXY("TO DESTROY MY SHIP! DIE EARTH SCUM!!!!",70,140, + 2,0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + pauseawhile(5); + setupsidebar(game_state,game_state->virtual_2); + vmwFlipVirtual(game_state->virtual_1,game_state->virtual_2,320,200); +} + + /* The Sequence After You Defeat (hopefully) the Boss */ +void afterboss(tb1_state *game_state) +{ + + vmwFont *tb1_font; + + tb1_font=game_state->graph_state->default_font; + + vmwLoadPicPacked(0,0,game_state->virtual_3,1,1, + tb1_data_file("level1/viewscr.tb1",game_state->path_to_data), + game_state->graph_state); + vmwDrawBox(0,0,320,200,0,game_state->virtual_1); + vmwArbitraryCrossBlit(game_state->virtual_3,0,42,58,37, + game_state->virtual_1,10,10); + vmwSmallTextXY("HMM.. THEY DON'T BUILD SUPERIOR",70,10, + 9,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("TECHNOLOGY LIKE THEY USED TO.",70,20, + 9,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("I GUESS I CAN GO HOME NOW.",70,30, + 9,0,1,tb1_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + pauseawhile(5); + + vmwArbitraryCrossBlit(game_state->virtual_3,0,5,58,37, + game_state->virtual_1,10,50); + vmwSmallTextXY("NOT SO FAST! YOU JUST DESTROYED AN ANTIQUATED",70,50, + 2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("DEFENSE SYSTEM THAT WAS PROGRAMMED BY A 16",70,60, + 2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("YEAR OLD! OUR MAIN DEFENSE PROGRAMMER HAS ",70,70, + 2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("MUCH MORE SKILL NOW! UNLESS YOU DESTROY OUR",70,80, + 2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("ENTIRE XENOCIDE... I MEAN PEACE... ENVOY",70,90, + 2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("WE WILL STILL DESTROY YOUR HOME PLANET.",70,100, + 2,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("NICE TRY PUNY EARTHLING!",70,110,2, + 0,1,tb1_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + pauseawhile(7); + + vmwArbitraryCrossBlit(game_state->virtual_3,0,42,58,37, + game_state->virtual_1,10,130); + vmwSmallTextXY("HMM.. I GUESS I BETTER SAVE THE EARTH.",70,130, + 9,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("I'D BETTER SAVE MY GAME TOO.",70,140, + 9,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("D'OH! I''M OUT OF BIG MISSILES! ",70,150, + 9,0,1,tb1_font,game_state->virtual_1); + vmwSmallTextXY("WELL AT LEAST I HAVE SOME SMALLER SPARES.",70,160, + 9,0,1,tb1_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + pauseawhile(5); + game_state->level++; + +} + + + + + /* Defines the behavior of the objects in level 1 */ + /* Should change so it works even if NUM_ENEMIES>5 */ +int add_another_enemy(int start_of_level, + tb1_state *game_state) { + + int what_type,i,need_to_pause=0; + static int wave_pointer=0; + static int wait_full_wave=0; + static int enemies_left_in_wave=0; + static int fighting_boss=0; + + /* If re-initing, then clear some variables */ + /* If we don't do this, the static variables won't get reset */ + /* After Level1 starts over [i.e. you die] */ + if (start_of_level) { + wave_pointer=0; + enemies_out=0; + enemies_left_in_wave=0; + fighting_boss=0; + } + + /* If waiting for empty, then return w/o adding any */ + if ((wait_full_wave) && (enemies_out)) return 0; + else { + wait_full_wave=0; + } + +// if (level_one_wave_behavior[behavior_pointer]!=BOSS_BEHAVIOR) behavior_pointer++; + + /* In order to be called, an enemy was destroyed */ + + /* Are these sanity checks needed? */ + if (enemies_out<0) { + enemies_out=0; + printf("Blargh 0\n"); + } + if (enemies_out>NUM_ENEMIES) { + enemies_out=NUM_ENEMIES; + printf("Blargh 7\n"); + } + + if (enemies_left_in_wave<=0) { + wave_pointer++; + enemies_left_in_wave=level_one_wave_behavior[wave_pointer].how_many; + } + + /* Move on to next behvior */ + + switch(level_one_wave_behavior[wave_pointer].enemy_type) { + + /* STANDARD */ + /* That is, 5 enemies bouncing back/forth, gradually lowering*/ + case STANDARD: + /* We add all 5 at once, so there better not be anything else out */ + if (enemies_out==0) { + enemies_out=5; + enemies_left_in_wave-=5; + wait_full_wave=1; + /* Randomly pick what type they are */ + what_type=(2+rand()%8); + + for(i=0; i<5; i++) { + enemy[i].kind=what_type; + enemy[i].x=i*20; /* Space them in one line */ + enemy[i].y=0; + enemy[i].xspeed=5; + enemy[i].minx=(i*20); /* Make sure they "bounce" */ + enemy[i].maxx=(i*20)+120; /* Properly even when some */ + enemy[i].boundarycheck=1; /* Destroyed */ + enemy[i].yspeed=10; + enemy[i].out=1; + enemy[i].exploding=0; + enemy[i].hitsneeded=1; + enemy[i].dead=0; + } + } + break; + + /* *FALLING STRAIGHT* */ + /* That is, raining down from above */ + case RAINING: + /* Fill up all empty slots? Interesting behavior */ + for(i=0; i<5;i++) { + if ((!enemy[i].out) && ( (rand()%5)==3) ){ + enemies_left_in_wave--; + enemy[i].kind=rand()%8+2; + enemy[i].x=rand()%200+1; + enemy[i].y=0; + enemy[i].xspeed=0; + enemy[i].minx=enemy[i].x; /* Hacky way of making sure they */ + enemy[i].maxx=enemy[i].x; /* Fall vertically */ + enemy[i].boundarycheck=1; + enemy[i].yspeed=5+(wave_pointer/8); /* Fall faster as game */ + /* goes on */ + enemy[i].out=1; + enemy[i].exploding=0; + enemy[i].hitsneeded=1; + enemy[i].dead=0; + enemies_out++; + } + } + break; + + /* *FALLING GRADUALLY SIDEWAYS* */ + /* AKA Wiggling back and forth independently */ + case WIGGLING: + for(i=0;i<5;i++) { + if (!enemy[i].out) { + enemies_left_in_wave--; + enemy[i].kind=rand()%8+2; + enemy[i].y=0; + enemy[i].xspeed=5; + enemy[i].minx=rand()%100; /* Set a random range to "wiggle */ + enemy[i].maxx=rand()%100+120; + enemy[i].x=enemy[i].minx; + enemy[i].boundarycheck=0; + enemy[i].yspeed=1; /* Constantly Fall */ + enemy[i].out=1; + enemy[i].exploding=0; + enemy[i].hitsneeded=1; + enemy[i].dead=0; + enemies_out++; + } + } + break; + + /**ZIG-ZAG**/ + /* That is, fall in a diagonal formation */ + case DIAGONAL: + if (!enemies_out) wait_full_wave=1; + case DIAGONAL_NO_WAIT: + /* Another one of these that we need all to be empty */ + if (!enemies_out) { + enemies_out=5; + enemies_left_in_wave-=5; + what_type=rand()%8+2; + for(i=0;i<5;i++) { + if (!enemy[i].out) { + enemy[i].kind=what_type; + enemy[i].x=i*20; /* Nice diagonal pattern */ + enemy[i].y=i*10; + enemy[i].xspeed=5; + enemy[i].minx=0; + enemy[i].maxx=220; + enemy[i].boundarycheck=0; + enemy[i].yspeed=1; /* Gradually fall */ + enemy[i].out=1; + enemy[i].exploding=0; + enemy[i].hitsneeded=1; + enemy[i].dead=0; + } + } + } + break; + + case SCROLL_A_BIT: + enemies_left_in_wave--; + break; + + case BEFORE_BOSS: + beforeboss(game_state); + enemies_left_in_wave--; + if ((game_state->sound_possible) &&(game_state->music_enabled)) { + loadSound(tb1_data_file("music/boss1.mod",game_state->path_to_data)); + playSound(); + } + + break; + + case BOSS_DESTROYED: + enemies_left_in_wave--; + if ((enemies_left_in_wave>25) && ( !(enemies_left_in_wave%3)) && + (game_state->sound_possible)&&(game_state->sound_enabled)) { + playGameFX(SND_KAPOW); + } + break; + + + case AFTER_BOSS: + stopSound(); + afterboss(game_state); + enemies_left_in_wave--; + break; + + case THE_END: + return LEVEL_OVER; + + /* Beginning of Boss */ + case BOSS_BEHAVIOR: + if ((!enemies_out) && (!fighting_boss)) { + fighting_boss=1; + enemy[0].kind=14; + enemy[1].kind=14; + enemy[2].kind=13; + for(i=0;i<3;i++) { + enemy[i].x=(i*20)+10; + enemy[i].y=0; + enemy[i].xspeed=5; + enemy[i].minx=0; + enemy[i].maxx=220; + enemy[i].boundarycheck=1; + enemy[i].yspeed=0; + enemy[i].out=1; + enemy[i].exploding=0; + enemy[i].hitsneeded=5; + enemy[i].dead=0; + enemies_out++; + } + } break; + default: break; + } + + if (fighting_boss) { + + /* Objects Cast off by the Boss */ + /* Detect if Level One is Over */ + if ((enemy[0].dead) && (enemy[1].dead) && (enemy[2].dead)) { + enemies_left_in_wave--; + fighting_boss=0; + } + else + for(i=3;i<5;i++) { + if ((!enemy[i].out) && (enemy[i-3].out)) { + enemies_out++; + enemy[i].kind=rand()%8+2; + enemy[i].x=enemy[i-3].x; + enemy[i].y=20; + enemy[i].xspeed=0; + enemy[i].minx=enemy[i].x; + enemy[i].maxx=enemy[i].x; + enemy[i].boundarycheck=0; + enemy[i].yspeed=4; + enemy[i].out=1; + enemy[i].exploding=0; + enemy[i].hitsneeded=1; + enemy[i].dead=0; + } + } + } + return need_to_pause; +} + + + + + /* The Main Level One */ +void LevelOneEngine(tb1_state *game_state) { + + int ch=0; + int i,j,grapherror; + char tempst[300]; + int itemp,levelover=0; + int shipx=36,shipadd=0,shipframe=1; + vmwSprite *bigship1,*bigship2,*bigship3; + vmwSprite *shapetable[20]; + long oldusec,time_spent=1; // oldsec; + int howmuchscroll=0; + int game_paused=0; + int done_waiting=0; + + vmwVisual *virtual_1,*virtual_2; + vmwFont *tb1_font; + + /* For convenience */ + tb1_font=game_state->graph_state->default_font; + virtual_1=game_state->virtual_1; + virtual_2=game_state->virtual_2; + + /* Set this up for Save Game */ + game_state->begin_score=game_state->score; + game_state->begin_shields=game_state->shields; + + /* Load Ship Sprites */ + grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1, + tb1_data_file("level1/ships.tb1",game_state->path_to_data), + game_state->graph_state); + if (grapherror) { + return; + } + + bigship1=vmwGetSprite(0,0,48,30,virtual_1); + bigship2=vmwGetSprite(0,32,48,30,virtual_1); + bigship3=vmwGetSprite(0,64,48,30,virtual_1); + + /* Load Inanimate Object Shapes */ + grapherror=vmwLoadPicPacked(0,0,virtual_1,0,1, + tb1_data_file("level1/tbshapes.tb1",game_state->path_to_data), + game_state->graph_state); + + for(j=0;j<2;j++) + for(i=0;i<10;i++) + shapetable[(j*10)+i]=vmwGetSprite(1+(i*19),1+(j*19),18,18,virtual_1); + + /* Set up initial system conditions [ie, no enemies] */ + for(i=0;igraph_state, virtual_1); + + + /* Setup and draw the sidebar */ + setupsidebar(game_state,virtual_2); + + vmwFlipVirtual(virtual_1,virtual_2,320,200); + sprintf(tempst,"%d",game_state->level); +// vmwDrawBox(251,52,62,7,0,virtual_1); + vmwTextXY(tempst,307,51,12,0,0,tb1_font,virtual_1); + + /* Clear the screen and draw the stars */ + vmwDrawBox(0,0,320,400,0,virtual_2); + for(i=0;i<100;i++) { + vmwPutSprite(shapetable[11],rand()%238,rand()%380,virtual_2); + vmwPutSprite(shapetable[12],rand()%238,rand()%380,virtual_2); + } + /* Initialize shield state */ + change_shields(game_state); + + /* Initiate some last variables */ + add_another_enemy(1,game_state); + pauseawhile(5); + + /* Get time values for frame-limiting */ + gettimeofday(&timing_info,&dontcare); + //oldsec=timing_info.tv_sec; + oldusec=timing_info.tv_usec; + + /* MAIN GAME LOOP */ + while(!levelover) { + ch=0; + /* Scroll the Stars */ + /* We have a 240x400 field of stars */ + howmuchscroll--; + if (howmuchscroll<0) howmuchscroll=399; + + /* If scroll>199, then we have to split into two copies */ + /* One from scroll to 400 */ + /* Another from 0-(scroll-200) */ + if (howmuchscroll>199) { + vmwArbitraryCrossBlit(virtual_2,0,howmuchscroll,240, + 400-howmuchscroll, + virtual_1,0,0); + vmwArbitraryCrossBlit(virtual_2,0,0,240,howmuchscroll-200, + virtual_1,0,400-howmuchscroll); + } + else { + vmwArbitraryCrossBlit(virtual_2,0,howmuchscroll,240,200, + virtual_1,0,0); + } + + /* Add new enemies and move to next wave if needed */ + if (enemies_outlevel=2; + levelover=1; + return; + } + } + + /* See if the enemies have hit anything/scrolled off screen */ + for(i=0;isound_possible)&&(game_state->sound_enabled)) + playGameFX(SND_KAPOW); + enemy[i].hitsneeded--; + if (enemy[i].hitsneeded<1) enemy[i].dead=1; + else enemy[i].dead=0; + enemy[i].exploding=1; + enemy[i].explodeprogress=0; + missile[itemp].out=0; + game_state->score+=10; + changescore(game_state); + } + } + } + + /* While we are at it, see if scrolled off screen */ + if (enemy[i].y>179) { + enemy[i].out=0; + enemy[i].dead=1; + enemies_out--; + } + } + } + + /* Explode the things that are exploding */ + for(i=0;i1 */ + enemy[i].out=0; + enemy[i].exploding=0; + enemies_out--; + } + else enemy[i].exploding=0; + } + } + + /* Move the Missiles */ + for(i=0;i=enemy[i].maxx)) { + enemy[i].xspeed=-enemy[i].xspeed; + enemy[i].x+=enemy[i].xspeed; + enemy[i].y+=enemy[i].yspeed; + } + + /* See if colliding with spaceship */ + if (enemy[i].y>140) { + if (collision(shipx,165,24,15,enemy[i].x,enemy[i].y,9,9)) { + if ((game_state->sound_possible)&&(game_state->sound_enabled)) + playGameFX(SND_BONK); + enemy[i].hitsneeded--; + if (enemy[i].hitsneeded==0) enemy[i].dead=1; + else enemy[i].dead=0; + enemy[i].exploding=1; + enemy[i].explodeprogress=0; + game_state->shields--; + if (game_state->shields<0) levelover=1; + if (game_state->shields>0) change_shields(game_state); + } + } + } + } + + /* **READ KEYBOARD** */ + if ( (ch=vmwGetInput())!=0) { + switch(ch){ + case VMW_ESCAPE: levelover=1; break; + case VMW_RIGHT: if (shipadd>=0) shipadd+=3; else shipadd=0; break; + case VMW_LEFT: if (shipadd<=0) shipadd-=3; else shipadd=0; break; + case VMW_F1: game_paused=1; help(game_state); break; + case 'P': case 'p': game_paused=1; + coolbox(65,85,175,110,1,virtual_1); + vmwTextXY("GAME PAUSED",79,95,4,7, + 0,tb1_font,virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + while (vmwGetInput()==0) { + usleep(30000); + } + break; + case 'S': + case 's': if (game_state->sound_possible) { + game_state->sound_enabled=!(game_state->sound_enabled); + } + break; + case VMW_F2: game_paused=1; + savegame(game_state); + break; + case ' ': for(j=0;j<2;j++) + if (!missile[j].out) { + if ((game_state->sound_possible)&&(game_state->sound_enabled)) + playGameFX(SND_CC); + missile[j].out=1; + missile[j].x=shipx+15; + missile[j].y=165; + vmwPutSprite(shapetable[0], + missile[j].x, + missile[j].y,virtual_1); + j=3; + } + } + } + + /* **MOVE SHIP** */ + shipx+=shipadd; + if (shipx<1) shipx=1; + if (shipx>190) shipx=190; + switch(shipframe) { + + case 1: vmwPutSprite(bigship1,shipx,165,virtual_1); + break; + case 3: vmwPutSprite(bigship2,shipx,165,virtual_1); + break; + case 2: + case 4: vmwPutSprite(bigship3,shipx,165,virtual_1); + break; + } + shipframe++; + if (shipframe==5) shipframe=1; + + /* Flip Pages */ +#ifdef DEBUG_ON + sprintf(tempst,"%li",1000000/time_spent); + vmwTextXY(tempst,10,10,4,7,0,tb1_font,virtual_1); +#endif + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + + /* If time passed was too little, wait a bit */ + /* 33,333 would frame rate to 30Hz */ + /* Linux with 100Hz scheduling only gives +- 10000 accuracy */ + done_waiting=0; + while (!done_waiting){ + + gettimeofday(&timing_info,&dontcare); + time_spent=timing_info.tv_usec-oldusec; + /* Assume we don't lag more than a second */ + /* Seriously, if we lag more than 10ms we are screwed anyway */ + if (time_spent<0) time_spent+=1000000; + if (time_spent<30000) usleep(100); + else (done_waiting=1); + } + oldusec=timing_info.tv_usec; + //oldsec=timing_info.tv_sec; + + /* If game is paused, don't keep track of time */ + if (game_paused) { + gettimeofday(&timing_info,&dontcare); + oldusec=timing_info.tv_usec; + //oldsec=timing_info.tv_sec; + game_paused=0; + } + } +} + + /* The little opener before Level 1 */ +void LevelOneLittleOpener(tb1_state *game_state) { + + vmwSprite *ship1,*ship2; + int i; + + vmwClearScreen(game_state->virtual_2,0); + + vmwLoadPicPacked(0,0,game_state->virtual_2,1,1, + tb1_data_file("level1/moon2.tb1",game_state->path_to_data), + game_state->graph_state); +// vmwLoadPicPacked(0,0,game_state->virtual_1,1,0, /* Load palette */ +// tb1_data_file("level1/moon2.tb1",game_state->path_to_data)); + + ship1=vmwGetSprite(9,178,15,18,game_state->virtual_2); + ship2=vmwGetSprite(30,178,15,18,game_state->virtual_2); + vmwDrawBox(0,178,319,21,0,game_state->virtual_2); + + for(i=100;i>0;i--) { + vmwFlipVirtual(game_state->virtual_1,game_state->virtual_2,320,200); + vmwPutSprite(ship2,i*2,100,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + usleep(30000); + if (vmwGetInput()) break; + } + vmwFlipVirtual(game_state->virtual_1,game_state->virtual_2,320,200); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + + vmwTextXY(">KCHK< TOM! WHERE ARE YOU GOING?",5,180,15,0,1, + game_state->graph_state->default_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + pauseawhile(3); + vmwDrawBox(0,178,319,21,0,game_state->virtual_1); + vmwTextXY("Ooops. ",5,180,24,0,1,game_state->graph_state->default_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + pauseawhile(3); + for(i=0;i<151;i++) { + vmwFlipVirtual(game_state->virtual_1,game_state->virtual_2,320,200); + vmwPutSprite(ship1,i*2,100,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + usleep(15000); + if (vmwGetInput()) break; + } + vmwFlipVirtual(game_state->virtual_1,game_state->virtual_2,320,200); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + + vmwDrawBox(0,0,320,200,0,game_state->virtual_1); + vmwLoadPicPacked(0,0,game_state->virtual_1,1,0, /* Restore Palette */ + tb1_data_file("tbomb1.tb1",game_state->path_to_data), + game_state->graph_state); + +} diff --git a/tb1_linux/level_3.c b/tb1_linux/level_3.c index 14cecea..b5e1815 100644 --- a/tb1_linux/level_3.c +++ b/tb1_linux/level_3.c @@ -1,908 +1,907 @@ -#include -#include /* For rand() */ -#include -#include -#include - -#include "./svmwgraph/svmwgraph.h" -#include "tb1_state.h" - -#include "help.h" -#include "loadsave.h" -#include "graphic_tools.h" -#include "tblib.h" - -#define NORTH 0 -#define SOUTH 1 -#define EAST 2 -#define WEST 3 - -#define TOM_SHAPE 60 - -vmwSprite *shape_table[80]; - - -void loadlevel3shapes(tb1_state *game_state) { - - - int i,j; - - vmwLoadPicPacked(0,0,game_state->virtual_2,0,1, - tb1_data_file("level3/tblev3.tb1", - game_state->path_to_data), - game_state->graph_state); - - for(j=0;j<5;j++) { - for(i=0;i<20;i++) { - shape_table[(j*20)+i]=vmwGetSprite(1+(i*11),1+(j*11), - 10,10,game_state->virtual_2); - } - } -} - -int our_sgn(int value) { - - if (value==0) return 0; - if (value<0) return -1; - return 1; -} - - - -/* -Procedure levelthree; -label newroom; -type{ -EnemyInfo = record - x,y:integer; - kind:byte; - out,exploding,boundarycheck,dead:boolean; - explodprogress:byte; - minx,maxx,xspeed,yspeed:integer; - hitsneeded:integer; - end;} -pittype = record - px,py:integer; - end; -kctype = record - kcx,kcy:integer; - kcout:boolean; - end; - -const framedir:array[0..1,0..3] of integer =((0,1,0,-1),(1,0,-1,0)); -VAR loop1,loop2:integer; - ch,ch2:char; - pits:array[0..4] of pittype; - numpits:byte; - - bullet1x,bullet1y,bullet2x,bullet2y,i:integer; - bullet1dir,bullet2dir,collide:byte; - bullet1out,bullet2out:boolean; - whichone,temp,temp2:integer; - tempst:string; - what:byte; - k:integer; - itemp,jtemp:byte; - whatdelay:byte; - tempilg:byte; - xx:integer; - ucollide,dcollide,lcollide,rcollide:word; - walking,feet:byte; - room:byte; - backrow,topblocky:integer; - levelover,odd,changeroom,havegun:boolean; - whichroomnext:array[0..3] of byte; {n,s,e,w} - keycards:array[0..3] of boolean; - keycard:kctype; - shieldup:array[0..11] of boolean; - shieldx,shieldy,laserx,lasery:integer; - laserup:array[0..11] of boolean; - computers:array[0..11] of boolean; - computerx,computery:integer; - computer_0hits:integer; - tempkc:byte; - -procedure horizwalls(x,y,howfar:word); -var i:word; -begin - for i:=0 to howfar do - put10shape240(shape3array[3],vaddr2,x+(i*10),y); -end; - -procedure verticalwalls(x,y,howfar:word); -var i:word; -begin - for i:=0 to howfar do - put10shape240(shape3array[2],vaddr2,x,y+(i*10)); -end; - -procedure dopits; -var i:word; -begin - for i:=0 to (numpits-1) do - with pits[i] do - put10shape240(shape3array[5],vaddr2,px,py); -end; - -procedure clearroom; -var i,j:byte; -begin - for i:=0 to 23 do - for j:=0 to 19 do - put10shape240(shape3array[0], - vaddr2,i*10,j*10); -end; - - -procedure doroom(n,s,e,w:boolean); -var i:byte; -begin - for i:=0 to 2 do begin - put10shape240(shape3array[18],vaddr2,100+(i*10),0); - put10shape240(shape3array[18],vaddr2,100+(i*10),199); - put10shape240(shape3array[19],vaddr2,0,90+(i*10)); - put10shape240(shape3array[19],vaddr2,239,90+(i*10)); - end; - - if n then begin - horizwalls(0,0,10); - horizwalls(130,0,10); - end - else horizwalls(0,0,23); - if s then begin - horizwalls(0,197,10); - horizwalls(130,197,10); - end - else horizwalls(0,197,23); - - if e then begin - verticalwalls(237,0,8); - verticalwalls(237,110,8); - end - - else for i:=0 to 20 do put10shape240(shape3array[2],vaddr2,237,i*10); - if w then begin - verticalwalls(0,0,8); - verticalwalls(0,110,8); - end - else for i:=0 to 20 do put10shape240(shape3array[2],vaddr2,0,i*10); - -end; -*/ - -void LevelThreeEngine(tb1_state *game_state) { - - int level_over=0; - int ch,direction=NORTH; - int x_add=0,y_add=0; - int game_paused=0; - - int tom_x=100,tom_y=100,walking=0; - - - vmwVisual *virtual_1,*virtual_2; - vmwFont *tb1_font; - - long oldsec,oldusec,time_spent; - - struct timeval timing_info; - struct timezone dontcare; - int speed_factor=0; - - - virtual_1=game_state->virtual_1; - virtual_2=game_state->virtual_2; - tb1_font=game_state->graph_state->default_font; - - loadlevel3shapes(game_state); -/* computer_0hits:=0; - whatdelay:=1; - havegun:=true; - for i:=0 to 3 do keycards[i]:=false; - for i:=0 to 11 do begin - shieldup[i]:=false; - laserup[i]:=false; - computers[i]:=false; - end; - shieldup[0]:=true; - laserup[0]:=true; - computers[0]:=true; - - shipx:=115; - shipy:=180; - odd:=false; - shipxadd:=0; - room:=0; - shipyadd:=0; - - shipframe:=1; - shipspeed:=5; - - ch:=#1; ch2:=#1; - bullet1out:=false; bullet2out:=false; - bullet1x:=0; bullet1y:=0; - bullet2x:=0; bullet2y:=0; - - flip(vaddr2,vaddr); - str(level,tempst); - fillblock(251,52,314,59,0,vaddr); - vmwTextXY(tempst,307,51,12,0,vaddr,false); - - cls(0,vaddr2); - - pal(250,0,0,63); - pal(251,63,0,0); - - pal(254,shields*4,0,0); - howmuchscroll:=50; - - cls(0,vga); - coolbox(70,85,240,120,true,vga); - vmwTextXY(' LEVEL THREE:',84,95,4,7,vga,false); - vmwTextXY(' THE ALIEN SHIP',84,105,4,7,vga,false); - - clearkeyboardbuffer; - pauseawhile(300); - numpassive:=0; - levelover:=false; - -newroom: - numpits:=0; - changeroom:=false; - if room=254 then room:=0; - clearroom; - if shipframe=1 then shipy:=188 - else if shipframe=3 then shipy:=3 - else if shipframe=2 then shipx:=3 - else if shipframe=4 then shipx:=228; - keycard.kcout:=false; - - - if room=0 then begin - whichroomnext[0]:=1; - whichroomnext[1]:=255; - clearroom; - verticalwalls(30,0,16); - verticalwalls(207,0,16); - verticalwalls(57,30,16); - verticalwalls(180,30,16); - with pits[0] do begin - px:=95; - py:=80; - end; - with pits[1] do begin - px:=135; - py:=80; - end; - numpits:=2; { actual} - dopits; - - for i:=0 to 10 do - for j:=0 to 2 do begin - put10shape240(shape3array[4],vaddr2,60+(j*10),80+(i*10)); - put10shape240(shape3array[4],vaddr2,150+(j*10),80+(i*10)); - end; -{walkway} - for i:=0 to 15 do for j:=0 to 1 do - put10shape240(shape3array[1],vaddr2,110+(j*10),40+(i*10)); - - put10shape240(shape3array[6],vaddr2,110,30); - put10shape240(shape3array[6],vaddr2,120,30); - computerx:=110; - computery:=30; - - if shieldup[0] then begin - shieldx:=10; - shieldy:=10; - put10shape240(shape3array[8],vaddr2,10,10); - end; - - if laserup[0] then begin - laserx:=220; - lasery:=10; - put10shape240(shape3array[7],vaddr2,220,10); - end; - - {badguys} - {put10shape240(shape3array[32],vaddr2,40,180); - put10shape240(shape3array[32],vaddr2,190,180);} - - - doroom(true,true,false,false); - - - end; - if room=1 then begin - whichroomnext[0]:=2; - whichroomnext[1]:=0; - doroom(true,true,false,false); - end; - if room=2 then begin - whichroomnext[1]:=1; - whichroomnext[2]:=6; - whichroomnext[3]:=4; - with pits[0] do begin - px:=95; - py:=80; - end; - with pits[1] do begin - px:=135; - py:=80; - end; - numpits:=2; - dopits; - - doroom(false,true,true,true); - end; - if room=3 then begin - whichroomnext[0]:=4; - if not(keycards[3]) then - begin - keycard.kcout:=true; - keycard.kcx:=100; - keycard.kcy:=100; - put10shape240(shape3array[12],vaddr2,100,100); - end; - doroom(true,false,false,false); - end; - if room=4 then begin - whichroomnext[0]:=7; - whichroomnext[1]:=3; - whichroomnext[2]:=2; - doroom(true,true,true,false); - end; - if room=5 then begin - whichroomnext[0]:=6; - doroom(true,false,false,false); - if not(keycards[2]) then begin - keycard.kcout:=true; - keycard.kcx:=100; - keycard.kcy:=100; - put10shape240(shape3array[11],vaddr2,100,100); - end; - end; - if room=6 then begin - whichroomnext[0]:=11; - whichroomnext[1]:=5; - whichroomnext[3]:=2; - doroom(true,true,false,true); - end; - if room=7 then begin - whichroomnext[0]:=8; - whichroomnext[1]:=4; - doroom(true,true,false,false); - end; - if room=8 then begin - whichroomnext[1]:=7; - whichroomnext[2]:=9; - if not(keycards[0]) then begin - keycard.kcout:=true; - keycard.kcx:=100; - keycard.kcy:=100; - put10shape240(shape3array[9],vaddr2,100,100); - end; - doroom(false,true,true,false); - end; - if room=9 then begin - whichroomnext[2]:=10; - whichroomnext[3]:=8; - doroom(false,false,true,true); - end; - if room=10 then begin - whichroomnext[1]:=11; - whichroomnext[3]:=9; - if not(keycards[1]) then begin - keycard.kcout:=true; - keycard.kcx:=100; - keycard.kcy:=100; - put10shape240(shape3array[10],vaddr2,100,100); - end; - doroom(false,true,false,true); - end; - if room=11 then begin - whichroomnext[0]:=10; - whichroomnext[1]:=6; - doroom(true,true,false,false); - end; - if room=255 then begin - if keycards[0] and keycards[1] and - keycards[2] and keycards[3] then - begin - levelover:=true; - cls(0,vga); - vmwTextXY('You Have won!',5,5,9,7,vga,false); - vmwTextXY('But as you can see this level is not done yet.',5,15,9,7,vga,false); - {vmwTextXY('Anyway');} - readln; - inc(level); - end - else begin - cls(0,vga); - vmwTextXY('You Cannot Leave Yet',5,5,9,7,vga,true); - repeat until keypressed; tempch:=readkey; - levelover:=false; - shipframe:=1; - room:=254; - end; - end; - if (room=254) and not(levelover) then goto newroom; - -*/ - - gettimeofday(&timing_info,&dontcare); - oldsec=timing_info.tv_sec; oldusec=timing_info.tv_usec; - - -/**** GAME LOOP ****/ -/*******************/ - - while (!level_over) { - - - /***Collision Check***/ -/* if numpits>0 then - for i:=0 to (numpits-1) do with pits[i] do - if collision(shipx,shipy,5,4,px,py,4,4) - then begin - levelover:=true; - cls(0,vga); - grapherror:=loadpicsuperpacked(0,0,vga,false,true,'tbpit.tb1'); - - - {vmwTextXY('You Fell In A Pit!',5,5,9,2,vga,false);} - clearkeyboardbuffer; - repeat until keypressed; tempch:=readkey; - end; - if keycard.kcout then - if collision(shipx,shipy,5,4,keycard.kcx,keycard.kcy,5,5) - then begin - keycard.kcout:=false; - case room of - 3: keycards[3]:=true; - 5: keycards[2]:=true; - 8: keycards[0]:=true; - 10:keycards[1]:=true; - end; - put10shape240(shape3array[0],vaddr2,keycard.kcx,keycard.kcy); - end; - if shieldup[room] then - if collision(shipx,shipy,5,4,shieldx,shieldy,5,5) - then begin - shieldup[room]:=false; - put10shape240(shape3array[0],vaddr2,shieldx,shieldy); - inc(shields); - pal(254,shields*4,0,0); - for itemp:=0 to shields do - for jtemp:=71 to 78 do - horizontalline(250+(itemp*4), - 254+(itemp*4),jtemp, - 47-itemp,vaddr); - end; - if laserup[room] then - if collision(shipx,shipy,5,4,laserx,lasery,5,5) - then begin - laserup[room]:=false; - put10shape240(shape3array[0],vaddr2,laserx,lasery); - end; - if computers[room] then - if collision(shipx,shipy,5,4,computerx,computery,10,5) - then begin - cls(0,vga); - grapherror:=loadpicsuperpacked(0,0,vga,false,true,'tbconsol.tb1'); - tempkc:=0; - if keycards[0] then begin - inc(tempkc); - putpixel(147,132,0,vga); - end; - if keycards[1] then begin - inc(tempkc); - putpixel(179,132,0,vga); - end; - if keycards[2] then begin - inc(tempkc); - putpixel(179,160,0,vga); - end; - if keycards[3] then begin - inc(tempkc); - putpixel(147,160,0,vga); - end; - - case room of - 0: begin - inc(computer_0hits); - if computer_0hits=1 then begin - - vmwTextXY('COMPUTER ACTIVATED:',47,30,2,0,vga,true); - vmwSmallTextXY(' HUMAN YOU HAVE COME TOO SOON. LEVELS 3',47,40,2,0,vga,true); - vmwSmallTextXY(' AND 4 ARE INCOMPLETE.',47,48,2,0,vga,true); - vmwSmallTextXY(' ANYWAY I CAN SEE YOU ARE NOT THE',47,58,2,0,vga,true); - vmwSmallTextXY(' TENTACLEE COMMANDER. YOU ARE IN',47,66,2,0,vga,true); - vmwSmallTextXY(' GRAVE DANGER. LUCKILY THE MAIN',47,74,2,0,vga,true); - vmwSmallTextXY(' COMPUTER SYSTEM DOES NOT APPROVE',47,82,2,0,vga,true); - vmwSmallTextXY(' OF THE TENTACLEE'S POLICIES.',47,90,2,0,vga,true); - vmwSmallTextXY(' I PERSONALLY CANNOT SHUT OFF THE TRACTOR',47,100,2,0,vga,true); - vmwSmallTextXY(' BEAM. YOU MUST RETRIEVE FOUR KEYCARDS',47,108,2,0,vga,true); - vmwSmallTextXY(' SCATTERED AROUND THE FLIGHT DECK.',47,116,2,0,vga,true); - vmwSmallTextXY(' THE MAP BELOW WILL AID YOU.',47,124,2,0,vga,true); - end; - if computer_0hits=2 then begin - - vmwTextXY('COMPUTER ACTIVATED:',47,30,2,0,vga,true); - vmwSmallTextXY(' HUMAN I HAVE ALREADY TOLD YOU MUCH.',47,40,2,0,vga,true); - vmwSmallTextXY(' COLLECT THE 4 KEYCARDS, MADE OF',47,48,2,0,vga,true); - vmwSmallTextXY(' RUBY, GOLD, EMERALD, AND ALUMINUM.',47,56,2,0,vga,true); - vmwSmallTextXY(' WATCH OUT FOR ENEMIES NOT UNDER MY',47,66,2,0,vga,true); - vmwSmallTextXY(' CONTROL, RADIOACTIVE FLOORS, AND',47,74,2,0,vga,true); - vmwSmallTextXY(' EXTREMELY DEEP PITS.',47,82,2,0,vga,true); - end; - if computer_0hits>2 then begin - vmwTextXY('COMPUTER ACTIVATED:',47,30,2,0,vga,true); - vmwSmallTextXY(' HUMAN, GO AWAY. YOU ANNOY ME.',47,40,2,0,vga,true); - vmwSmallTextXY(' I HAVE TOLD YOU EVERYTHING.',47,48,2,0,vga,true); - end; - - - - end; - end; - clearkeyboardbuffer; - repeat until keypressed; tempch:=readkey; - shipx:=shipx+(4*framedir[1,shipframe]); - shipy:=shipy+(4*framedir[0,shipframe]); - end; -*/ - - /***DO EXPLOSIONS***/ -/*{ for i:=0 to 30 do - if passive[i].exploding then with passive[i] do begin - inc(explodeprogress); - vmwPutSprite240(shape2array[35+explodeprogress],vaddr2, - 20,9,x,y+howmuchscroll); - if explodeprogress>4 then begin - dead:=true; - exploding:=false; - vmwPutSprite240over(14800(*shape2array[34]*),vaddr2, - 20,9,x,y+howmuchscroll); - end; - end; -*/ - - /***MOVE BULLETS***/ -/* if bullet1out then begin - case bullet1dir of - 1:begin dec(bullet1y,5); - collide:=upcollide(bullet1x,bullet1y,5,-5,3,vaddr2); - end; - 2:begin inc(bullet1x,5); - collide:=leftcollide(bullet1x,bullet1y,5,10,3,vaddr2); - end; - 3:begin inc(bullet1y,5); - collide:=upcollide(bullet1x,bullet1y,5,10,3,vaddr2); - end; - 4:begin dec(bullet1x,5); - collide:=leftcollide(bullet1x,bullet1y,5,-5,3,vaddr2); - end; - end; - - if collide<>0 then bullet1out:=false; - if bullet1out then vmwPutSprite(shape3array[76],vaddr,10,9,bullet1x,bullet1y); - end; - if bullet2out then begin - dec(bullet2y,5); - if bullet2y<5 then bullet2out:=false; - if bullet2out then vmwPutSprite(shape3array[76],vaddr,10,9,bullet2x,bullet2y); - end; - */ - /***MOVE ENEMIES***/ -/* { for j:=0 to 30 do begin - if passive[j].dead=false then begin - inc(passive[j].y); - if(passive[j].y)>190 then passive[j].dead:=true; - end; - end; - for j:=0 to 30 do begin - if passive[j].lastshot>0 then dec(passive[j].lastshot); - if (passive[j].dead=false) and (passive[j].shooting) - and (passive[j].lastshot=0) and (passive[j].y>0) - then begin - tempilg:=7; - for i:=0 to 5 do if enemy[i].out=false then tempilg:=i; - if tempilg<>7 then begin - passive[j].lastshot:=30; - enemy[tempilg].out:=true; - enemy[tempilg].y:=passive[j].y; - enemy[tempilg].x:=passive[j].x+5; - enemy[tempilg].yspeed:=5; - enemy[tempilg].kind:=25; - if passive[j].kind=11 then enemy[tempilg].kind:=26; - end; - end; - end; - for j:=0 to 5 do begin - if enemy[j].out then begin - vmwPutSprite(shape2array[enemy[j].kind],vaddr, - 20,9,enemy[j].x,enemy[j].y); - enemy[j].y:=enemy[j].y+enemy[j].yspeed; - if enemy[j].y>189 then enemy[j].out:=false; - end; - end; - } -*/ - - /***READ KEYBOARD***/ - if ( (ch=vmwGetInput())!=0) { - switch(ch){ - case VMW_ESCAPE: level_over=1; - break; - case VMW_RIGHT: if (direction==EAST) x_add=2; - else direction=EAST; - break; - /* - if (shipframe=2) and (shipxadd=0) then shipxadd:=2 - else if (shipframe<>2) then shipframe:=2 - else inc(shipxadd); - */ - case VMW_LEFT: if (direction==WEST) x_add=-2; - else direction=WEST; - break; - case VMW_UP: if (direction==NORTH) y_add=-2; - else direction=NORTH; - break; - case VMW_DOWN: if (direction==SOUTH) y_add=2; - else direction=SOUTH; - break; - case VMW_F1: game_paused=1; - help(game_state); - break; - - case 'P': - case 'p': game_paused=1; - coolbox(65,85,175,110,1,virtual_1); - vmwTextXY("GAME PAUSED",79,95,4,7,0, - game_state->graph_state->default_font, - virtual_1); - vmwClearKeyboardBuffer(); - vmwBlitMemToDisplay(game_state->graph_state, - virtual_1); - while (vmwGetInput()==0) usleep(30000); - break; - case 'S': - case 's': if (game_state->sound_possible) - game_state->sound_enabled=!(game_state->sound_enabled); - break; - - case VMW_F2: game_paused=1; - savegame(game_state); - break; - case ' ': /* shoot */ - break; - /* - - if (ch=' ') and havegun then begin - if (bullet1out=false) then begin - {if sbeffects then StartSound(Sound[4], 0, false);} - bullet1out:=true; - bullet1x:=shipx+3; - bullet1y:=shipy+4; - bullet1dir:=shipframe; - vmwPutSprite(shape3array[76],vaddr,10,9,bullet1x,bullet1y); - end - else - if (bullet2out=false) then begin - {if sbeffects then StartSound(Sound[4], 0, false);} - bullet2out:=true; - bullet2x:=shipx; - bullet2y:=shipy; - bullet2dir:=shipframe; - vmwPutSprite(shape3array[76],vaddr,10,9,bullet2x,bullet2y); - end; - end; -*/ - } - } - - /***MOVE TOM***/ - - - /* ucollide:=upcollide(shipx,shipy,abs(shipyadd),-abs(shipyadd),10,vaddr2); - dcollide:=upcollide(shipx,shipy,abs(shipyadd),8,10,vaddr2); - lcollide:=leftcollide(shipx,shipy,abs(shipxadd),-abs(shipxadd),8,vaddr2); - rcollide:=leftcollide(shipx,shipy,abs(shipxadd),0,8,vaddr2);*/ - - /* if (shipframe=1) and (ucollide<>0) then shipyadd:=0; - if (shipframe=3) and (dcollide<>0) then shipyadd:=0; - if (shipframe=2) and (rcollide<>0) then shipxadd:=0; - if (shipframe=4) and (lcollide<>0) then shipxadd:=0; - */ - tom_x+=x_add; - tom_y+=y_add; - y_add-=our_sgn(y_add); - x_add-=our_sgn(x_add); - /* - - case ucollide of - 5: begin - changeroom:=true; - room:=whichroomnext[0]; - end; - end; - case dcollide of - 5: begin - changeroom:=true; - room:=whichroomnext[1]; - end; - end; - case rcollide of - 5: begin - changeroom:=true; - room:=whichroomnext[2]; - end; - end; - case lcollide of - 5: begin - changeroom:=true; - room:=whichroomnext[3]; - end; - end; - */ - - if ((!y_add) || (!x_add)) walking+=4; - else walking=0; - - if (walking>12) walking=0; - - switch(direction) { - case NORTH: vmwPutSprite(shape_table[TOM_SHAPE+walking],tom_x,tom_y,game_state->virtual_1); - break; - case EAST: vmwPutSprite (shape_table[TOM_SHAPE+1+walking],tom_x,tom_y,game_state->virtual_1); - break; - case SOUTH: vmwPutSprite (shape_table[TOM_SHAPE+2+walking],tom_x,tom_y,game_state->virtual_1); - break; - case WEST: vmwPutSprite (shape_table[TOM_SHAPE+3+walking],tom_x,tom_y,game_state->virtual_1); - } - - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - - - /* Calculate how much time has passed */ - gettimeofday(&timing_info,&dontcare); - time_spent=timing_info.tv_usec-oldusec; - if (timing_info.tv_sec-oldsec) time_spent+=1000000; -#ifdef DEBUG_ON - printf("%f\n",1000000/(float)time_spent); -#endif - - /* If time passed was too little, wait a bit */ - while (time_spent<33000){ - gettimeofday(&timing_info,&dontcare); - usleep(5); - time_spent=timing_info.tv_usec-oldusec; - if (timing_info.tv_sec-oldsec) time_spent+=1000000; - } - - /* It game is paused, don't keep track of time */ - if (game_paused) { - gettimeofday(&timing_info,&dontcare); - oldusec=timing_info.tv_usec; - oldsec=timing_info.tv_sec; - game_paused=0; - speed_factor=1; - } - else { - speed_factor=(time_spent/30000); - oldusec=timing_info.tv_usec; - oldsec=timing_info.tv_sec; - } - - } -} - - - -void LevelThreeLittleOpener(tb1_state *game_state) { - - int grapherror,i,j; - - vmwFont *tb1_font; - vmwVisual *virtual_1,*virtual_2; - - int star_x[6]; - int star_y[6]; - - tb1_font=game_state->graph_state->default_font; - virtual_1=game_state->virtual_1; - virtual_2=game_state->virtual_2; - - loadlevel3shapes(game_state); - - vmwClearScreen(game_state->virtual_1,0); - grapherror=vmwLoadPicPacked(0,0,virtual_2, - 1,1,tb1_data_file("level3/tbl3intr.tb1", - game_state->path_to_data),game_state->graph_state); - vmwArbitraryCrossBlit(game_state->virtual_2,0,3,171,114, - game_state->virtual_1,10,10); - - - - vmwPutSprite(shape_table[TOM_SHAPE],113,52,game_state->virtual_1); - - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - - vmwTextXY("Hmmmm... STUPID TRACTOR BEAM.",10,155,10,0,0,tb1_font,virtual_1); - vmwTextXY("I GUESS I'D BETTER GO SHUT IT OFF.",10,165,10,0,0,tb1_font,virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - - pauseawhile(8); - vmwClearKeyboardBuffer(); - - for(i=24;i>=0;i--) { - vmwArbitraryCrossBlit(game_state->virtual_2,0,3,171,114, - game_state->virtual_1,10,10); - vmwPutSprite(shape_table[TOM_SHAPE+(4*(i% 4))],113,28+i,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - usleep(50000); - } - vmwPutSprite (shape_table[TOM_SHAPE],113,28,game_state->virtual_1); - vmwDrawBox(10,155,290,30,0,game_state->virtual_1); - vmwTextXY("I'M LUCKY I WORE MAGNETIC SHOES.",10,155,12,0,0,tb1_font,game_state->virtual_1); - vmwTextXY("Hmmmm. SOMEONE LEFT THE AIR-LOCK",10,165,12,0,0,tb1_font,game_state->virtual_1); - vmwTextXY(" UNLOCKED. STRANGE.",10,175,12,0,0,tb1_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - pauseawhile(8); - vmwClearKeyboardBuffer(); - - vmwPutPixel(110,20,10,game_state->virtual_1); - vmwPutPixel(110,22,10,game_state->virtual_1); - vmwDrawBox(111,14,12,14,0,game_state->virtual_1); - vmwDrawBox(10,155,290,30,0,game_state->virtual_1); - vmwTextXY("I HOPE THIS ISN'T A TRAP.",10,155,9,0,0,tb1_font,game_state->virtual_1); - vmwTextXY("I WISH I HAD SOME FORM OF ",10,165,9,0,0,tb1_font,game_state->virtual_1); - vmwTextXY(" WEAPON.",10,175,9,0,0,tb1_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - pauseawhile(7); - vmwClearKeyboardBuffer(); - - vmwClearScreen(game_state->virtual_1,0); - - vmwArbitraryCrossBlit(game_state->virtual_2,179,41,108,93, - game_state->virtual_1,10,10); - - for(i=0;i<6;i++) { - star_x[i]=37+rand()%70; - star_y[i]=18+rand()%56; - vmwPutPixel(star_x[i],star_y[i],15,game_state->virtual_1); - } - - vmwTextXY("WOW!! A GLASS-WALLED AIR-LOCK.",10,135,9,0,0,tb1_font,game_state->virtual_1); - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - pauseawhile(5); - vmwClearKeyboardBuffer(); - - vmwDrawBox(10,135,290,50,0,game_state->virtual_1); - vmwTextXY("NOW WHERE ARE WE GOING?",5,125,9,0,0,tb1_font,game_state->virtual_1); - vmwTextXY("I GUESS THE PLANET EERM.",5,135,9,0,0,tb1_font,game_state->virtual_1); - vmwTextXY("WHAT AN ODD NAME.",5,145,9,0,0,tb1_font,game_state->virtual_1); - vmwTextXY("AND WHY AM I TALKING TO MYSELF?",5,155,10,0,0,tb1_font,game_state->virtual_1); - vmwTextXY("ANYWAY I JUST WANT TO GO HOME",5,165,9,0,0,tb1_font,game_state->virtual_1); - vmwTextXY(" AND SLEEP.",5,175,9,0,0,tb1_font,game_state->virtual_1); - vmwClearKeyboardBuffer(); - - j=0; - while ((j<1000) && (!(vmwGetInput()))) { - j++; - for(i=0;i<6;i++) { - vmwPutPixel(star_x[i],star_y[i],0,game_state->virtual_1); - star_x[i]++; - if (star_x[i]>107) { - star_x[i]=37; - star_y[i]=18+rand()%56; - } - vmwPutPixel(star_x[i],star_y[i],15,game_state->virtual_1); - } - vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - usleep(30000); - } - - vmwClearKeyboardBuffer(); -} - +#include +#include /* For rand() */ +#include +#include +#include + +#include "./svmwgraph/svmwgraph.h" +#include "tb1_state.h" + +#include "help.h" +#include "loadsave.h" +#include "graphic_tools.h" +#include "tblib.h" + +#define NORTH 0 +#define SOUTH 1 +#define EAST 2 +#define WEST 3 + +#define TOM_SHAPE 60 + +vmwSprite *shape_table[80]; + + +void loadlevel3shapes(tb1_state *game_state) { + + int i,j; + + vmwLoadPicPacked(0,0,game_state->virtual_2,0,1, + tb1_data_file("level3/tblev3.tb1", + game_state->path_to_data), + game_state->graph_state); + + for(j=0;j<5;j++) { + for(i=0;i<20;i++) { + shape_table[(j*20)+i]=vmwGetSprite(1+(i*11),1+(j*11), + 10,10,game_state->virtual_2); + } + } +} + +int our_sgn(int value) { + + if (value==0) return 0; + if (value<0) return -1; + return 1; +} + + + +/* +Procedure levelthree; +label newroom; +type{ +EnemyInfo = record + x,y:integer; + kind:byte; + out,exploding,boundarycheck,dead:boolean; + explodprogress:byte; + minx,maxx,xspeed,yspeed:integer; + hitsneeded:integer; + end;} +pittype = record + px,py:integer; + end; +kctype = record + kcx,kcy:integer; + kcout:boolean; + end; + +const framedir:array[0..1,0..3] of integer =((0,1,0,-1),(1,0,-1,0)); +VAR loop1,loop2:integer; + ch,ch2:char; + pits:array[0..4] of pittype; + numpits:byte; + + bullet1x,bullet1y,bullet2x,bullet2y,i:integer; + bullet1dir,bullet2dir,collide:byte; + bullet1out,bullet2out:boolean; + whichone,temp,temp2:integer; + tempst:string; + what:byte; + k:integer; + itemp,jtemp:byte; + whatdelay:byte; + tempilg:byte; + xx:integer; + ucollide,dcollide,lcollide,rcollide:word; + walking,feet:byte; + room:byte; + backrow,topblocky:integer; + levelover,odd,changeroom,havegun:boolean; + whichroomnext:array[0..3] of byte; {n,s,e,w} + keycards:array[0..3] of boolean; + keycard:kctype; + shieldup:array[0..11] of boolean; + shieldx,shieldy,laserx,lasery:integer; + laserup:array[0..11] of boolean; + computers:array[0..11] of boolean; + computerx,computery:integer; + computer_0hits:integer; + tempkc:byte; + +procedure horizwalls(x,y,howfar:word); +var i:word; +begin + for i:=0 to howfar do + put10shape240(shape3array[3],vaddr2,x+(i*10),y); +end; + +procedure verticalwalls(x,y,howfar:word); +var i:word; +begin + for i:=0 to howfar do + put10shape240(shape3array[2],vaddr2,x,y+(i*10)); +end; + +procedure dopits; +var i:word; +begin + for i:=0 to (numpits-1) do + with pits[i] do + put10shape240(shape3array[5],vaddr2,px,py); +end; + +procedure clearroom; +var i,j:byte; +begin + for i:=0 to 23 do + for j:=0 to 19 do + put10shape240(shape3array[0], + vaddr2,i*10,j*10); +end; + + +procedure doroom(n,s,e,w:boolean); +var i:byte; +begin + for i:=0 to 2 do begin + put10shape240(shape3array[18],vaddr2,100+(i*10),0); + put10shape240(shape3array[18],vaddr2,100+(i*10),199); + put10shape240(shape3array[19],vaddr2,0,90+(i*10)); + put10shape240(shape3array[19],vaddr2,239,90+(i*10)); + end; + + if n then begin + horizwalls(0,0,10); + horizwalls(130,0,10); + end + else horizwalls(0,0,23); + if s then begin + horizwalls(0,197,10); + horizwalls(130,197,10); + end + else horizwalls(0,197,23); + + if e then begin + verticalwalls(237,0,8); + verticalwalls(237,110,8); + end + + else for i:=0 to 20 do put10shape240(shape3array[2],vaddr2,237,i*10); + if w then begin + verticalwalls(0,0,8); + verticalwalls(0,110,8); + end + else for i:=0 to 20 do put10shape240(shape3array[2],vaddr2,0,i*10); + +end; +*/ + +void LevelThreeEngine(tb1_state *game_state) { + + int level_over=0; + int ch,direction=NORTH; + int x_add=0,y_add=0; + int game_paused=0; + + int tom_x=100,tom_y=100,walking=0; + + vmwVisual *virtual_1;//,*virtual_2; +// vmwFont *tb1_font; + + long oldsec,oldusec,time_spent; + + struct timeval timing_info; + struct timezone dontcare; +// int speed_factor=0; + + virtual_1=game_state->virtual_1; +// virtual_2=game_state->virtual_2; +// tb1_font=game_state->graph_state->default_font; + + loadlevel3shapes(game_state); +/* computer_0hits:=0; + whatdelay:=1; + havegun:=true; + for i:=0 to 3 do keycards[i]:=false; + for i:=0 to 11 do begin + shieldup[i]:=false; + laserup[i]:=false; + computers[i]:=false; + end; + shieldup[0]:=true; + laserup[0]:=true; + computers[0]:=true; + + shipx:=115; + shipy:=180; + odd:=false; + shipxadd:=0; + room:=0; + shipyadd:=0; + + shipframe:=1; + shipspeed:=5; + + ch:=#1; ch2:=#1; + bullet1out:=false; bullet2out:=false; + bullet1x:=0; bullet1y:=0; + bullet2x:=0; bullet2y:=0; + + flip(vaddr2,vaddr); + str(level,tempst); + fillblock(251,52,314,59,0,vaddr); + vmwTextXY(tempst,307,51,12,0,vaddr,false); + + cls(0,vaddr2); + + pal(250,0,0,63); + pal(251,63,0,0); + + pal(254,shields*4,0,0); + howmuchscroll:=50; + + cls(0,vga); + coolbox(70,85,240,120,true,vga); + vmwTextXY(' LEVEL THREE:',84,95,4,7,vga,false); + vmwTextXY(' THE ALIEN SHIP',84,105,4,7,vga,false); + + clearkeyboardbuffer; + pauseawhile(300); + numpassive:=0; + levelover:=false; + +newroom: + numpits:=0; + changeroom:=false; + if room=254 then room:=0; + clearroom; + if shipframe=1 then shipy:=188 + else if shipframe=3 then shipy:=3 + else if shipframe=2 then shipx:=3 + else if shipframe=4 then shipx:=228; + keycard.kcout:=false; + + + if room=0 then begin + whichroomnext[0]:=1; + whichroomnext[1]:=255; + clearroom; + verticalwalls(30,0,16); + verticalwalls(207,0,16); + verticalwalls(57,30,16); + verticalwalls(180,30,16); + with pits[0] do begin + px:=95; + py:=80; + end; + with pits[1] do begin + px:=135; + py:=80; + end; + numpits:=2; { actual} + dopits; + + for i:=0 to 10 do + for j:=0 to 2 do begin + put10shape240(shape3array[4],vaddr2,60+(j*10),80+(i*10)); + put10shape240(shape3array[4],vaddr2,150+(j*10),80+(i*10)); + end; +{walkway} + for i:=0 to 15 do for j:=0 to 1 do + put10shape240(shape3array[1],vaddr2,110+(j*10),40+(i*10)); + + put10shape240(shape3array[6],vaddr2,110,30); + put10shape240(shape3array[6],vaddr2,120,30); + computerx:=110; + computery:=30; + + if shieldup[0] then begin + shieldx:=10; + shieldy:=10; + put10shape240(shape3array[8],vaddr2,10,10); + end; + + if laserup[0] then begin + laserx:=220; + lasery:=10; + put10shape240(shape3array[7],vaddr2,220,10); + end; + + {badguys} + {put10shape240(shape3array[32],vaddr2,40,180); + put10shape240(shape3array[32],vaddr2,190,180);} + + + doroom(true,true,false,false); + + + end; + if room=1 then begin + whichroomnext[0]:=2; + whichroomnext[1]:=0; + doroom(true,true,false,false); + end; + if room=2 then begin + whichroomnext[1]:=1; + whichroomnext[2]:=6; + whichroomnext[3]:=4; + with pits[0] do begin + px:=95; + py:=80; + end; + with pits[1] do begin + px:=135; + py:=80; + end; + numpits:=2; + dopits; + + doroom(false,true,true,true); + end; + if room=3 then begin + whichroomnext[0]:=4; + if not(keycards[3]) then + begin + keycard.kcout:=true; + keycard.kcx:=100; + keycard.kcy:=100; + put10shape240(shape3array[12],vaddr2,100,100); + end; + doroom(true,false,false,false); + end; + if room=4 then begin + whichroomnext[0]:=7; + whichroomnext[1]:=3; + whichroomnext[2]:=2; + doroom(true,true,true,false); + end; + if room=5 then begin + whichroomnext[0]:=6; + doroom(true,false,false,false); + if not(keycards[2]) then begin + keycard.kcout:=true; + keycard.kcx:=100; + keycard.kcy:=100; + put10shape240(shape3array[11],vaddr2,100,100); + end; + end; + if room=6 then begin + whichroomnext[0]:=11; + whichroomnext[1]:=5; + whichroomnext[3]:=2; + doroom(true,true,false,true); + end; + if room=7 then begin + whichroomnext[0]:=8; + whichroomnext[1]:=4; + doroom(true,true,false,false); + end; + if room=8 then begin + whichroomnext[1]:=7; + whichroomnext[2]:=9; + if not(keycards[0]) then begin + keycard.kcout:=true; + keycard.kcx:=100; + keycard.kcy:=100; + put10shape240(shape3array[9],vaddr2,100,100); + end; + doroom(false,true,true,false); + end; + if room=9 then begin + whichroomnext[2]:=10; + whichroomnext[3]:=8; + doroom(false,false,true,true); + end; + if room=10 then begin + whichroomnext[1]:=11; + whichroomnext[3]:=9; + if not(keycards[1]) then begin + keycard.kcout:=true; + keycard.kcx:=100; + keycard.kcy:=100; + put10shape240(shape3array[10],vaddr2,100,100); + end; + doroom(false,true,false,true); + end; + if room=11 then begin + whichroomnext[0]:=10; + whichroomnext[1]:=6; + doroom(true,true,false,false); + end; + if room=255 then begin + if keycards[0] and keycards[1] and + keycards[2] and keycards[3] then + begin + levelover:=true; + cls(0,vga); + vmwTextXY('You Have won!',5,5,9,7,vga,false); + vmwTextXY('But as you can see this level is not done yet.',5,15,9,7,vga,false); + {vmwTextXY('Anyway');} + readln; + inc(level); + end + else begin + cls(0,vga); + vmwTextXY('You Cannot Leave Yet',5,5,9,7,vga,true); + repeat until keypressed; tempch:=readkey; + levelover:=false; + shipframe:=1; + room:=254; + end; + end; + if (room=254) and not(levelover) then goto newroom; + +*/ + + gettimeofday(&timing_info,&dontcare); + oldsec=timing_info.tv_sec; oldusec=timing_info.tv_usec; + + +/**** GAME LOOP ****/ +/*******************/ + + while (!level_over) { + + + /***Collision Check***/ +/* if numpits>0 then + for i:=0 to (numpits-1) do with pits[i] do + if collision(shipx,shipy,5,4,px,py,4,4) + then begin + levelover:=true; + cls(0,vga); + grapherror:=loadpicsuperpacked(0,0,vga,false,true,'tbpit.tb1'); + + + {vmwTextXY('You Fell In A Pit!',5,5,9,2,vga,false);} + clearkeyboardbuffer; + repeat until keypressed; tempch:=readkey; + end; + if keycard.kcout then + if collision(shipx,shipy,5,4,keycard.kcx,keycard.kcy,5,5) + then begin + keycard.kcout:=false; + case room of + 3: keycards[3]:=true; + 5: keycards[2]:=true; + 8: keycards[0]:=true; + 10:keycards[1]:=true; + end; + put10shape240(shape3array[0],vaddr2,keycard.kcx,keycard.kcy); + end; + if shieldup[room] then + if collision(shipx,shipy,5,4,shieldx,shieldy,5,5) + then begin + shieldup[room]:=false; + put10shape240(shape3array[0],vaddr2,shieldx,shieldy); + inc(shields); + pal(254,shields*4,0,0); + for itemp:=0 to shields do + for jtemp:=71 to 78 do + horizontalline(250+(itemp*4), + 254+(itemp*4),jtemp, + 47-itemp,vaddr); + end; + if laserup[room] then + if collision(shipx,shipy,5,4,laserx,lasery,5,5) + then begin + laserup[room]:=false; + put10shape240(shape3array[0],vaddr2,laserx,lasery); + end; + if computers[room] then + if collision(shipx,shipy,5,4,computerx,computery,10,5) + then begin + cls(0,vga); + grapherror:=loadpicsuperpacked(0,0,vga,false,true,'tbconsol.tb1'); + tempkc:=0; + if keycards[0] then begin + inc(tempkc); + putpixel(147,132,0,vga); + end; + if keycards[1] then begin + inc(tempkc); + putpixel(179,132,0,vga); + end; + if keycards[2] then begin + inc(tempkc); + putpixel(179,160,0,vga); + end; + if keycards[3] then begin + inc(tempkc); + putpixel(147,160,0,vga); + end; + + case room of + 0: begin + inc(computer_0hits); + if computer_0hits=1 then begin + + vmwTextXY('COMPUTER ACTIVATED:',47,30,2,0,vga,true); + vmwSmallTextXY(' HUMAN YOU HAVE COME TOO SOON. LEVELS 3',47,40,2,0,vga,true); + vmwSmallTextXY(' AND 4 ARE INCOMPLETE.',47,48,2,0,vga,true); + vmwSmallTextXY(' ANYWAY I CAN SEE YOU ARE NOT THE',47,58,2,0,vga,true); + vmwSmallTextXY(' TENTACLEE COMMANDER. YOU ARE IN',47,66,2,0,vga,true); + vmwSmallTextXY(' GRAVE DANGER. LUCKILY THE MAIN',47,74,2,0,vga,true); + vmwSmallTextXY(' COMPUTER SYSTEM DOES NOT APPROVE',47,82,2,0,vga,true); + vmwSmallTextXY(' OF THE TENTACLEE'S POLICIES.',47,90,2,0,vga,true); + vmwSmallTextXY(' I PERSONALLY CANNOT SHUT OFF THE TRACTOR',47,100,2,0,vga,true); + vmwSmallTextXY(' BEAM. YOU MUST RETRIEVE FOUR KEYCARDS',47,108,2,0,vga,true); + vmwSmallTextXY(' SCATTERED AROUND THE FLIGHT DECK.',47,116,2,0,vga,true); + vmwSmallTextXY(' THE MAP BELOW WILL AID YOU.',47,124,2,0,vga,true); + end; + if computer_0hits=2 then begin + + vmwTextXY('COMPUTER ACTIVATED:',47,30,2,0,vga,true); + vmwSmallTextXY(' HUMAN I HAVE ALREADY TOLD YOU MUCH.',47,40,2,0,vga,true); + vmwSmallTextXY(' COLLECT THE 4 KEYCARDS, MADE OF',47,48,2,0,vga,true); + vmwSmallTextXY(' RUBY, GOLD, EMERALD, AND ALUMINUM.',47,56,2,0,vga,true); + vmwSmallTextXY(' WATCH OUT FOR ENEMIES NOT UNDER MY',47,66,2,0,vga,true); + vmwSmallTextXY(' CONTROL, RADIOACTIVE FLOORS, AND',47,74,2,0,vga,true); + vmwSmallTextXY(' EXTREMELY DEEP PITS.',47,82,2,0,vga,true); + end; + if computer_0hits>2 then begin + vmwTextXY('COMPUTER ACTIVATED:',47,30,2,0,vga,true); + vmwSmallTextXY(' HUMAN, GO AWAY. YOU ANNOY ME.',47,40,2,0,vga,true); + vmwSmallTextXY(' I HAVE TOLD YOU EVERYTHING.',47,48,2,0,vga,true); + end; + + + + end; + end; + clearkeyboardbuffer; + repeat until keypressed; tempch:=readkey; + shipx:=shipx+(4*framedir[1,shipframe]); + shipy:=shipy+(4*framedir[0,shipframe]); + end; +*/ + + /***DO EXPLOSIONS***/ +/*{ for i:=0 to 30 do + if passive[i].exploding then with passive[i] do begin + inc(explodeprogress); + vmwPutSprite240(shape2array[35+explodeprogress],vaddr2, + 20,9,x,y+howmuchscroll); + if explodeprogress>4 then begin + dead:=true; + exploding:=false; + vmwPutSprite240over(14800(*shape2array[34]*),vaddr2, + 20,9,x,y+howmuchscroll); + end; + end; +*/ + + /***MOVE BULLETS***/ +/* if bullet1out then begin + case bullet1dir of + 1:begin dec(bullet1y,5); + collide:=upcollide(bullet1x,bullet1y,5,-5,3,vaddr2); + end; + 2:begin inc(bullet1x,5); + collide:=leftcollide(bullet1x,bullet1y,5,10,3,vaddr2); + end; + 3:begin inc(bullet1y,5); + collide:=upcollide(bullet1x,bullet1y,5,10,3,vaddr2); + end; + 4:begin dec(bullet1x,5); + collide:=leftcollide(bullet1x,bullet1y,5,-5,3,vaddr2); + end; + end; + + if collide<>0 then bullet1out:=false; + if bullet1out then vmwPutSprite(shape3array[76],vaddr,10,9,bullet1x,bullet1y); + end; + if bullet2out then begin + dec(bullet2y,5); + if bullet2y<5 then bullet2out:=false; + if bullet2out then vmwPutSprite(shape3array[76],vaddr,10,9,bullet2x,bullet2y); + end; + */ + /***MOVE ENEMIES***/ +/* { for j:=0 to 30 do begin + if passive[j].dead=false then begin + inc(passive[j].y); + if(passive[j].y)>190 then passive[j].dead:=true; + end; + end; + for j:=0 to 30 do begin + if passive[j].lastshot>0 then dec(passive[j].lastshot); + if (passive[j].dead=false) and (passive[j].shooting) + and (passive[j].lastshot=0) and (passive[j].y>0) + then begin + tempilg:=7; + for i:=0 to 5 do if enemy[i].out=false then tempilg:=i; + if tempilg<>7 then begin + passive[j].lastshot:=30; + enemy[tempilg].out:=true; + enemy[tempilg].y:=passive[j].y; + enemy[tempilg].x:=passive[j].x+5; + enemy[tempilg].yspeed:=5; + enemy[tempilg].kind:=25; + if passive[j].kind=11 then enemy[tempilg].kind:=26; + end; + end; + end; + for j:=0 to 5 do begin + if enemy[j].out then begin + vmwPutSprite(shape2array[enemy[j].kind],vaddr, + 20,9,enemy[j].x,enemy[j].y); + enemy[j].y:=enemy[j].y+enemy[j].yspeed; + if enemy[j].y>189 then enemy[j].out:=false; + end; + end; + } +*/ + + /***READ KEYBOARD***/ + if ( (ch=vmwGetInput())!=0) { + switch(ch){ + case VMW_ESCAPE: level_over=1; + break; + case VMW_RIGHT: if (direction==EAST) x_add=2; + else direction=EAST; + break; + /* + if (shipframe=2) and (shipxadd=0) then shipxadd:=2 + else if (shipframe<>2) then shipframe:=2 + else inc(shipxadd); + */ + case VMW_LEFT: if (direction==WEST) x_add=-2; + else direction=WEST; + break; + case VMW_UP: if (direction==NORTH) y_add=-2; + else direction=NORTH; + break; + case VMW_DOWN: if (direction==SOUTH) y_add=2; + else direction=SOUTH; + break; + case VMW_F1: game_paused=1; + help(game_state); + break; + + case 'P': + case 'p': game_paused=1; + coolbox(65,85,175,110,1,virtual_1); + vmwTextXY("GAME PAUSED",79,95,4,7,0, + game_state->graph_state->default_font, + virtual_1); + vmwClearKeyboardBuffer(); + vmwBlitMemToDisplay(game_state->graph_state, + virtual_1); + while (vmwGetInput()==0) usleep(30000); + break; + case 'S': + case 's': if (game_state->sound_possible) + game_state->sound_enabled=!(game_state->sound_enabled); + break; + + case VMW_F2: game_paused=1; + savegame(game_state); + break; + case ' ': /* shoot */ + break; + /* + + if (ch=' ') and havegun then begin + if (bullet1out=false) then begin + {if sbeffects then StartSound(Sound[4], 0, false);} + bullet1out:=true; + bullet1x:=shipx+3; + bullet1y:=shipy+4; + bullet1dir:=shipframe; + vmwPutSprite(shape3array[76],vaddr,10,9,bullet1x,bullet1y); + end + else + if (bullet2out=false) then begin + {if sbeffects then StartSound(Sound[4], 0, false);} + bullet2out:=true; + bullet2x:=shipx; + bullet2y:=shipy; + bullet2dir:=shipframe; + vmwPutSprite(shape3array[76],vaddr,10,9,bullet2x,bullet2y); + end; + end; +*/ + } + } + + /***MOVE TOM***/ + + + /* ucollide:=upcollide(shipx,shipy,abs(shipyadd),-abs(shipyadd),10,vaddr2); + dcollide:=upcollide(shipx,shipy,abs(shipyadd),8,10,vaddr2); + lcollide:=leftcollide(shipx,shipy,abs(shipxadd),-abs(shipxadd),8,vaddr2); + rcollide:=leftcollide(shipx,shipy,abs(shipxadd),0,8,vaddr2);*/ + + /* if (shipframe=1) and (ucollide<>0) then shipyadd:=0; + if (shipframe=3) and (dcollide<>0) then shipyadd:=0; + if (shipframe=2) and (rcollide<>0) then shipxadd:=0; + if (shipframe=4) and (lcollide<>0) then shipxadd:=0; + */ + tom_x+=x_add; + tom_y+=y_add; + y_add-=our_sgn(y_add); + x_add-=our_sgn(x_add); + /* + + case ucollide of + 5: begin + changeroom:=true; + room:=whichroomnext[0]; + end; + end; + case dcollide of + 5: begin + changeroom:=true; + room:=whichroomnext[1]; + end; + end; + case rcollide of + 5: begin + changeroom:=true; + room:=whichroomnext[2]; + end; + end; + case lcollide of + 5: begin + changeroom:=true; + room:=whichroomnext[3]; + end; + end; + */ + + if ((!y_add) || (!x_add)) walking+=4; + else walking=0; + + if (walking>12) walking=0; + + switch(direction) { + case NORTH: vmwPutSprite(shape_table[TOM_SHAPE+walking],tom_x,tom_y,game_state->virtual_1); + break; + case EAST: vmwPutSprite (shape_table[TOM_SHAPE+1+walking],tom_x,tom_y,game_state->virtual_1); + break; + case SOUTH: vmwPutSprite (shape_table[TOM_SHAPE+2+walking],tom_x,tom_y,game_state->virtual_1); + break; + case WEST: vmwPutSprite (shape_table[TOM_SHAPE+3+walking],tom_x,tom_y,game_state->virtual_1); + } + + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + + /* Calculate how much time has passed */ + gettimeofday(&timing_info,&dontcare); + time_spent=timing_info.tv_usec-oldusec; + if (timing_info.tv_sec-oldsec) time_spent+=1000000; +#ifdef DEBUG_ON + printf("%f\n",1000000/(float)time_spent); +#endif + + /* If time passed was too little, wait a bit */ + while (time_spent<33000){ + gettimeofday(&timing_info,&dontcare); + usleep(5); + time_spent=timing_info.tv_usec-oldusec; + if (timing_info.tv_sec-oldsec) time_spent+=1000000; + } + + /* It game is paused, don't keep track of time */ + if (game_paused) { + gettimeofday(&timing_info,&dontcare); + oldusec=timing_info.tv_usec; + oldsec=timing_info.tv_sec; + game_paused=0; + //speed_factor=1; + } + else { + //speed_factor=(time_spent/30000); + oldusec=timing_info.tv_usec; + oldsec=timing_info.tv_sec; + } + } +} + + + +void LevelThreeLittleOpener(tb1_state *game_state) { + + int grapherror,i,j; + + vmwFont *tb1_font; + vmwVisual *virtual_1,*virtual_2; + + int star_x[6]; + int star_y[6]; + + tb1_font=game_state->graph_state->default_font; + virtual_1=game_state->virtual_1; + virtual_2=game_state->virtual_2; + + loadlevel3shapes(game_state); + + vmwClearScreen(game_state->virtual_1,0); + grapherror=vmwLoadPicPacked(0,0,virtual_2, + 1,1,tb1_data_file("level3/tbl3intr.tb1", + game_state->path_to_data),game_state->graph_state); + if (grapherror) { + return; + } + + vmwArbitraryCrossBlit(game_state->virtual_2,0,3,171,114, + game_state->virtual_1,10,10); + + + + vmwPutSprite(shape_table[TOM_SHAPE],113,52,game_state->virtual_1); + + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + + vmwTextXY("Hmmmm... STUPID TRACTOR BEAM.",10,155,10,0,0,tb1_font,virtual_1); + vmwTextXY("I GUESS I'D BETTER GO SHUT IT OFF.",10,165,10,0,0,tb1_font,virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + + pauseawhile(8); + vmwClearKeyboardBuffer(); + + for(i=24;i>=0;i--) { + vmwArbitraryCrossBlit(game_state->virtual_2,0,3,171,114, + game_state->virtual_1,10,10); + vmwPutSprite(shape_table[TOM_SHAPE+(4*(i% 4))],113,28+i,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + usleep(50000); + } + vmwPutSprite (shape_table[TOM_SHAPE],113,28,game_state->virtual_1); + vmwDrawBox(10,155,290,30,0,game_state->virtual_1); + vmwTextXY("I'M LUCKY I WORE MAGNETIC SHOES.",10,155,12,0,0,tb1_font,game_state->virtual_1); + vmwTextXY("Hmmmm. SOMEONE LEFT THE AIR-LOCK",10,165,12,0,0,tb1_font,game_state->virtual_1); + vmwTextXY(" UNLOCKED. STRANGE.",10,175,12,0,0,tb1_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + pauseawhile(8); + vmwClearKeyboardBuffer(); + + vmwPutPixel(110,20,10,game_state->virtual_1); + vmwPutPixel(110,22,10,game_state->virtual_1); + vmwDrawBox(111,14,12,14,0,game_state->virtual_1); + vmwDrawBox(10,155,290,30,0,game_state->virtual_1); + vmwTextXY("I HOPE THIS ISN'T A TRAP.",10,155,9,0,0,tb1_font,game_state->virtual_1); + vmwTextXY("I WISH I HAD SOME FORM OF ",10,165,9,0,0,tb1_font,game_state->virtual_1); + vmwTextXY(" WEAPON.",10,175,9,0,0,tb1_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + pauseawhile(7); + vmwClearKeyboardBuffer(); + + vmwClearScreen(game_state->virtual_1,0); + + vmwArbitraryCrossBlit(game_state->virtual_2,179,41,108,93, + game_state->virtual_1,10,10); + + for(i=0;i<6;i++) { + star_x[i]=37+rand()%70; + star_y[i]=18+rand()%56; + vmwPutPixel(star_x[i],star_y[i],15,game_state->virtual_1); + } + + vmwTextXY("WOW!! A GLASS-WALLED AIR-LOCK.",10,135,9,0,0,tb1_font,game_state->virtual_1); + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + pauseawhile(5); + vmwClearKeyboardBuffer(); + + vmwDrawBox(10,135,290,50,0,game_state->virtual_1); + vmwTextXY("NOW WHERE ARE WE GOING?",5,125,9,0,0,tb1_font,game_state->virtual_1); + vmwTextXY("I GUESS THE PLANET EERM.",5,135,9,0,0,tb1_font,game_state->virtual_1); + vmwTextXY("WHAT AN ODD NAME.",5,145,9,0,0,tb1_font,game_state->virtual_1); + vmwTextXY("AND WHY AM I TALKING TO MYSELF?",5,155,10,0,0,tb1_font,game_state->virtual_1); + vmwTextXY("ANYWAY I JUST WANT TO GO HOME",5,165,9,0,0,tb1_font,game_state->virtual_1); + vmwTextXY(" AND SLEEP.",5,175,9,0,0,tb1_font,game_state->virtual_1); + vmwClearKeyboardBuffer(); + + j=0; + while ((j<1000) && (!(vmwGetInput()))) { + j++; + for(i=0;i<6;i++) { + vmwPutPixel(star_x[i],star_y[i],0,game_state->virtual_1); + star_x[i]++; + if (star_x[i]>107) { + star_x[i]=37; + star_y[i]=18+rand()%56; + } + vmwPutPixel(star_x[i],star_y[i],15,game_state->virtual_1); + } + vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); + usleep(30000); + } + + vmwClearKeyboardBuffer(); +} + diff --git a/tb1_linux/svmwgraph/Makefile b/tb1_linux/svmwgraph/Makefile index 416290d..8ac057f 100644 --- a/tb1_linux/svmwgraph/Makefile +++ b/tb1_linux/svmwgraph/Makefile @@ -4,49 +4,49 @@ INCLUDE= $(INCLUDE_GLOBAL) LIBS= $(LIBS_GLOBAL) all: libsvmwgraph.a - + libsvmwgraph.a: vmw_core.o vmw_dialogs.o vmw_flip.o vmw_font.o vmw_paintpro.o vmw_palette.o vmw_pcx.o vmw_setup.o vmw_sprite.o $(CURSES_TARGET) null_svmwgraph.o $(OPENGL_TARGET) $(SDL_TARGET) ar cru libsvmwgraph.a vmw_core.o vmw_dialogs.o vmw_flip.o vmw_font.o vmw_paintpro.o vmw_palette.o vmw_pcx.o vmw_setup.o vmw_sprite.o $(CURSES_TARGET) null_svmwgraph.o $(OPENGL_TARGET) $(SDL_TARGET) ranlib libsvmwgraph.a vmw_core.o: vmw_core.c - $(CC) $(INCLUDE) -c vmw_core.c + $(CC) $(CFLAGS) $(INCLUDE) -c vmw_core.c vmw_dialogs.o: vmw_dialogs.c - $(CC) $(INCLUDE) -c vmw_dialogs.c + $(CC) $(CFLAGS) $(INCLUDE) -c vmw_dialogs.c vmw_flip.o: vmw_flip.c - $(CC) $(INCLUDE) -c vmw_flip.c + $(CC) $(CFLAGS) $(INCLUDE) -c vmw_flip.c vmw_font.o: vmw_font.c - $(CC) $(INCLUDE) -c vmw_font.c + $(CC) $(CFLAGS) $(INCLUDE) -c vmw_font.c vmw_paintpro.o: vmw_paintpro.c - $(CC) $(INCLUDE) -c vmw_paintpro.c + $(CC) $(CFLAGS) $(INCLUDE) -c vmw_paintpro.c vmw_palette.o: vmw_palette.c - $(CC) $(INCLUDE) -c vmw_palette.c + $(CC) $(CFLAGS) $(INCLUDE) -c vmw_palette.c vmw_pcx.o: vmw_pcx.c - $(CC) $(INCLUDE) -c vmw_pcx.c - -vmw_setup.o: vmw_setup.c - $(CC) $(INCLUDE) $(SDL_FLAGS) $(CURSES_FLAGS) $(OPENGL_FLAGS) -c vmw_setup.c - -vmw_sprite.o: vmw_sprite.c - $(CC) $(INCLUDE) -c vmw_sprite.c + $(CC) $(CFLAGS) $(INCLUDE) -c vmw_pcx.c -curses_svmwgraph.o: curses_svmwgraph.c - $(CC) $(INCLUDE) -c curses_svmwgraph.c $(CURSES_FLAGS) +vmw_setup.o: vmw_setup.c + $(CC) $(CFLAGS) $(INCLUDE) $(SDL_FLAGS) $(CURSES_FLAGS) $(OPENGL_FLAGS) -c vmw_setup.c + +vmw_sprite.o: vmw_sprite.c + $(CC) $(CFLAGS) $(INCLUDE) -c vmw_sprite.c + +curses_svmwgraph.o: curses_svmwgraph.c + $(CC) $(CFLAGS) $(INCLUDE) -c curses_svmwgraph.c $(CURSES_FLAGS) null_svmwgraph.o: null_svmwgraph.c - $(CC) $(INCLUDE) -c null_svmwgraph.c - + $(CC) $(CFLAGS) $(INCLUDE) -c null_svmwgraph.c + opengl_svmwgraph.o: opengl_svmwgraph.c - $(CC) $(INCLUDE) -c opengl_svmwgraph.c + $(CC) $(CFLAGS) $(INCLUDE) -c opengl_svmwgraph.c sdl_svmwgraph.o: sdl_svmwgraph.c - $(CC) $(INCLUDE) -c sdl_svmwgraph.c + $(CC) $(CFLAGS) $(INCLUDE) -c sdl_svmwgraph.c clean: rm -f libsvmwgraph.a *.o *~ diff --git a/tb1_linux/svmwgraph/opengl_svmwgraph.c b/tb1_linux/svmwgraph/opengl_svmwgraph.c index a004b3a..191a32d 100644 --- a/tb1_linux/svmwgraph/opengl_svmwgraph.c +++ b/tb1_linux/svmwgraph/opengl_svmwgraph.c @@ -1,352 +1,349 @@ -/* The OpenGL hooks for the Super VMW graphics library */ - -#include -#include -#include - -#include "svmwgraph.h" -#include /* For atexit() */ -#include - -static float rotation=0.0; - -unsigned char palette[256][4]; - -#define TEXTURE_SIZE 64 - -int texture_grid[5][4]; -GLubyte *texture_data[5][4]; - - -typedef struct { - GLubyte *texture_data; - GLuint texture_name; - GLfloat x1,y1,x2,y2; -} texture_block; - - -texture_block *current_texture; - -GLuint temp_texture_name; -int texnumx,texnumy; - - - -void reshape(int w,int h) { - glViewport(0,0,(GLsizei)w,(GLsizei)h); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,100.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - //glTranslatef(0.0,0.0,-3.6); -} - - - - /* Setup the Graphics */ - /* Pass '0' to auto-detect bpp */ -void *openGL_setupGraphics(int *xsize,int *ysize,int *bpp, - int fullscreen,int verbose) { - - SDL_Surface *sdl_screen=NULL; - SDL_Joystick *joy; - int mode,x,y; - - /* Initialize SDL */ - if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK)<0) { - printf("Error trying to init SDL: %s\n",SDL_GetError()); - return NULL; - } - - if (fullscreen) mode=SDL_OPENGL | SDL_FULLSCREEN; - else mode=SDL_OPENGL; - - /* Create the OpenGL screen */ - if ( (sdl_screen=SDL_SetVideoMode(*xsize, *ysize, 0, mode)) == NULL ) { - printf("Unable to create OpenGL screen: %s\n", SDL_GetError()); - SDL_Quit(); - return NULL; - } - - atexit(SDL_Quit); - - SDL_WM_SetCaption("Tom Bombem...",NULL); - - /* Try to init Joysticks */ - if (SDL_NumJoysticks()>0){ - /* Open joystick */ - joy=SDL_JoystickOpen(0); - if (joy) { - printf("Opened Joystick 0\n"); - printf("Name: %s\n", SDL_JoystickName(0)); - SDL_JoystickEventState(SDL_ENABLE); - } - } - - printf(" GL_VERSION: %s\n", glGetString(GL_VERSION)); - printf(" GL_VENDOR: %s\n", glGetString(GL_VENDOR)); - printf(" GL_RENDERER: %s\n", glGetString(GL_RENDERER)); - - glPixelStorei(GL_UNPACK_ALIGNMENT,1); - glClearColor(0.0,0.0,0.0,0.0); - glClearDepth(1.0); - glShadeModel(GL_SMOOTH); - glEnable(GL_DEPTH_TEST); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - glLoadIdentity(); - - reshape(*xsize,*ysize); - - printf("Init!\n"); fflush(stdout); - -// Initializing Textures!! -// - - - for(x=0;x<5;x++) { - for(y=0;y<4;y++) { - texture_data[x][y]=calloc(64*64,sizeof(char)*4); - glBindTexture(GL_TEXTURE_2D,texture_grid[x][y]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, - 64 ,0,GL_RGBA,GL_UNSIGNED_BYTE,texture_data[x][y]); - - } - } - - - -#if 0 - texnumx=320/TEXTURE_SIZE; - if (320%TEXTURE_SIZE) texnumx++; - texnumy=200/TEXTURE_SIZE; - if (200%TEXTURE_SIZE) texnumy++; - - texture_grid=calloc(texnumx*texnumy,sizeof(texture_block)); - - for(x=0;xtexture_data=malloc(TEXTURE_SIZE*TEXTURE_SIZE); - - current_texture->x1=x*TEXTURE_SIZE; - current_texture->y1=y*TEXTURE_SIZE; - current_texture->x2=(x+1)*TEXTURE_SIZE; - if (current_texture->x2>320) current_texture->x2=320; - current_texture->y2=(y+1)*TEXTURE_SIZE; - if (current_texture->y2>200) current_texture->y2=200; - - glGenTextures(1,&temp_texture_name); - - current_texture->texture_name=temp_texture_name; - - glBindTexture(GL_TEXTURE_2D, temp_texture_name); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,TEXTURE_SIZE, - TEXTURE_SIZE,0,GL_RGBA,GL_UNSIGNED_BYTE, - current_texture->texture_data); -// glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); - - } - } - - - glOrtho(-20,340,-20,220,-100,100); - -// gluPerspective(60,1.6,-10,10); -#endif - return sdl_screen; - -} - - -void openGL_flushPalette(vmwSVMWGraphState *state) { - - int i; - - for(i=0;i<256;i++) { - palette[i][0]=((state->palette[i]>>11)<<3); - palette[i][1]=( ((state->palette[i]>>5)&0x3f)<<2); - palette[i][2]=((state->palette[i]&0x1f)<<3); - palette[i][3]=255; - } - -} - - -void openGL_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { - - - int x=0,y=0,temp_col,i,j,ending_j,ending_i; - unsigned char *s_pointer; - - GLubyte temp_data[64*64*4]; - - GLubyte *t_pointer; - - GLfloat light_position[]={0.0,0.0,25.0,0.0}; - GLfloat light_ambient[]={0.65,0.65,0.65,1.0}; - GLfloat lmodel_ambient[]={0.4,0.4,0.4,1.0}; - GLfloat white_light[]={1.0,1.0,1.0,1.0}; - - - glLoadIdentity(); - - gluLookAt(0.0,0.0,20.0, - 0.0,0.0,0.0, - 0.0,1.0,1.0); - - - - glLightfv(GL_LIGHT0, GL_POSITION, light_position); - glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); - glLightfv(GL_LIGHT0, GL_SPECULAR,white_light); - - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); - - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glColor3f(1,0,0); - { - GLfloat default_a[]={0.6,0.6,0.6,1.0 - }; - GLfloat default_d[]={ 0.8,0.8,0.8,1.0 - }; - GLfloat default_s[]={0.0,0.0,0.0,1.0 - }; - GLfloat default_e[]={0.0,0.0,0.0,1.0 - }; - - glMaterialfv(GL_FRONT,GL_AMBIENT,default_a); - glMaterialfv(GL_FRONT,GL_DIFFUSE,default_d); - glMaterialfv(GL_FRONT,GL_SPECULAR,default_s); - glMaterialfv(GL_FRONT,GL_EMISSION,default_e); - } -#if 0 - for (x=0;xxsize;x++) - for (y=0;yysize;y++) { - *((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)]; - s_pointer++; t_pointer+=2; - } -#endif - - - glRotatef(rotation,1,1,1); - rotation+=1.0; - glEnable(GL_TEXTURE_2D); - glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE); - - for(i=0;i<5;i++) { - for(j=0;j<3;j++) { /* make it 4, but fix so no out of bounds */ - s_pointer=(source->memory)+(((j*64*320)+(i*64))); - - for(y=0;y<64;y++) { - for(x=0;x<64;x++) { - temp_data[ ((y*64)+x)*4] =palette[*(s_pointer)][0]; - temp_data[ ((y*64)+x)*4+1] =palette[*(s_pointer)][1]; - temp_data[ ((y*64)+x)*4+2] =palette[*(s_pointer)][2]; - temp_data[ ((y*64)+x)*4+3] =palette[*(s_pointer)][3]; - s_pointer++; - } - s_pointer+=(320-64); - } - - glBindTexture(GL_TEXTURE_2D,texture_grid[i][j]); - - glTexSubImage2D(GL_TEXTURE_2D,0,0,0,64,64,GL_RGBA,GL_UNSIGNED_BYTE, - &temp_data); - - glPushMatrix(); - glTranslatef( i*4,-(j*4),0); - - glBegin(GL_QUADS); - glNormal3f(0.0,0.0,1.0); - glTexCoord2f(0,0); - glVertex3f(-2,2,0); - glTexCoord2f(1,0); - glVertex3f(2,2,0); - glTexCoord2f(1,1); - glVertex3f(2,-2,0); - glTexCoord2f(0,1); - glVertex3f(-2,-2,0); - glEnd(); - glPopMatrix(); - } - } - glDisable(GL_TEXTURE_2D); -#if 0 - -// glEnable(GL_DEPTH_TEST); - glEnable(GL_TEXTURE_2D); - - for(y=0;ytexture_name); - - s_pointer=source->memory+((y*TEXTURE_SIZE)*320)+(x*TEXTURE_SIZE); - - t_pointer=(current_texture->texture_data); - - ending_j=TEXTURE_SIZE; - if (((y*TEXTURE_SIZE)+TEXTURE_SIZE)>200) - ending_j=200%TEXTURE_SIZE; - - ending_i=TEXTURE_SIZE; - if (((y*TEXTURE_SIZE)+TEXTURE_SIZE)>320) - ending_i=320%TEXTURE_SIZE; -// printf("==>%i %i %p\n",x,y,current_texture); fflush(stdout); - - - for(j=0;j>>%p %p=%i\n",t_pointer,s_pointer,temp_col); fflush(stdout); - memcpy(t_pointer,palette[temp_col],3); - s_pointer++; - t_pointer+=4; - } - s_pointer+=(320-TEXTURE_SIZE); - } - - glTexSubImage2D(GL_TEXTURE_2D, - 0,0,0,TEXTURE_SIZE,TEXTURE_SIZE, - GL_RGBA, - GL_UNSIGNED_BYTE, - current_texture->texture_data); - - glBegin(GL_QUADS); - glTexCoord2f(0.0,0.0); glVertex3f(current_texture->x1,current_texture->y1,0.0); - glTexCoord2f(1.0,0.0); glVertex3f(current_texture->x2,current_texture->y1,0.0); - glTexCoord2f(1.0,1.0); glVertex3f(current_texture->x2,current_texture->y2,0.0); - glTexCoord2f(0.0,1.0); glVertex3f(current_texture->x1,current_texture->y2,0.0); - glEnd(); - } - - } - glFlush(); - - glDisable(GL_TEXTURE_2D); - glDisable(GL_DEPTH_TEST); - glPopMatrix(); -#endif - glFlush(); - SDL_GL_SwapBuffers(); - glDisable(GL_LIGHTING); -} - - -void openGL_closeGraphics() { -} +/* The OpenGL hooks for the Super VMW graphics library */ + +#include +#include +#include + +#include "svmwgraph.h" +#include /* For atexit() */ +#include + +static float rotation=0.0; + +unsigned char palette[256][4]; + +#define TEXTURE_SIZE 64 + +int texture_grid[5][4]; +GLubyte *texture_data[5][4]; + + +typedef struct { + GLubyte *texture_data; + GLuint texture_name; + GLfloat x1,y1,x2,y2; +} texture_block; + + +texture_block *current_texture; + +GLuint temp_texture_name; +int texnumx,texnumy; + + + +void reshape(int w,int h) { + glViewport(0,0,(GLsizei)w,(GLsizei)h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,100.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + //glTranslatef(0.0,0.0,-3.6); +} + + + + /* Setup the Graphics */ + /* Pass '0' to auto-detect bpp */ +void *openGL_setupGraphics(int *xsize,int *ysize,int *bpp, + int fullscreen,int verbose) { + + SDL_Surface *sdl_screen=NULL; + SDL_Joystick *joy; + int mode,x,y; + + /* Initialize SDL */ + if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK)<0) { + printf("Error trying to init SDL: %s\n",SDL_GetError()); + return NULL; + } + + if (fullscreen) mode=SDL_OPENGL | SDL_FULLSCREEN; + else mode=SDL_OPENGL; + + /* Create the OpenGL screen */ + if ( (sdl_screen=SDL_SetVideoMode(*xsize, *ysize, 0, mode)) == NULL ) { + printf("Unable to create OpenGL screen: %s\n", SDL_GetError()); + SDL_Quit(); + return NULL; + } + + atexit(SDL_Quit); + + SDL_WM_SetCaption("Tom Bombem...",NULL); + + /* Try to init Joysticks */ + if (SDL_NumJoysticks()>0){ + /* Open joystick */ + joy=SDL_JoystickOpen(0); + if (joy) { + printf("Opened Joystick 0\n"); + printf("Name: %s\n", SDL_JoystickName(0)); + SDL_JoystickEventState(SDL_ENABLE); + } + } + + printf(" GL_VERSION: %s\n", glGetString(GL_VERSION)); + printf(" GL_VENDOR: %s\n", glGetString(GL_VENDOR)); + printf(" GL_RENDERER: %s\n", glGetString(GL_RENDERER)); + + glPixelStorei(GL_UNPACK_ALIGNMENT,1); + glClearColor(0.0,0.0,0.0,0.0); + glClearDepth(1.0); + glShadeModel(GL_SMOOTH); + glEnable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glLoadIdentity(); + + reshape(*xsize,*ysize); + + printf("Init!\n"); fflush(stdout); + +// Initializing Textures!! +// + + + for(x=0;x<5;x++) { + for(y=0;y<4;y++) { + texture_data[x][y]=calloc(64*64,sizeof(char)*4); + glBindTexture(GL_TEXTURE_2D,texture_grid[x][y]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, + 64 ,0,GL_RGBA,GL_UNSIGNED_BYTE,texture_data[x][y]); + + } + } + + + +#if 0 + texnumx=320/TEXTURE_SIZE; + if (320%TEXTURE_SIZE) texnumx++; + texnumy=200/TEXTURE_SIZE; + if (200%TEXTURE_SIZE) texnumy++; + + texture_grid=calloc(texnumx*texnumy,sizeof(texture_block)); + + for(x=0;xtexture_data=malloc(TEXTURE_SIZE*TEXTURE_SIZE); + + current_texture->x1=x*TEXTURE_SIZE; + current_texture->y1=y*TEXTURE_SIZE; + current_texture->x2=(x+1)*TEXTURE_SIZE; + if (current_texture->x2>320) current_texture->x2=320; + current_texture->y2=(y+1)*TEXTURE_SIZE; + if (current_texture->y2>200) current_texture->y2=200; + + glGenTextures(1,&temp_texture_name); + + current_texture->texture_name=temp_texture_name; + + glBindTexture(GL_TEXTURE_2D, temp_texture_name); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,TEXTURE_SIZE, + TEXTURE_SIZE,0,GL_RGBA,GL_UNSIGNED_BYTE, + current_texture->texture_data); +// glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); + + } + } + + + glOrtho(-20,340,-20,220,-100,100); + +// gluPerspective(60,1.6,-10,10); +#endif + return sdl_screen; + +} + + +void openGL_flushPalette(vmwSVMWGraphState *state) { + + int i; + + for(i=0;i<256;i++) { + palette[i][0]=((state->palette[i]>>11)<<3); + palette[i][1]=( ((state->palette[i]>>5)&0x3f)<<2); + palette[i][2]=((state->palette[i]&0x1f)<<3); + palette[i][3]=255; + } + +} + + +void openGL_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { + + + int x=0,y=0,i,j;//temp_col,ending_j,ending_i; + unsigned char *s_pointer; + + GLubyte temp_data[64*64*4]; + +// GLubyte *t_pointer; + + GLfloat light_position[]={0.0,0.0,25.0,0.0}; +// GLfloat light_ambient[]={0.65,0.65,0.65,1.0}; + GLfloat lmodel_ambient[]={0.4,0.4,0.4,1.0}; + GLfloat white_light[]={1.0,1.0,1.0,1.0}; + + glLoadIdentity(); + + gluLookAt(0.0,0.0,20.0, + 0.0,0.0,0.0, + 0.0,1.0,1.0); + + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); + glLightfv(GL_LIGHT0, GL_SPECULAR,white_light); + + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glColor3f(1,0,0); + { + GLfloat default_a[]={0.6,0.6,0.6,1.0 + }; + GLfloat default_d[]={ 0.8,0.8,0.8,1.0 + }; + GLfloat default_s[]={0.0,0.0,0.0,1.0 + }; + GLfloat default_e[]={0.0,0.0,0.0,1.0 + }; + + glMaterialfv(GL_FRONT,GL_AMBIENT,default_a); + glMaterialfv(GL_FRONT,GL_DIFFUSE,default_d); + glMaterialfv(GL_FRONT,GL_SPECULAR,default_s); + glMaterialfv(GL_FRONT,GL_EMISSION,default_e); + } +#if 0 + for (x=0;xxsize;x++) + for (y=0;yysize;y++) { + *((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)]; + s_pointer++; t_pointer+=2; + } +#endif + + + glRotatef(rotation,1,1,1); + rotation+=1.0; + glEnable(GL_TEXTURE_2D); + glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE); + + for(i=0;i<5;i++) { + for(j=0;j<3;j++) { /* make it 4, but fix so no out of bounds */ + s_pointer=(source->memory)+(((j*64*320)+(i*64))); + + for(y=0;y<64;y++) { + for(x=0;x<64;x++) { + temp_data[ ((y*64)+x)*4] =palette[*(s_pointer)][0]; + temp_data[ ((y*64)+x)*4+1] =palette[*(s_pointer)][1]; + temp_data[ ((y*64)+x)*4+2] =palette[*(s_pointer)][2]; + temp_data[ ((y*64)+x)*4+3] =palette[*(s_pointer)][3]; + s_pointer++; + } + s_pointer+=(320-64); + } + + glBindTexture(GL_TEXTURE_2D,texture_grid[i][j]); + + glTexSubImage2D(GL_TEXTURE_2D,0,0,0,64,64,GL_RGBA,GL_UNSIGNED_BYTE, + &temp_data); + + glPushMatrix(); + glTranslatef( i*4,-(j*4),0); + + glBegin(GL_QUADS); + glNormal3f(0.0,0.0,1.0); + glTexCoord2f(0,0); + glVertex3f(-2,2,0); + glTexCoord2f(1,0); + glVertex3f(2,2,0); + glTexCoord2f(1,1); + glVertex3f(2,-2,0); + glTexCoord2f(0,1); + glVertex3f(-2,-2,0); + glEnd(); + glPopMatrix(); + } + } + glDisable(GL_TEXTURE_2D); +#if 0 + +// glEnable(GL_DEPTH_TEST); + glEnable(GL_TEXTURE_2D); + + for(y=0;ytexture_name); + + s_pointer=source->memory+((y*TEXTURE_SIZE)*320)+(x*TEXTURE_SIZE); + + t_pointer=(current_texture->texture_data); + + ending_j=TEXTURE_SIZE; + if (((y*TEXTURE_SIZE)+TEXTURE_SIZE)>200) + ending_j=200%TEXTURE_SIZE; + + ending_i=TEXTURE_SIZE; + if (((y*TEXTURE_SIZE)+TEXTURE_SIZE)>320) + ending_i=320%TEXTURE_SIZE; +// printf("==>%i %i %p\n",x,y,current_texture); fflush(stdout); + + + for(j=0;j>>%p %p=%i\n",t_pointer,s_pointer,temp_col); fflush(stdout); + memcpy(t_pointer,palette[temp_col],3); + s_pointer++; + t_pointer+=4; + } + s_pointer+=(320-TEXTURE_SIZE); + } + + glTexSubImage2D(GL_TEXTURE_2D, + 0,0,0,TEXTURE_SIZE,TEXTURE_SIZE, + GL_RGBA, + GL_UNSIGNED_BYTE, + current_texture->texture_data); + + glBegin(GL_QUADS); + glTexCoord2f(0.0,0.0); glVertex3f(current_texture->x1,current_texture->y1,0.0); + glTexCoord2f(1.0,0.0); glVertex3f(current_texture->x2,current_texture->y1,0.0); + glTexCoord2f(1.0,1.0); glVertex3f(current_texture->x2,current_texture->y2,0.0); + glTexCoord2f(0.0,1.0); glVertex3f(current_texture->x1,current_texture->y2,0.0); + glEnd(); + } + + } + glFlush(); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glPopMatrix(); +#endif + glFlush(); + SDL_GL_SwapBuffers(); + glDisable(GL_LIGHTING); +} + + +void openGL_closeGraphics() { +} diff --git a/tb1_linux/svmwgraph/sdl_svmwgraph.c b/tb1_linux/svmwgraph/sdl_svmwgraph.c index 3408204..27714c3 100644 --- a/tb1_linux/svmwgraph/sdl_svmwgraph.c +++ b/tb1_linux/svmwgraph/sdl_svmwgraph.c @@ -1,450 +1,444 @@ -/* The SDL hooks for the Super VMW graphics library */ - -#include -#include "svmwgraph.h" -#include /* For atexit() */ - - /* Setup the Graphics */ - /* Pass '0' to auto-detect bpp */ -void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp, - int fullscreen,int verbose) -{ - SDL_Surface *sdl_screen=NULL; - int mode; - SDL_Joystick *joy; - - mode=SDL_SWSURFACE|SDL_HWPALETTE|SDL_HWSURFACE; - if (fullscreen) mode|=SDL_FULLSCREEN; - - /* Initialize the SDL library */ - if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 ) { - fprintf(stderr, - "Couldn't initialize SDL: %s\n", SDL_GetError()); - return NULL; - } - - /* Clean up on exit */ - atexit(SDL_Quit); - - /* Detect Joystick */ - if (SDL_NumJoysticks()>0){ - /* Open joystick */ - joy=SDL_JoystickOpen(0); - if (joy) { - printf("Opened Joystick 0\n"); - printf("Name: %s\n", SDL_JoystickName(0)); - SDL_JoystickEventState(SDL_ENABLE); - } - } - - - if (*bpp!=0) { - - /* Initialize the display */ - sdl_screen = SDL_SetVideoMode(*xsize, *ysize, *bpp, mode); - } - else { - sdl_screen=SDL_SetVideoMode(*xsize,*ysize,0,mode); - } - - - if ( sdl_screen == NULL ) { - fprintf(stderr, "ERROR! Couldn't set %dx%d video mode: %s\n", - *xsize,*ysize,SDL_GetError()); - return NULL; - } - - if (*bpp==0) *bpp=sdl_screen->format->BytesPerPixel*8; - if (verbose) { - printf(" + SDL Graphics Initialization successful...\n"); - printf(" + Using %dx%dx%dbpp Visual...\n",*xsize,*ysize,*bpp); -#if BYTE_ORDER==LITTLE_ENDIAN - printf(" + Little-endian byte-order detected\n"); -#else - printf(" + Big-endian byte-order detected\n"); -#endif - printf(" + Red: %x Green: %x Blue: %x Alpha: %x\n", - sdl_screen->format->Rmask, - sdl_screen->format->Gmask, - sdl_screen->format->Bmask, - sdl_screen->format->Amask); - } - return sdl_screen; -} - - -void SDL_flushPalette(vmwSVMWGraphState *state) { - - SDL_Surface *target; - SDL_Color temp_col[256]; - int i; - - if (state->bpp==8) { - for(i=0;i<256;i++) { - temp_col[i].r=(state->palette[i]>>11)<<3; - temp_col[i].g=((state->palette[i]>>5)&0x3f)<<2; - temp_col[i].b=(state->palette[i]&0x1f)<<3; - } - - target=(SDL_Surface *)state->output_screen; - - SDL_SetColors(target,temp_col,0,256); - } -} - -void SDL_NoScale32bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { - - int x,y,color; - - unsigned char *s_pointer,*t_pointer; - - SDL_Surface *target; - - target=(SDL_Surface *)target_p->output_screen; - - if ( SDL_MUSTLOCK(target) ) { - if ( SDL_LockSurface(target) < 0 ) - return; - } - - s_pointer=source->memory; - t_pointer=((Uint8 *)target->pixels); - -// printf("%i %i\n",source->xsize,source->ysize); - - for (x=0;xxsize;x++) - for (y=0;yysize;y++) { - color=SDL_MapRGB(target->format,target_p->actual_pal[*(s_pointer)].r, - target_p->actual_pal[*(s_pointer)].g, - target_p->actual_pal[*(s_pointer)].b); - - *((Uint32 *)(t_pointer))=color; - s_pointer++; t_pointer+=4; - - } - - - /* Update the display */ - if ( SDL_MUSTLOCK(target) ) { - SDL_UnlockSurface(target); - } - - /* Write this out to the screen */ - SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize); -} - - -void SDL_Double32bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { - - int x,y,scale,color; - - unsigned char *s_pointer,*t_pointer; - - SDL_Surface *target; - - target=(SDL_Surface *)target_p->output_screen; - - scale=target_p->scale; - - if ( SDL_MUSTLOCK(target) ) { - if ( SDL_LockSurface(target) < 0 ) - return; - } - - s_pointer=source->memory; - t_pointer=((Uint8 *)target->pixels); - - for(y=0;yysize;y++) { - for(x=0;xxsize;x++) { - color=SDL_MapRGB(target->format, - target_p->actual_pal[*(s_pointer)].r, - target_p->actual_pal[*(s_pointer)].g, - target_p->actual_pal[*(s_pointer)].b); - - /* i=0, j=0 */ - *((Uint32 *) ( (t_pointer)))=color; - - /* i=1, j=0 */ - *((Uint32 *) ( (t_pointer+(4*target_p->xsize) )))=color; - - /* i=0, j=1 */ - *((Uint32 *) ( (t_pointer+4) ))=color; - - /* i=1 j=1 */ - *((Uint32 *) ( (t_pointer+4+(4*target_p->xsize) )))=color; - - s_pointer++; t_pointer+=8; - } - t_pointer+=4*target_p->xsize; - } - - /* Update the display */ - if ( SDL_MUSTLOCK(target) ) { - SDL_UnlockSurface(target); - } - - /* Write this out to the screen */ - SDL_UpdateRect(target, 0, 0, target_p->xsize, target_p->ysize); -} - - -void SDL_NoScale16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { - - int x,y; - - unsigned char *s_pointer,*t_pointer; - - SDL_Surface *target; - - target=(SDL_Surface *)target_p->output_screen; - - if ( SDL_MUSTLOCK(target) ) { - if ( SDL_LockSurface(target) < 0 ) - return; - } - - s_pointer=source->memory; - t_pointer=((Uint8 *)target->pixels); - -// printf("%i %i\n",source->xsize,source->ysize); - - for (x=0;xxsize;x++) - for (y=0;yysize;y++) { - *((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)]; - s_pointer++; t_pointer+=2; - } - - - /* Update the display */ - if ( SDL_MUSTLOCK(target) ) { - SDL_UnlockSurface(target); - } - - /* Write this out to the screen */ - SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize); - -} - - /* I should make this generic, but it makes it really slow */ -void SDL_Double16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { - - int x,y,scale; - - unsigned char *s_pointer,*t_pointer; - - SDL_Surface *target; - - target=(SDL_Surface *)target_p->output_screen; - - scale=target_p->scale; - - if ( SDL_MUSTLOCK(target) ) { - if ( SDL_LockSurface(target) < 0 ) - return; - } - - s_pointer=source->memory; - t_pointer=((Uint8 *)target->pixels); - - for (y=0;yysize;y++) { - for (x=0;xxsize;x++) { - - /* i=0, j=0 */ - *((Uint16 *) ( (t_pointer)))= - target_p->palette[*(s_pointer)]; - - /* i=1, j=0 */ - *((Uint16 *) ( (t_pointer+(2*target_p->xsize) )))= - target_p->palette[*(s_pointer)]; - /* i=0, j=1 */ - *((Uint16 *) ( (t_pointer+2) ))= - target_p->palette[*(s_pointer)]; - - /* i=1 j=1 */ - *((Uint16 *) ( (t_pointer+2+(2*target_p->xsize) )))= - target_p->palette[*(s_pointer)]; - - - s_pointer++; t_pointer+=4; - } - t_pointer+=2*target_p->xsize; - } - - - /* Update the display */ - if ( SDL_MUSTLOCK(target) ) { - SDL_UnlockSurface(target); - } - - /* Write this out to the screen */ - SDL_UpdateRect(target, 0, 0, target_p->xsize, target_p->ysize); - -} - -void SDL_NoScale8bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { - - int x,y; - - unsigned char *s_pointer,*t_pointer; - - SDL_Surface *target; - - target=(SDL_Surface *)target_p->output_screen; - - if ( SDL_MUSTLOCK(target) ) { - if ( SDL_LockSurface(target) < 0 ) - return; - } - - s_pointer=source->memory; - t_pointer=((Uint8 *)target->pixels); - - for (x=0;xxsize;x++) - for (y=0;yysize;y++) { - *((Uint8 *)(t_pointer))=*(s_pointer); - s_pointer++; t_pointer++; - } - - - /* Update the display */ - if ( SDL_MUSTLOCK(target) ) { - SDL_UnlockSurface(target); - } - - /* Write this out to the screen */ - SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize); - -} - - -void SDL_Double8bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { - - int x,y; - - unsigned char *s_pointer,*t_pointer; - - SDL_Surface *target; - - target=(SDL_Surface *)target_p->output_screen; - - if ( SDL_MUSTLOCK(target) ) { - if ( SDL_LockSurface(target) < 0 ) - return; - } - - s_pointer=source->memory; - t_pointer=((Uint8 *)target->pixels); - - for (y=0;yysize;y++) { - for (x=0;xxsize;x++) { - /* i=0, j=0 */ - *((Uint8 *)(t_pointer))=*(s_pointer); - /* i=1, j=0 */ - *((Uint8 *)(t_pointer+(target_p->xsize)))=*(s_pointer); - /* i=0, j=1 */ - *((Uint8 *)(t_pointer+1))=*(s_pointer); - /* i=1, j=1 */ - *((Uint8 *)(t_pointer+1+target_p->xsize))=*(s_pointer); - s_pointer++; t_pointer+=2; - } - t_pointer+=target_p->xsize; - } - - /* Update the display */ - if ( SDL_MUSTLOCK(target) ) { - SDL_UnlockSurface(target); - } - - /* Write this out to the screen */ - SDL_UpdateRect(target, 0, 0, target_p->xsize, target_p->ysize); - -} - - -void SDL_clearKeyboardBuffer() { - SDL_Event event; - while (SDL_PollEvent(&event)) { - - } -} - -int SDL_getInput() { - - SDL_Event event; - int keypressed,button; - int axis,direction; - - static int going_right=0; - static int going_left=0; - - while ( SDL_PollEvent(&event)) { - - switch(event.type) { - case SDL_JOYBUTTONDOWN: - button=event.jbutton.button; -// printf("BUTTON %i\n",button); - switch(button) { - case 0: return ' '; - case 1: return VMW_ENTER; - } - break; - case SDL_JOYAXISMOTION: - axis=event.jaxis.axis; - direction=event.jaxis.value; -// printf("%i %i\n",axis,direction); - if (axis==0) { /* X */ - - if (direction>5000) { - if (!going_right) { - going_right=1; - return VMW_RIGHT; - } - } - else if (direction<-5000) { - if (!going_left) { - going_left=1; - return VMW_LEFT; - } - } - else { - going_left=0; - going_right=0; - } - } -// if (axis==1) { /* Y */ -// if (direction>0) return VMW_UP; -// if (direction<0) return VMW_DOWN; -// } - - break; - case SDL_KEYDOWN: - keypressed=event.key.keysym.sym; - switch (keypressed) { - case SDLK_BACKSPACE: return VMW_BACKSPACE; - case SDLK_ESCAPE : return VMW_ESCAPE; - case SDLK_RETURN : return VMW_ENTER; - case SDLK_UP : return VMW_UP; - case SDLK_DOWN : return VMW_DOWN; - case SDLK_RIGHT : return VMW_RIGHT; - case SDLK_LEFT : return VMW_LEFT; - case SDLK_F1 : return VMW_F1; - case SDLK_F2 : return VMW_F2; - case SDLK_PAGEUP : return VMW_PGUP; - case SDLK_PAGEDOWN : return VMW_PGDN; - case SDLK_HOME : return VMW_HOME; - case SDLK_END : return VMW_END; - case SDLK_INSERT : return VMW_INS; - case SDLK_DELETE : return VMW_DEL; - default: if ((keypressed>='a') && (keypressed<='z') - && (event.key.keysym.mod & KMOD_SHIFT) ) - return keypressed-32; - else return keypressed; - } - default: break; - } - } - return 0; -} - -void SDL_closeGraphics() { -} +/* The SDL hooks for the Super VMW graphics library */ + +#include +#include "svmwgraph.h" +#include /* For atexit() */ + + /* Setup the Graphics */ + /* Pass '0' to auto-detect bpp */ +void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp, + int fullscreen,int verbose) +{ + SDL_Surface *sdl_screen=NULL; + int mode; + SDL_Joystick *joy; + + mode=SDL_SWSURFACE|SDL_HWPALETTE|SDL_HWSURFACE; + if (fullscreen) mode|=SDL_FULLSCREEN; + + /* Initialize the SDL library */ + if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 ) { + fprintf(stderr, + "Couldn't initialize SDL: %s\n", SDL_GetError()); + return NULL; + } + + /* Clean up on exit */ + atexit(SDL_Quit); + + /* Detect Joystick */ + if (SDL_NumJoysticks()>0){ + /* Open joystick */ + joy=SDL_JoystickOpen(0); + if (joy) { + printf("Opened Joystick 0\n"); + printf("Name: %s\n", SDL_JoystickName(0)); + SDL_JoystickEventState(SDL_ENABLE); + } + } + + + if (*bpp!=0) { + + /* Initialize the display */ + sdl_screen = SDL_SetVideoMode(*xsize, *ysize, *bpp, mode); + } + else { + sdl_screen=SDL_SetVideoMode(*xsize,*ysize,0,mode); + } + + + if ( sdl_screen == NULL ) { + fprintf(stderr, "ERROR! Couldn't set %dx%d video mode: %s\n", + *xsize,*ysize,SDL_GetError()); + return NULL; + } + + if (*bpp==0) *bpp=sdl_screen->format->BytesPerPixel*8; + if (verbose) { + printf(" + SDL Graphics Initialization successful...\n"); + printf(" + Using %dx%dx%dbpp Visual...\n",*xsize,*ysize,*bpp); +#if BYTE_ORDER==LITTLE_ENDIAN + printf(" + Little-endian byte-order detected\n"); +#else + printf(" + Big-endian byte-order detected\n"); +#endif + printf(" + Red: %x Green: %x Blue: %x Alpha: %x\n", + sdl_screen->format->Rmask, + sdl_screen->format->Gmask, + sdl_screen->format->Bmask, + sdl_screen->format->Amask); + } + return sdl_screen; +} + + +void SDL_flushPalette(vmwSVMWGraphState *state) { + + SDL_Surface *target; + SDL_Color temp_col[256]; + int i; + + if (state->bpp==8) { + for(i=0;i<256;i++) { + temp_col[i].r=(state->palette[i]>>11)<<3; + temp_col[i].g=((state->palette[i]>>5)&0x3f)<<2; + temp_col[i].b=(state->palette[i]&0x1f)<<3; + } + + target=(SDL_Surface *)state->output_screen; + + SDL_SetColors(target,temp_col,0,256); + } +} + +void SDL_NoScale32bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { + + int x,y,color; + + unsigned char *s_pointer,*t_pointer; + + SDL_Surface *target; + + target=(SDL_Surface *)target_p->output_screen; + + if ( SDL_MUSTLOCK(target) ) { + if ( SDL_LockSurface(target) < 0 ) + return; + } + + s_pointer=source->memory; + t_pointer=((Uint8 *)target->pixels); + +// printf("%i %i\n",source->xsize,source->ysize); + + for (x=0;xxsize;x++) + for (y=0;yysize;y++) { + color=SDL_MapRGB(target->format,target_p->actual_pal[*(s_pointer)].r, + target_p->actual_pal[*(s_pointer)].g, + target_p->actual_pal[*(s_pointer)].b); + + *((Uint32 *)(t_pointer))=color; + s_pointer++; t_pointer+=4; + + } + + + /* Update the display */ + if ( SDL_MUSTLOCK(target) ) { + SDL_UnlockSurface(target); + } + + /* Write this out to the screen */ + SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize); +} + + +void SDL_Double32bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { + + int x,y,color;//,scale; + + unsigned char *s_pointer,*t_pointer; + + SDL_Surface *target; + + target=(SDL_Surface *)target_p->output_screen; + +// scale=target_p->scale; + + if ( SDL_MUSTLOCK(target) ) { + if ( SDL_LockSurface(target) < 0 ) + return; + } + + s_pointer=source->memory; + t_pointer=((Uint8 *)target->pixels); + + for(y=0;yysize;y++) { + for(x=0;xxsize;x++) { + color=SDL_MapRGB(target->format, + target_p->actual_pal[*(s_pointer)].r, + target_p->actual_pal[*(s_pointer)].g, + target_p->actual_pal[*(s_pointer)].b); + + /* i=0, j=0 */ + *((Uint32 *) ( (t_pointer)))=color; + + /* i=1, j=0 */ + *((Uint32 *) ( (t_pointer+(4*target_p->xsize) )))=color; + + /* i=0, j=1 */ + *((Uint32 *) ( (t_pointer+4) ))=color; + + /* i=1 j=1 */ + *((Uint32 *) ( (t_pointer+4+(4*target_p->xsize) )))=color; + + s_pointer++; t_pointer+=8; + } + t_pointer+=4*target_p->xsize; + } + + /* Update the display */ + if ( SDL_MUSTLOCK(target) ) { + SDL_UnlockSurface(target); + } + + /* Write this out to the screen */ + SDL_UpdateRect(target, 0, 0, target_p->xsize, target_p->ysize); +} + + +void SDL_NoScale16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { + + int x,y; + + unsigned char *s_pointer,*t_pointer; + + SDL_Surface *target; + + target=(SDL_Surface *)target_p->output_screen; + + if ( SDL_MUSTLOCK(target) ) { + if ( SDL_LockSurface(target) < 0 ) + return; + } + + s_pointer=source->memory; + t_pointer=((Uint8 *)target->pixels); + +// printf("%i %i\n",source->xsize,source->ysize); + + for (x=0;xxsize;x++) + for (y=0;yysize;y++) { + *((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)]; + s_pointer++; t_pointer+=2; + } + + /* Update the display */ + if ( SDL_MUSTLOCK(target) ) { + SDL_UnlockSurface(target); + } + + /* Write this out to the screen */ + SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize); + +} + + /* I should make this generic, but it makes it really slow */ +void SDL_Double16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { + + int x,y; + + unsigned char *s_pointer,*t_pointer; + + SDL_Surface *target; + + target=(SDL_Surface *)target_p->output_screen; + + //scale=target_p->scale; + + if ( SDL_MUSTLOCK(target) ) { + if ( SDL_LockSurface(target) < 0 ) + return; + } + + s_pointer=source->memory; + t_pointer=((Uint8 *)target->pixels); + + for (y=0;yysize;y++) { + for (x=0;xxsize;x++) { + + /* i=0, j=0 */ + *((Uint16 *) ( (t_pointer)))= + target_p->palette[*(s_pointer)]; + + /* i=1, j=0 */ + *((Uint16 *) ( (t_pointer+(2*target_p->xsize) )))= + target_p->palette[*(s_pointer)]; + /* i=0, j=1 */ + *((Uint16 *) ( (t_pointer+2) ))= + target_p->palette[*(s_pointer)]; + + /* i=1 j=1 */ + *((Uint16 *) ( (t_pointer+2+(2*target_p->xsize) )))= + target_p->palette[*(s_pointer)]; + + s_pointer++; t_pointer+=4; + } + t_pointer+=2*target_p->xsize; + } + + /* Update the display */ + if ( SDL_MUSTLOCK(target) ) { + SDL_UnlockSurface(target); + } + + /* Write this out to the screen */ + SDL_UpdateRect(target, 0, 0, target_p->xsize, target_p->ysize); + +} + +void SDL_NoScale8bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { + + int x,y; + + unsigned char *s_pointer,*t_pointer; + + SDL_Surface *target; + + target=(SDL_Surface *)target_p->output_screen; + + if ( SDL_MUSTLOCK(target) ) { + if ( SDL_LockSurface(target) < 0 ) + return; + } + + s_pointer=source->memory; + t_pointer=((Uint8 *)target->pixels); + + for (x=0;xxsize;x++) + for (y=0;yysize;y++) { + *((Uint8 *)(t_pointer))=*(s_pointer); + s_pointer++; t_pointer++; + } + + /* Update the display */ + if ( SDL_MUSTLOCK(target) ) { + SDL_UnlockSurface(target); + } + + /* Write this out to the screen */ + SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize); + +} + + +void SDL_Double8bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { + + int x,y; + + unsigned char *s_pointer,*t_pointer; + + SDL_Surface *target; + + target=(SDL_Surface *)target_p->output_screen; + + if ( SDL_MUSTLOCK(target) ) { + if ( SDL_LockSurface(target) < 0 ) + return; + } + + s_pointer=source->memory; + t_pointer=((Uint8 *)target->pixels); + + for (y=0;yysize;y++) { + for (x=0;xxsize;x++) { + /* i=0, j=0 */ + *((Uint8 *)(t_pointer))=*(s_pointer); + /* i=1, j=0 */ + *((Uint8 *)(t_pointer+(target_p->xsize)))=*(s_pointer); + /* i=0, j=1 */ + *((Uint8 *)(t_pointer+1))=*(s_pointer); + /* i=1, j=1 */ + *((Uint8 *)(t_pointer+1+target_p->xsize))=*(s_pointer); + s_pointer++; t_pointer+=2; + } + t_pointer+=target_p->xsize; + } + + /* Update the display */ + if ( SDL_MUSTLOCK(target) ) { + SDL_UnlockSurface(target); + } + + /* Write this out to the screen */ + SDL_UpdateRect(target, 0, 0, target_p->xsize, target_p->ysize); +} + + +void SDL_clearKeyboardBuffer(void) { + SDL_Event event; + while (SDL_PollEvent(&event)) { + } +} + +int SDL_getInput(void) { + + SDL_Event event; + int keypressed,button; + int axis,direction; + + static int going_right=0; + static int going_left=0; + + while ( SDL_PollEvent(&event)) { + + switch(event.type) { + case SDL_JOYBUTTONDOWN: + button=event.jbutton.button; +// printf("BUTTON %i\n",button); + switch(button) { + case 0: return ' '; + case 1: return VMW_ENTER; + } + break; + case SDL_JOYAXISMOTION: + axis=event.jaxis.axis; + direction=event.jaxis.value; +// printf("%i %i\n",axis,direction); + if (axis==0) { /* X */ + + if (direction>5000) { + if (!going_right) { + going_right=1; + return VMW_RIGHT; + } + } + else if (direction<-5000) { + if (!going_left) { + going_left=1; + return VMW_LEFT; + } + } + else { + going_left=0; + going_right=0; + } + } +// if (axis==1) { /* Y */ +// if (direction>0) return VMW_UP; +// if (direction<0) return VMW_DOWN; +// } + + break; + case SDL_KEYDOWN: + keypressed=event.key.keysym.sym; + switch (keypressed) { + case SDLK_BACKSPACE: return VMW_BACKSPACE; + case SDLK_ESCAPE : return VMW_ESCAPE; + case SDLK_RETURN : return VMW_ENTER; + case SDLK_UP : return VMW_UP; + case SDLK_DOWN : return VMW_DOWN; + case SDLK_RIGHT : return VMW_RIGHT; + case SDLK_LEFT : return VMW_LEFT; + case SDLK_F1 : return VMW_F1; + case SDLK_F2 : return VMW_F2; + case SDLK_PAGEUP : return VMW_PGUP; + case SDLK_PAGEDOWN : return VMW_PGDN; + case SDLK_HOME : return VMW_HOME; + case SDLK_END : return VMW_END; + case SDLK_INSERT : return VMW_INS; + case SDLK_DELETE : return VMW_DEL; + default: if ((keypressed>='a') && (keypressed<='z') + && (event.key.keysym.mod & KMOD_SHIFT) ) + return keypressed-32; + else return keypressed; + } + default: break; + } + } + return 0; +} + +void SDL_closeGraphics() { +} diff --git a/tb1_linux/svmwgraph/vmw_paintpro.c b/tb1_linux/svmwgraph/vmw_paintpro.c index 2304a9b..aa6d0a6 100644 --- a/tb1_linux/svmwgraph/vmw_paintpro.c +++ b/tb1_linux/svmwgraph/vmw_paintpro.c @@ -1,334 +1,335 @@ -/* An implementation of my own legacy "PaintPro[gram] graphics format */ - -/* The format is seemingly very random, but it was sort of OK for */ -/* my skill level at the time */ - -/* Version 1 was just, in text ASCII, a list of COLOR followed on a - * new line by num-across, a very primitive RLE [Run-Length-Encoding] - * Compression scheme [which I thought up on my own] */ - -/* Later versions supported 256 color mode, and made sure the BASIC - * loader worked */ - -/* There was an actual "PaintPro program, written in TurboPascal - * that was fairly decent considering. It would edit in - * the EGA and VGA 16 color modes, and later mode13 320x200x256 */ - -/* The files were still pretty large, so Version 5 implemented - * "Packing", basically shoving the color and numacross into - * a 24 bit value. This, along with block-reading rapidly - * reduced load times */ - -/* Version 6 added a fancy header, along with palette saving, and - * an optimization of storing multiple 1-pixel runs in half the size. - * Before this palette files were stored separately. */ - -/* The resulting file format is very similar [quite accidentally] to - * the PCX file format. Why don't I make paintpro files obsolete? - * nostalgia mostly. */ - -/* Paintpro files usually have the extension .AMG [AMazing Graphics, - * an inside joke], .PPP [Paint Pro Packed], .PRO, or .TB1 [from - * Tom Bombem */ - - - - -#include "svmwgraph.h" - -#include /* For FILE I/O */ -#include /* For strncmp */ -#include /* for open() */ -#include /* for lseek() */ -#include /* for file modes */ - - - /* Take a 24bit value [3 bytes] and split the top and bottom */ - /* 12 bits into 2 integers */ -#define THREE_BYTES_INT1(a,b) ( ( ( (int)(a))<<4)+ ((b)>>4) ) -#define THREE_BYTES_INT2(b,c) ( ( ( ( (int)(b))&0x0f)<<8)+ (c)) - - /* Do the opposite. Take 2 ints and make 3 bytes */ - -#define TWO_INTS_THREE_BYTES(a,b) three_bytes[0]=((unsigned char)(((a)>>4)&0xff)); three_bytes[1]=((unsigned char) ( (((a)&0x0f)<<4)+(((b)>>8)&0x0f))); three_bytes[2]=((unsigned char)((b)&0xff)); - - -vmwPaintProHeader *vmwGetPaintProHeader(char *filename) { - - FILE *fff; - static vmwPaintProHeader *header=NULL; - unsigned char buffer[18]; - int i; - - if ( (fff=fopen(filename,"rb"))==NULL) { /* b for w32 stupidity */ - printf("Error! %s does not exist!\n",filename); - return NULL; - } - - if (fread(buffer,1,18,fff)!=18) { - printf("Error! Corrupted paintpro header!\n"); - return NULL; - } - - fclose(fff); - - if (header==NULL) { - if (( header=calloc(1,sizeof(vmwPaintProHeader)))==NULL) { - printf("Error! Seriously low on memory!\n"); - return NULL; - } - } - - /* Load PAINTPRO string */ - for(i=0;i<8;i++) header->ppro_string[i]=buffer[i]; - for(i=0;i<4;i++) header->version[i]=buffer[i+8]; - header->xsize=THREE_BYTES_INT1(buffer[12],buffer[13]); - header->ysize=THREE_BYTES_INT2(buffer[13],buffer[14]); - header->num_colors=THREE_BYTES_INT1(buffer[15],buffer[16]); - - return header; -} - - /*---------------------------------------------------------------*\ - | vmwLoadPicPacked | - | There is so much history in this function, I won't get into | - | it here. See the paintpro documentation found elsewhere | - \*---------------------------------------------------------------*/ - -int vmwLoadPicPacked(int x1,int y1,vmwVisual *target, - int LoadPal,int LoadPic,char *FileName, - vmwSVMWGraphState *graph_state) - - /* Retro comments */ -/*{ Loads a paintpro image, filename, at location x1,y1 *\ -\* to offset where (vga=$A000) and loadspal if LOADPAL=true */ -/* Loadsapicture if Loadpic=true and returns error} */ - -{ - int x,y,i; - int ppro_fd; - int color,numacross; - int read_status; - vmwPaintProHeader *ppro_header; - unsigned char three_bytes[3]; - int broken=0; - - if ( (ppro_header=vmwGetPaintProHeader(FileName))==NULL) { - printf("ERROR! Invalid Header in %s!\n",FileName); - return VMW_ERROR_FILE; - } - - /* Open the file */ - ppro_fd=open(FileName,O_RDONLY); - - if (ppro_fd<0) { - printf("ERROR! File \"%s\" not found!\n",FileName); - return VMW_ERROR_FILE; - } - - /* Check to see if its really a Paintpro File */ - if (strncmp(ppro_header->ppro_string,"PAINTPRO",8)) { - printf("ERROR! %s is NOT a paintpro file!\n",FileName); - return VMW_ERROR_INVALID; - } - - /* Check to see if it is the proper version (currently 6.0) */ - if (strncmp(ppro_header->version,"V6.1",4)) { - if (!strncmp(ppro_header->version,"V6.0",4)) { - printf("Warning! Broken 6.0 file! Please convert.\n"); - broken=1; - } - else { - printf("ERROR! %s unsupported, must be >=6.0\n", - ppro_header->version); - return VMW_ERROR_INVALID; - } - } - - /*Load Palette*/ - if (ppro_header->num_colors>256) - printf("More than 256 colors not supported yet (%d)\n", - ppro_header->num_colors); - - /* Seek past the header */ - lseek(ppro_fd,18,SEEK_SET); - - /* Fun and games to convert the 24 bit color in paintpro to */ - /* 565 packed 16bit RGB */ - - if (!LoadPal) { - /* Skip past palette if not loading it */ - lseek(ppro_fd,3*ppro_header->num_colors,SEEK_CUR); - } - else { - for(i=0;inum_colors;i++) { - read_status=read(ppro_fd,&three_bytes,3); - vmwLoadPalette(graph_state, - three_bytes[0], - three_bytes[1], - three_bytes[2],i); - } - vmwFlushPalette(graph_state); - } - - if (!LoadPic) { - close(ppro_fd); - return 0; /* We already loaded the palette */ - } - - x=x1; - y=y1; - - while (yysize) { - /* Read in next 3 bytes */ - read_status=read(ppro_fd,&three_bytes,3); - - /* If we read less than 3, something is wrong */ - if (read_status<3) { - printf("Ran out of data too soon!\n"); - break; - } - - color=THREE_BYTES_INT1(three_bytes[0],three_bytes[1]); - numacross=THREE_BYTES_INT2(three_bytes[1],three_bytes[2]); - - /* If int1 greater than 2047, we have two single pixels */ - /* of color int1-2048 and int2-2048 */ - if (color>2047) { - vmwPutPixel(x,y,color-2048,target); - x++; - if (x>=ppro_header->xsize+x1) { - x=x1; y++; - } - vmwPutPixel(x,y,numacross-2048,target); - x++; - if (x>=ppro_header->xsize+x1){ - x=x1;y++; - } - } - else { /* Standard paintpro format */ - /* Wrap if numacross is bigger than width */ - while ((x+numacross)>=(ppro_header->xsize+x1)) { - vmwDrawHLine(x,y,((ppro_header->xsize+x1)-x),color,target); - /* Old versions of paintro created broken */ - /* Files which need an extra +1 after xsize */ - /* In the following line */ - numacross=numacross-((ppro_header->xsize+broken)-x); - x=x1; - y++; - } - - if (numacross!=0) { - if (y>=y1+ppro_header->ysize) { - printf("Trying to draw past end of screen %d\n",y); - } - if (numacross > ppro_header->xsize-1) { - printf("X too big?%d\n",numacross); - } - vmwDrawHLine(x,y,numacross,color,target); - } - x=x+numacross; - } - } - close(ppro_fd); - return 0; -} - -int vmwSavePicPacked(int x1,int y1,int xsize,int ysize, - vmwVisual *source, - int num_colors, - vmw24BitPal *palette, - char *FileName) { - - int ppro_fd,i,x,y,color=0,oldcolor=-1,numacross=0; - int already_have_single_pixel=0; - int save_pixel=0; - char ppro_string[]="PAINTPRO"; - char ppro_version[]="V6.1"; - unsigned char three_bytes[3]; - - ppro_fd=open(FileName,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR); - if (ppro_fd<0) { - printf("Error opening \"%s\" for writing!\n",FileName); - return VMW_ERROR_FILE; - } - - /* 8 bytes, "PAINTPRO" */ - write(ppro_fd,ppro_string,8); - /* 4 bytes, "V6.0" */ - write(ppro_fd,ppro_version,4); - - /* xsize, ysize */ - TWO_INTS_THREE_BYTES(xsize,ysize); - write(ppro_fd,three_bytes,3); - /* num_colors, 0 */ - TWO_INTS_THREE_BYTES(num_colors,0); - write(ppro_fd,three_bytes,3); - - /* Write num_colors r,g,b */ - for(i=0;i=x1+xsize) { - x=x1; - y++; - } - } - /* Write out data left */ - if (already_have_single_pixel) { - /* Oops.. wanted to pack, but we can't */ - TWO_INTS_THREE_BYTES(save_pixel,1); - write(ppro_fd,three_bytes,3); - } - - /* Write out the last run */ - TWO_INTS_THREE_BYTES(color,numacross); - write(ppro_fd,three_bytes,3); - - close(ppro_fd); - return 0; - -} +/* An implementation of my own legacy "PaintPro[gram] graphics format */ + +/* The format is seemingly very random, but it was sort of OK for */ +/* my skill level at the time */ + +/* Version 1 was just, in text ASCII, a list of COLOR followed on a + * new line by num-across, a very primitive RLE [Run-Length-Encoding] + * Compression scheme [which I thought up on my own] */ + +/* Later versions supported 256 color mode, and made sure the BASIC + * loader worked */ + +/* There was an actual "PaintPro program, written in TurboPascal + * that was fairly decent considering. It would edit in + * the EGA and VGA 16 color modes, and later mode13 320x200x256 */ + +/* The files were still pretty large, so Version 5 implemented + * "Packing", basically shoving the color and numacross into + * a 24 bit value. This, along with block-reading rapidly + * reduced load times */ + +/* Version 6 added a fancy header, along with palette saving, and + * an optimization of storing multiple 1-pixel runs in half the size. + * Before this palette files were stored separately. */ + +/* The resulting file format is very similar [quite accidentally] to + * the PCX file format. Why don't I make paintpro files obsolete? + * nostalgia mostly. */ + +/* Paintpro files usually have the extension .AMG [AMazing Graphics, + * an inside joke], .PPP [Paint Pro Packed], .PRO, or .TB1 [from + * Tom Bombem */ + + + + +#include "svmwgraph.h" + +#include /* For FILE I/O */ +#include /* For strncmp */ +#include /* for open() */ +#include /* for lseek() */ +#include /* for calloc() */ +#include /* for file modes */ + + + /* Take a 24bit value [3 bytes] and split the top and bottom */ + /* 12 bits into 2 integers */ +#define THREE_BYTES_INT1(a,b) ( ( ( (int)(a))<<4)+ ((b)>>4) ) +#define THREE_BYTES_INT2(b,c) ( ( ( ( (int)(b))&0x0f)<<8)+ (c)) + + /* Do the opposite. Take 2 ints and make 3 bytes */ + +#define TWO_INTS_THREE_BYTES(a,b) three_bytes[0]=((unsigned char)(((a)>>4)&0xff)); three_bytes[1]=((unsigned char) ( (((a)&0x0f)<<4)+(((b)>>8)&0x0f))); three_bytes[2]=((unsigned char)((b)&0xff)); + + +vmwPaintProHeader *vmwGetPaintProHeader(char *filename) { + + FILE *fff; + static vmwPaintProHeader *header=NULL; + unsigned char buffer[18]; + int i; + + if ( (fff=fopen(filename,"rb"))==NULL) { /* b for w32 stupidity */ + printf("Error! %s does not exist!\n",filename); + return NULL; + } + + if (fread(buffer,1,18,fff)!=18) { + printf("Error! Corrupted paintpro header!\n"); + return NULL; + } + + fclose(fff); + + if (header==NULL) { + if (( header=calloc(1,sizeof(vmwPaintProHeader)))==NULL) { + printf("Error! Seriously low on memory!\n"); + return NULL; + } + } + + /* Load PAINTPRO string */ + for(i=0;i<8;i++) header->ppro_string[i]=buffer[i]; + for(i=0;i<4;i++) header->version[i]=buffer[i+8]; + header->xsize=THREE_BYTES_INT1(buffer[12],buffer[13]); + header->ysize=THREE_BYTES_INT2(buffer[13],buffer[14]); + header->num_colors=THREE_BYTES_INT1(buffer[15],buffer[16]); + + return header; +} + + /*---------------------------------------------------------------*\ + | vmwLoadPicPacked | + | There is so much history in this function, I won't get into | + | it here. See the paintpro documentation found elsewhere | + \*---------------------------------------------------------------*/ + +int vmwLoadPicPacked(int x1,int y1,vmwVisual *target, + int LoadPal,int LoadPic,char *FileName, + vmwSVMWGraphState *graph_state) + + /* Retro comments */ +/*{ Loads a paintpro image, filename, at location x1,y1 *\ +\* to offset where (vga=$A000) and loadspal if LOADPAL=true */ +/* Loadsapicture if Loadpic=true and returns error} */ + +{ + int x,y,i; + int ppro_fd; + int color,numacross; + int read_status; + vmwPaintProHeader *ppro_header; + unsigned char three_bytes[3]; + int broken=0; + + if ( (ppro_header=vmwGetPaintProHeader(FileName))==NULL) { + printf("ERROR! Invalid Header in %s!\n",FileName); + return VMW_ERROR_FILE; + } + + /* Open the file */ + ppro_fd=open(FileName,O_RDONLY); + + if (ppro_fd<0) { + printf("ERROR! File \"%s\" not found!\n",FileName); + return VMW_ERROR_FILE; + } + + /* Check to see if its really a Paintpro File */ + if (strncmp(ppro_header->ppro_string,"PAINTPRO",8)) { + printf("ERROR! %s is NOT a paintpro file!\n",FileName); + return VMW_ERROR_INVALID; + } + + /* Check to see if it is the proper version (currently 6.0) */ + if (strncmp(ppro_header->version,"V6.1",4)) { + if (!strncmp(ppro_header->version,"V6.0",4)) { + printf("Warning! Broken 6.0 file! Please convert.\n"); + broken=1; + } + else { + printf("ERROR! %s unsupported, must be >=6.0\n", + ppro_header->version); + return VMW_ERROR_INVALID; + } + } + + /*Load Palette*/ + if (ppro_header->num_colors>256) + printf("More than 256 colors not supported yet (%d)\n", + ppro_header->num_colors); + + /* Seek past the header */ + lseek(ppro_fd,18,SEEK_SET); + + /* Fun and games to convert the 24 bit color in paintpro to */ + /* 565 packed 16bit RGB */ + + if (!LoadPal) { + /* Skip past palette if not loading it */ + lseek(ppro_fd,3*ppro_header->num_colors,SEEK_CUR); + } + else { + for(i=0;inum_colors;i++) { + read_status=read(ppro_fd,&three_bytes,3); + vmwLoadPalette(graph_state, + three_bytes[0], + three_bytes[1], + three_bytes[2],i); + } + vmwFlushPalette(graph_state); + } + + if (!LoadPic) { + close(ppro_fd); + return 0; /* We already loaded the palette */ + } + + x=x1; + y=y1; + + while (yysize) { + /* Read in next 3 bytes */ + read_status=read(ppro_fd,&three_bytes,3); + + /* If we read less than 3, something is wrong */ + if (read_status<3) { + printf("Ran out of data too soon!\n"); + break; + } + + color=THREE_BYTES_INT1(three_bytes[0],three_bytes[1]); + numacross=THREE_BYTES_INT2(three_bytes[1],three_bytes[2]); + + /* If int1 greater than 2047, we have two single pixels */ + /* of color int1-2048 and int2-2048 */ + if (color>2047) { + vmwPutPixel(x,y,color-2048,target); + x++; + if (x>=ppro_header->xsize+x1) { + x=x1; y++; + } + vmwPutPixel(x,y,numacross-2048,target); + x++; + if (x>=ppro_header->xsize+x1){ + x=x1;y++; + } + } + else { /* Standard paintpro format */ + /* Wrap if numacross is bigger than width */ + while ((x+numacross)>=(ppro_header->xsize+x1)) { + vmwDrawHLine(x,y,((ppro_header->xsize+x1)-x),color,target); + /* Old versions of paintro created broken */ + /* Files which need an extra +1 after xsize */ + /* In the following line */ + numacross=numacross-((ppro_header->xsize+broken)-x); + x=x1; + y++; + } + + if (numacross!=0) { + if (y>=y1+ppro_header->ysize) { + printf("Trying to draw past end of screen %d\n",y); + } + if (numacross > ppro_header->xsize-1) { + printf("X too big?%d\n",numacross); + } + vmwDrawHLine(x,y,numacross,color,target); + } + x=x+numacross; + } + } + close(ppro_fd); + return 0; +} + +int vmwSavePicPacked(int x1,int y1,int xsize,int ysize, + vmwVisual *source, + int num_colors, + vmw24BitPal *palette, + char *FileName) { + + int ppro_fd,i,x,y,color=0,oldcolor=-1,numacross=0; + int already_have_single_pixel=0; + int save_pixel=0; + char ppro_string[]="PAINTPRO"; + char ppro_version[]="V6.1"; + unsigned char three_bytes[3]; + + ppro_fd=open(FileName,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR); + if (ppro_fd<0) { + printf("Error opening \"%s\" for writing!\n",FileName); + return VMW_ERROR_FILE; + } + + /* 8 bytes, "PAINTPRO" */ + write(ppro_fd,ppro_string,8); + /* 4 bytes, "V6.0" */ + write(ppro_fd,ppro_version,4); + + /* xsize, ysize */ + TWO_INTS_THREE_BYTES(xsize,ysize); + write(ppro_fd,three_bytes,3); + /* num_colors, 0 */ + TWO_INTS_THREE_BYTES(num_colors,0); + write(ppro_fd,three_bytes,3); + + /* Write num_colors r,g,b */ + for(i=0;i=x1+xsize) { + x=x1; + y++; + } + } + /* Write out data left */ + if (already_have_single_pixel) { + /* Oops.. wanted to pack, but we can't */ + TWO_INTS_THREE_BYTES(save_pixel,1); + write(ppro_fd,three_bytes,3); + } + + /* Write out the last run */ + TWO_INTS_THREE_BYTES(color,numacross); + write(ppro_fd,three_bytes,3); + + close(ppro_fd); + return 0; + +} diff --git a/tb1_linux/svmwgraph/vmw_pcx.c b/tb1_linux/svmwgraph/vmw_pcx.c index 4e72d9e..4e6d4fe 100644 --- a/tb1_linux/svmwgraph/vmw_pcx.c +++ b/tb1_linux/svmwgraph/vmw_pcx.c @@ -1,306 +1,303 @@ -/* WARNING! These functions only work at 320x200x8bpp right now */ - -/* It is easy to obtain the docs to make this load/save arbitrary */ -/* PCX files. However, I don't have the time nor the inclination */ -/* To do it right now ;) */ - -/* Routines to Load/Save PCX graphics files. */ - -#include "svmwgraph.h" - -#include /* For FILE I/O */ -#include /* For strncmp */ -#include /* for open() */ -#include /* for lseek() */ -#include /* for file modes */ - - -int vmwGetPCXInfo(char *FileName, int *xsize, int *ysize, int *type) { - - unsigned char pcx_header[128]; - int xmin,ymin,xmax,ymax,version=PCX_UNKNOWN,bpp,debug=1,pcx_fd; - - /* Open the file */ - pcx_fd=open(FileName,O_RDONLY); - - if (pcx_fd<0) { - printf("ERROR! File \"%s\" not found!\n",FileName); - return VMW_ERROR_FILE; - } - - lseek(pcx_fd,0,SEEK_SET); - - read(pcx_fd,&pcx_header,128); - - xmin=(pcx_header[5]<<8)+pcx_header[4]; - ymin=(pcx_header[7]<<8)+pcx_header[6]; - - xmax=(pcx_header[9]<<8)+pcx_header[8]; - ymax=(pcx_header[11]<<8)+pcx_header[10]; - - version=pcx_header[1]; - bpp=pcx_header[3]; - - if (debug) { - - printf("Manufacturer: "); - if (pcx_header[0]==10) printf("Zsoft\n"); - else printf("Unknown %i\n",pcx_header[0]); - - printf("Version: "); - - switch(version) { - case 0: printf("2.5\n"); break; - case 2: printf("2.8 w palette\n"); break; - case 3: printf("2.8 w/o palette\n"); break; - case 4: printf("Paintbrush for Windows\n"); break; - case 5: printf("3.0+\n"); break; - default: printf("Unknown %i\n",version); - } - printf("Encoding: "); - if (pcx_header[2]==1) printf("RLE\n"); - else printf("Unknown %i\n",pcx_header[2]); - - printf("BitsPerPixelPerPlane: %i\n",bpp); - printf("File goes from %i,%i to %i,%i\n",xmin,ymin,xmax,ymax); - - printf("Horizontal DPI: %i\n",(pcx_header[13]<<8)+pcx_header[12]); - printf("Vertical DPI: %i\n",(pcx_header[15]<<8)+pcx_header[14]); - - printf("Number of colored planes: %i\n",pcx_header[65]); - printf("Bytes per line: %i\n",(pcx_header[67]<<8)+pcx_header[66]); - printf("Palette Type: %i\n",(pcx_header[69]<<8)+pcx_header[68]); - printf("Hscreen Size: %i\n",(pcx_header[71]<<8)+pcx_header[70]); - printf("Vscreen Size: %i\n",(pcx_header[73]<<8)+pcx_header[72]); - - } - -// *xsize=(xmax-xmin+1); -// *ysize=(ymax-ymin+1); - *xsize=(xmax-xmin+1); - *ysize=(ymax-ymin+1); - - if ((version==5) && (bpp==8) && (pcx_header[65]==3)) *type=PCX_24BIT; - else if (version==5) *type=PCX_8BITPAL; - else *type=PCX_UNKNOWN; - - close(pcx_fd); - - return 0; -} - -int vmwLoadPCX(int x1,int y1,vmwVisual *target, - int LoadPal,int LoadPic,char *FileName, - vmwSVMWGraphState *graph_state) - -{ - - int pcx_fd,x,y,i,numacross,xsize,ysize,xmin,ymin; - unsigned int r,g,b; - int bpp,planes,bpl,xmax,ymax,version; - unsigned char pcx_header[128]; - unsigned char temp_byte; - - /* Open the file */ - pcx_fd=open(FileName,O_RDONLY); - - if (pcx_fd<0) { - printf("ERROR! File \"%s\" not found!\n",FileName); - return VMW_ERROR_FILE; - } - - - - /*************** DECODE THE HEADER *************************/ - read(pcx_fd,&pcx_header,128); - - xmin=(pcx_header[5]<<8)+pcx_header[4]; - ymin=(pcx_header[7]<<8)+pcx_header[6]; - - xmax=(pcx_header[9]<<8)+pcx_header[8]; - ymax=(pcx_header[11]<<8)+pcx_header[10]; - - version=pcx_header[1]; - bpp=pcx_header[3]; - planes=pcx_header[65]; - bpl=(pcx_header[67]<<8)+pcx_header[66]; - - xsize=((xmax-xmin)+1); - ysize=((ymax-ymin)+1); - - /* Possibly add some sanity checking in the header at some point... */ - /* Or actually even get the proper VALUES from the header. Some day... */ - - if (LoadPic) { - - - unsigned char *pointer=target->memory; - - x=0; y=0; - - while (x=x1+xsize) { - x=0; - y++; - numacross=1; -// printf("%i %i %i\n",x,y,numacross); -// fflush(stdout); - } - } - - /* Urgh obscure */ - temp_byte=12; - write(pcx_fd,&temp_byte,1); - - /* Write num_colors r,g,b */ - for(i=0;i<256;i++) { - temp_byte=palette[i].r; - write(pcx_fd,&temp_byte,1); - temp_byte=palette[i].g; - write(pcx_fd,&temp_byte,1); - temp_byte=palette[i].b; - write(pcx_fd,&temp_byte,1); - } - - close(pcx_fd); - return 0; -} +/* WARNING! These functions only work at 320x200x8bpp right now */ + +/* It is easy to obtain the docs to make this load/save arbitrary */ +/* PCX files. However, I don't have the time nor the inclination */ +/* To do it right now ;) */ + +/* Routines to Load/Save PCX graphics files. */ + +#include "svmwgraph.h" + +#include /* For FILE I/O */ +#include /* For strncmp */ +#include /* for open() */ +#include /* for lseek() */ +#include /* for calloc() */ +#include /* for file modes */ + + +int vmwGetPCXInfo(char *FileName, int *xsize, int *ysize, int *type) { + + unsigned char pcx_header[128]; + int xmin,ymin,xmax,ymax,version=PCX_UNKNOWN,bpp,debug=1,pcx_fd; + + /* Open the file */ + pcx_fd=open(FileName,O_RDONLY); + + if (pcx_fd<0) { + printf("ERROR! File \"%s\" not found!\n",FileName); + return VMW_ERROR_FILE; + } + + lseek(pcx_fd,0,SEEK_SET); + + read(pcx_fd,&pcx_header,128); + + xmin=(pcx_header[5]<<8)+pcx_header[4]; + ymin=(pcx_header[7]<<8)+pcx_header[6]; + + xmax=(pcx_header[9]<<8)+pcx_header[8]; + ymax=(pcx_header[11]<<8)+pcx_header[10]; + + version=pcx_header[1]; + bpp=pcx_header[3]; + + if (debug) { + + printf("Manufacturer: "); + if (pcx_header[0]==10) printf("Zsoft\n"); + else printf("Unknown %i\n",pcx_header[0]); + + printf("Version: "); + + switch(version) { + case 0: printf("2.5\n"); break; + case 2: printf("2.8 w palette\n"); break; + case 3: printf("2.8 w/o palette\n"); break; + case 4: printf("Paintbrush for Windows\n"); break; + case 5: printf("3.0+\n"); break; + default: printf("Unknown %i\n",version); + } + printf("Encoding: "); + if (pcx_header[2]==1) printf("RLE\n"); + else printf("Unknown %i\n",pcx_header[2]); + + printf("BitsPerPixelPerPlane: %i\n",bpp); + printf("File goes from %i,%i to %i,%i\n",xmin,ymin,xmax,ymax); + + printf("Horizontal DPI: %i\n",(pcx_header[13]<<8)+pcx_header[12]); + printf("Vertical DPI: %i\n",(pcx_header[15]<<8)+pcx_header[14]); + + printf("Number of colored planes: %i\n",pcx_header[65]); + printf("Bytes per line: %i\n",(pcx_header[67]<<8)+pcx_header[66]); + printf("Palette Type: %i\n",(pcx_header[69]<<8)+pcx_header[68]); + printf("Hscreen Size: %i\n",(pcx_header[71]<<8)+pcx_header[70]); + printf("Vscreen Size: %i\n",(pcx_header[73]<<8)+pcx_header[72]); + + } + +// *xsize=(xmax-xmin+1); +// *ysize=(ymax-ymin+1); + *xsize=(xmax-xmin+1); + *ysize=(ymax-ymin+1); + + if ((version==5) && (bpp==8) && (pcx_header[65]==3)) *type=PCX_24BIT; + else if (version==5) *type=PCX_8BITPAL; + else *type=PCX_UNKNOWN; + + close(pcx_fd); + + return 0; +} + +int vmwLoadPCX(int x1,int y1,vmwVisual *target, + int LoadPal,int LoadPic,char *FileName, + vmwSVMWGraphState *graph_state) + +{ + + int pcx_fd,x,i,numacross,xsize,ysize,xmin,ymin;//y; + unsigned int r,g,b; + int xmax,ymax;//bpl,bpp,planes,version; + unsigned char pcx_header[128]; + unsigned char temp_byte; + + /* Open the file */ + pcx_fd=open(FileName,O_RDONLY); + + if (pcx_fd<0) { + printf("ERROR! File \"%s\" not found!\n",FileName); + return VMW_ERROR_FILE; + } + + + /*************** DECODE THE HEADER *************************/ + read(pcx_fd,&pcx_header,128); + + xmin=(pcx_header[5]<<8)+pcx_header[4]; + ymin=(pcx_header[7]<<8)+pcx_header[6]; + + xmax=(pcx_header[9]<<8)+pcx_header[8]; + ymax=(pcx_header[11]<<8)+pcx_header[10]; + + //version=pcx_header[1]; + //bpp=pcx_header[3]; + //planes=pcx_header[65]; + //bpl=(pcx_header[67]<<8)+pcx_header[66]; + + xsize=((xmax-xmin)+1); + ysize=((ymax-ymin)+1); + + /* Possibly add some sanity checking in the header at some point... */ + /* Or actually even get the proper VALUES from the header. Some day... */ + + if (LoadPic) { + + + unsigned char *pointer=target->memory; + + x=0; //y=0; + + while (x=x1+xsize) { + x=0; + y++; + numacross=1; +// printf("%i %i %i\n",x,y,numacross); +// fflush(stdout); + } + } + + /* Urgh obscure */ + temp_byte=12; + write(pcx_fd,&temp_byte,1); + + /* Write num_colors r,g,b */ + for(i=0;i<256;i++) { + temp_byte=palette[i].r; + write(pcx_fd,&temp_byte,1); + temp_byte=palette[i].g; + write(pcx_fd,&temp_byte,1); + temp_byte=palette[i].b; + write(pcx_fd,&temp_byte,1); + } + + close(pcx_fd); + return 0; +} diff --git a/tb1_linux/svmwgraph/vmw_setup.c b/tb1_linux/svmwgraph/vmw_setup.c index 2059ab2..723f970 100644 --- a/tb1_linux/svmwgraph/vmw_setup.c +++ b/tb1_linux/svmwgraph/vmw_setup.c @@ -9,7 +9,7 @@ #include /* For printf */ #include /* For Memory Allocation */ -void *(*vmwSetupGraphics)(int *xsize,int *ysize, int *bpp, +void *(*vmwSetupGraphics)(int *xsize,int *ysize, int *bpp, int fullscreen,int verbose); void (*vmwBlitMemToDisplay)(vmwSVMWGraphState *display, vmwVisual *source); void (*vmwFlushPalette)(vmwSVMWGraphState *state); @@ -21,29 +21,29 @@ void (*vmwCloseGraphics)(void); vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize, int bpp,int scale,int fullscreen, int verbose) { - + vmwSVMWGraphState *temp_state; - + if ( (temp_state=calloc(1,sizeof(vmwSVMWGraphState)) )==NULL) { printf("Error allocating memory!\n"); return NULL; } /* Setup Setup routines */ switch (display_type) { - case VMW_NULLTARGET: + case VMW_NULLTARGET: vmwSetupGraphics=null_setupGraphics; break; - case VMW_CURSESTARGET: + case VMW_CURSESTARGET: #ifdef CURSES_TARGET vmwSetupGraphics=curses_setupGraphics; #endif break; - case VMW_OPENGLTARGET: + case VMW_OPENGLTARGET: #ifdef OPENGL_TARGET vmwSetupGraphics=openGL_setupGraphics; #endif break; - case VMW_SDLTARGET: + case VMW_SDLTARGET: #ifdef SDL_TARGET vmwSetupGraphics=SDL_setupGraphics; #endif @@ -51,14 +51,14 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize, default: printf("ERROR! Unknown Display Target %i.\n",display_type); return NULL; } - + temp_state->bpp=bpp; temp_state->xsize=xsize; temp_state->ysize=ysize; temp_state->scale=scale; temp_state->default_font=NULL; temp_state->palette_size=256; - + if ( (temp_state->palette=calloc(temp_state->palette_size,sizeof(int)) )==NULL) { printf("Error allocating palette of size %i!\n",temp_state->palette_size); return NULL; @@ -69,6 +69,10 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize, return NULL; } + if (vmwSetupGraphics==NULL) { + fprintf(stderr,"Unsupported graphics target!\n"); + return NULL; + } /* Attempt to get desired graphics state */ temp_state->output_screen=vmwSetupGraphics(&temp_state->xsize, @@ -76,7 +80,7 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize, &temp_state->bpp, fullscreen,verbose); if (temp_state->output_screen==NULL) return NULL; - /* Setup proper blitter and others*/ + /* Setup proper blitter and others*/ switch (display_type) { case VMW_NULLTARGET: vmwFlushPalette=null_flushPalette; diff --git a/tb1_linux/tb1.c b/tb1_linux/tb1.c index c6ec985..ee5d161 100644 --- a/tb1_linux/tb1.c +++ b/tb1_linux/tb1.c @@ -1,474 +1,477 @@ -/****************************************************************\ -\* TOM BOMBEM AND THE INVASION OF THE INANIMATE_OBJECTS */ -/* version 2.9.16 26 December 2009 *\ -\* by Vince Weaver vince@deater.net */ -/* *\ -\* Originally written in Pascal and x86 assembly for DOS */ -/* using the PCGPE code as an example in 1994 *\ -\* Ported to Linux, C, and ggi late 1997-early 1998 */ -/* Port continued to SDL in June of 2000 *\ -\* This source is released under the GPL */ -/****************************************************************/ - -#define TB1_VERSION "2.9.16" - -#include -#include /* for calloc */ -#include /* for strncpy */ -#include -#include -#include - -#include "svmwgraph/svmwgraph.h" -#include "tb1_state.h" -#include "tblib.h" -#include "sound.h" - -#include "graphic_tools.h" -#include "help.h" -#include "quit.h" -#include "story.h" -#include "credits.h" -#include "about.h" -#include "loadsave.h" -#include "options.h" -#include "playgame.h" - -int command_line_help(int show_version,char *runas) { - - if (!show_version) { - printf("Usage: %s [-curses] [-double] [-fullscreen] [-nosound]" - " [-version] [-?]\n\n",runas); - printf(" -curses : play in color text-mode\n"); - printf(" -double : play in 640x480 mode\n"); - printf(" -fullscreen : play in fullscreen mode (if available)\n"); - printf(" -nosound : disables sound within game\n"); - printf(" -opengl : play in openGL mode\n"); - printf(" -version : print version\n"); - printf(" -? : print this help message\n"); - printf("\n"); - } - return 0; -} - - -void vmw_opener(tb1_state *game_state, vmwVisual *virtual_1) { - - int x; - - for(x=0;x<256;x++) { - vmwLoadPalette(game_state->graph_state,0,0,0,x); /* 0=black */ - } - - /* Do the VMW Software Production Logo */ - for(x=0;x<=40;x++) { - vmwLoadPalette(game_state->graph_state, ((x+20)*4),0,0,100+x); - vmwLoadPalette(game_state->graph_state,0,0, ( (x+20)*4 ),141+x); - vmwLoadPalette(game_state->graph_state,0, ( (x+20)*4),0,182+x); - } - - /* Set the white color */ - vmwLoadPalette(game_state->graph_state,0xff,0xff,0xff,15); - - vmwFlushPalette(game_state->graph_state); - - /* Actually draw the stylized VMW */ - for(x=0;x<=40;x++) { - vmwDrawVLine(x+40,45,2*x,100+x,virtual_1); - vmwDrawVLine(x+120,45,2*x,141+x,virtual_1); - vmwDrawVLine(x+200,45,2*x,141+x,virtual_1); - vmwDrawVLine(x+80,125-(2*x),2*x,182+x,virtual_1); - vmwDrawVLine(x+160,125-(2*x),2*x,182+x,virtual_1); - } - for(x=40;x>0;x--){ - vmwDrawVLine(x+80,45,80-(2*x),140-x,virtual_1); - vmwDrawVLine(x+160,45,80-(2*x),181-x,virtual_1); - vmwDrawVLine(x+240,45,80-(2*x),181-x,virtual_1); - vmwDrawVLine(x+120,45+(2*x),80-(2*x),222-x,virtual_1); - vmwDrawVLine(x+200,45+(2*x),80-(2*x),222-x,virtual_1); - } - - vmwTextXY("A VMW SOFTWARE PRODUCTION",60,140, - 15,15,0,game_state->graph_state->default_font,virtual_1); - - if ((game_state->sound_possible) && (game_state->music_enabled)) { - playSound(); - } - - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - pauseawhile(5); - vmwFadeToBlack(game_state->graph_state,virtual_1,0); -} - -int main(int argc,char **argv) { - - int i,grapherror,reloadpic=0; - int ch,barpos,time_sec; - int graphics_target=VMW_SDLTARGET; - FILE *fff; - char *dir_name,options_file[BUFSIZ]; - vmwVisual *virtual_1,*virtual_2,*virtual_3; - - tb1_state *game_state; - - vmwFont *tb1_font; - - struct timeval time_info; - struct timezone dontcare; - - printf("\nTom Bombem v%s by Vince Weaver vince@deater.net\n",TB1_VERSION); - printf(" http://www.deater.net/weave/vmwprod/tb1\n\n"); - - /* Setup the game state */ - if ( (game_state=calloc(1,sizeof(tb1_state)))==NULL) { - printf("You are seriously low on RAM!\n"); - return 3; - } - - /* Some sane defaults */ - game_state->level=0; - game_state->shields=0; - game_state->score=0; - game_state->virtual_1=NULL; - game_state->virtual_2=NULL; - game_state->virtual_3=NULL; - game_state->sound_possible=1; - game_state->music_enabled=1; - game_state->sound_enabled=1; - game_state->sound_volume=5; - game_state->music_volume=5; - game_state->default_double_size=0; - game_state->default_fullscreen=0; - - /* Load saved defaults, if any */ - dir_name=check_for_tb1_directory(game_state,0); - if (dir_name==NULL) { - printf(" + No ~/.tb1 directory. Using default options.\n"); - } - else { - sprintf(options_file,"%s/options.tb1",dir_name); - fff=fopen(options_file,"r"); - if (fff==NULL) { - printf(" + No ~/.tb1/options.tb1 file. Using defaults.\n"); - } - else { - printf(" + Reading options from ~/.tb1/options.tb1\n"); - fscanf(fff,"%i %i %i %i %i %i", - &game_state->sound_enabled, - &game_state->music_enabled, - &game_state->sound_volume, - &game_state->music_volume, - &game_state->default_double_size, - &game_state->default_fullscreen); - fclose(fff); - } - } - - - /* Parse Command Line Arguments */ - i=1; - while(idefault_fullscreen=1; - break; - case 'c': - graphics_target=VMW_CURSESTARGET; - break; - case 'd': - game_state->default_double_size=1; - break; - case 'n': - game_state->sound_possible=0; - printf(" + Sound totally disabled\n"); - break; - case 'o': - graphics_target=VMW_OPENGLTARGET; - break; - default : - command_line_help(0,argv[0]); - printf("Unknown Option: %s\n\n",argv[i]); - return 5; - } - } - else { - command_line_help(0,argv[0]); - printf("Unknown Option: %s\n\n",argv[i]); - return 5; - } - i++; - } - - /* Find the Data */ -/* FIXME : User Defined Path Info*/ - if ( (fff=fopen("./data/tb1_data_files_here","r"))!=NULL) { - strncpy(game_state->path_to_data,"./data/",20); - } - else if ( (fff=fopen("/usr/local/games/tb1/data/tb1_data_files_here","r")) - !=NULL) { - strncpy(game_state->path_to_data,"/usr/local/games/tb1/data/",40); - } - else { - char tempst[200]; - - sprintf(tempst,"%s/.tb1/data/tb1_data_files_here",getenv("HOME")); - if ( (fff=fopen(tempst,"r"))!=NULL) { - sprintf(game_state->path_to_data,"%s/.tb1/data/",getenv("HOME")); - } - else { - printf("ERROR! Could not find tb1 data!\n"); - printf(" Checked ./data, /usr/local/games/tb1/data\n"); - printf(" and %s/.tb1/data\n\n",getenv("HOME")); - return 9; - } - } - printf(" + Found tb1 data in %s\n",game_state->path_to_data); - -/* LEGACY OPERATION BOTTLECAP STUFF---> *\ -\* --> You are not meant to understand this <-- */ -/* No 9-22-94 Back to yes 10-6-94 uh_oh 2-21-95 *\ -\* gone for real long time 10-12-95 */ -/* 11-95 not AMG, but AAT *\ -\* 3-96 oh well... gave up on AAT finally */ -/* 5-11-96 Now MLP... *\ -\* 9-22-2000 :( */ -/* 3-25-2002 Now KRG ;) */ - - /* Randomize random number generator */ - srandom(time(NULL)); - printf(" + Seeding random number generator...\n"); - - /* Load/Detect sound */ - if (game_state->sound_possible) { - if (initSound(game_state->path_to_data)<0) { - game_state->sound_possible=0; - } - /* Load fanfare Music */ - if (game_state->sound_possible) { - loadSound(tb1_data_file("music/vmwfan.mod",game_state->path_to_data)); - } - printf(" + Loaded sounds...\n"); - } - - /* Setup Graphics */ - if (!game_state->default_double_size) { - if ( (game_state->graph_state= - vmwSetupSVMWGraph(graphics_target, - 320,200, - 0,1, - game_state->default_fullscreen, - 1))==NULL) { - fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); - return VMW_ERROR_DISPLAY; - } - } - else { /* We are double-sized */ - if ( (game_state->graph_state= - vmwSetupSVMWGraph(graphics_target, - 640,480, - 0,2, - game_state->default_fullscreen, - 1))==NULL) { - fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); - return VMW_ERROR_DISPLAY; - } - } - - /* Load the tom bombem font */ - game_state->graph_state->default_font= - vmwLoadFont(tb1_data_file("tbfont.tb1", - game_state->path_to_data),8,16,256); - printf(" + Loaded tb1 font...\n"); - - /* Allocate the 3 virtual screens */ - if ((game_state->virtual_1=vmwSetupVisual(320,200))==NULL) { - fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 1!\n"); - return VMW_ERROR_MEM; - } - - if ((game_state->virtual_2=vmwSetupVisual(320,400))==NULL) { - fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 2!\n"); - return VMW_ERROR_MEM; - } - - if ((game_state->virtual_3=vmwSetupVisual(320,200))==NULL) { - fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 3!\n"); - return VMW_ERROR_MEM; - } - - printf(" + Allocated virtual screens...\n"); - - /* To ease typing burden */ - virtual_1=game_state->virtual_1; - virtual_2=game_state->virtual_2; - virtual_3=game_state->virtual_3; - tb1_font=game_state->graph_state->default_font; - - /* The "fancy" opener */ - vmw_opener(game_state,virtual_1); - - /* Load menu music */ - if (game_state->sound_possible) { - stopSound(); - loadSound(tb1_data_file("music/weave1.mod",game_state->path_to_data)); - } - - /* Load palette */ - grapherror=vmwLoadPicPacked(0,0,virtual_1,1,0, - tb1_data_file("tbomb1.tb1", - game_state->path_to_data), - game_state->graph_state); - - /* Bit of a hack to load proper unfade colors */ - vmwFadeToBlack(game_state->graph_state,virtual_1,1); - - /* Load Title Picture */ - grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1, - tb1_data_file("tbomb1.tb1", - game_state->path_to_data), - game_state->graph_state); - - /* Copy the picture over */ - vmwFlipVirtual(virtual_3,virtual_1,320,200); - - vmwUnFade(game_state->graph_state,virtual_1); - - /* Main Menu Loop */ - while(1) { - /* If virtual_3 was over-written, re-load it */ - if (reloadpic) { - if ((game_state->sound_possible) && (game_state->music_enabled)) { - loadSound(tb1_data_file("music/weave1.mod", - game_state->path_to_data)); - } - grapherror=vmwLoadPicPacked(0,0,virtual_3,1,1, - tb1_data_file("tbomb1.tb1", - game_state->path_to_data), - game_state->graph_state); - reloadpic=0; - } - - vmwFlipVirtual(virtual_1,virtual_3,320,200); - - /* Play the menu-music */ - if ((game_state->sound_possible) && (game_state->music_enabled)) { - playSound(); - } - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - - /* Don't show the menu until keypress/15s */ - pauseawhile(15); - - barpos=0; - vmwTextXY("F1 HELP",0,190,9,7,0,tb1_font,virtual_1); - coolbox(117,61,199,140,1,virtual_1); - - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - ch=0; - - while(ch!=VMW_ENTER){ - if (barpos==0) { - vmwTextXY("NEW GAME",123,67,32,0,1,tb1_font,virtual_1); - } - else { - vmwTextXY("NEW GAME",123,67,32,7,1,tb1_font,virtual_1); - } - if (barpos==1) { - vmwTextXY("OPTIONS",123,77,32,0,1,tb1_font,virtual_1); - } - else { - vmwTextXY("OPTIONS",123,77,32,7,1,tb1_font,virtual_1); - } - if (barpos==2) { - vmwTextXY("ABOUT",123,87,32,0,1,tb1_font,virtual_1); - } - else { - vmwTextXY("ABOUT",123,87,32,7,1,tb1_font,virtual_1); - } - if (barpos==3) { - vmwTextXY("LOAD GAME",123,97,32,0,1,tb1_font,virtual_1); - } - else { - vmwTextXY("LOAD GAME",123,97,32,7,1,tb1_font,virtual_1); - } - if (barpos==4) { - vmwTextXY("STORY",123,107,32,0,1,tb1_font,virtual_1); - } - else { - vmwTextXY("STORY",123,107,32,7,1,tb1_font,virtual_1); - } - if (barpos==5) { - vmwTextXY("CREDITS",123,117,32,0,1,tb1_font,virtual_1); - } - else { - vmwTextXY("CREDITS",123,117,32,7,1,tb1_font,virtual_1); - } - if (barpos==6) { - vmwTextXY("QUIT",123,127,32,0,1,tb1_font,virtual_1); - } - else { - vmwTextXY("QUIT",123,127,32,7,1,tb1_font,virtual_1); - } - - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - - /* If at title screen too long, run credits */ - gettimeofday(&time_info,&dontcare); - time_sec=time_info.tv_sec; - - while( ((ch=vmwGetInput())==0)) { - usleep(30); - gettimeofday(&time_info,&dontcare); - if (time_info.tv_sec-time_sec>40) { - if (game_state->sound_possible) stopSound(); - credits(game_state); - ch=VMW_ENTER; - barpos=9; - reloadpic=1; - break; - } - } - - /* Change menu position based on key pressed */ - if ((ch==VMW_DOWN)||(ch==VMW_RIGHT)) barpos++; - if ((ch==VMW_UP) || (ch==VMW_LEFT)) barpos--; - if (ch==VMW_F1) {barpos=10; ch=VMW_ENTER;} /*F1*/ - if (ch=='n') barpos=0; /*N*/ - if (ch=='o') barpos=1; /*O*/ - if (ch=='a') barpos=2; /*A*/ - if (ch=='l') barpos=3; /*L*/ - if (ch=='s') barpos=4; /*S*/ - if (ch=='c') barpos=5; /*C*/ - if (ch=='q') barpos=6; /*Q*/ - if (ch==VMW_ESCAPE){ /* escape */ - barpos=6; - ch=VMW_ENTER; - } - if(barpos==7) barpos=0; - if(barpos<0) barpos=6; - } - if (game_state->sound_possible) stopSound(); - - /* Run whatever it was that the person pressed */ - switch (barpos) { - case 0: playthegame(game_state); reloadpic=1; break; - case 1: options(game_state); reloadpic=1; break; - case 2: about(game_state); reloadpic=1; break; - case 3: loadgame(game_state); reloadpic=1; break; - case 4: story(game_state); reloadpic=1; break; - case 5: credits(game_state); break; - case 6: barpos=quit(game_state); break; - case 10: help(game_state); reloadpic=1; break; - } - } -} +/****************************************************************\ +\* TOM BOMBEM AND THE INVASION OF THE INANIMATE_OBJECTS */ +/* version 2.9.16 26 December 2009 *\ +\* by Vince Weaver vince@deater.net */ +/* *\ +\* Originally written in Pascal and x86 assembly for DOS */ +/* using the PCGPE code as an example in 1994 *\ +\* Ported to Linux, C, and ggi late 1997-early 1998 */ +/* Port continued to SDL in June of 2000 *\ +\* This source is released under the GPL */ +/****************************************************************/ + +#define TB1_VERSION "2.9.16" + +#include +#include /* for calloc */ +#include /* for strncpy */ +#include +#include +#include + +#include "svmwgraph/svmwgraph.h" +#include "tb1_state.h" +#include "tblib.h" +#include "sound.h" + +#include "graphic_tools.h" +#include "help.h" +#include "quit.h" +#include "story.h" +#include "credits.h" +#include "about.h" +#include "loadsave.h" +#include "options.h" +#include "playgame.h" + +int command_line_help(int show_version,char *runas) { + + if (!show_version) { + printf("Usage: %s [-curses] [-double] [-fullscreen] [-nosound]" + " [-version] [-?]\n\n",runas); + printf(" -curses : play in color text-mode\n"); + printf(" -double : play in 640x480 mode\n"); + printf(" -fullscreen : play in fullscreen mode (if available)\n"); + printf(" -nosound : disables sound within game\n"); + printf(" -opengl : play in openGL mode\n"); + printf(" -version : print version\n"); + printf(" -? : print this help message\n"); + printf("\n"); + } + return 0; +} + + +void vmw_opener(tb1_state *game_state, vmwVisual *virtual_1) { + + int x; + + for(x=0;x<256;x++) { + vmwLoadPalette(game_state->graph_state,0,0,0,x); /* 0=black */ + } + + /* Do the VMW Software Production Logo */ + for(x=0;x<=40;x++) { + vmwLoadPalette(game_state->graph_state, ((x+20)*4),0,0,100+x); + vmwLoadPalette(game_state->graph_state,0,0, ( (x+20)*4 ),141+x); + vmwLoadPalette(game_state->graph_state,0, ( (x+20)*4),0,182+x); + } + + /* Set the white color */ + vmwLoadPalette(game_state->graph_state,0xff,0xff,0xff,15); + + vmwFlushPalette(game_state->graph_state); + + /* Actually draw the stylized VMW */ + for(x=0;x<=40;x++) { + vmwDrawVLine(x+40,45,2*x,100+x,virtual_1); + vmwDrawVLine(x+120,45,2*x,141+x,virtual_1); + vmwDrawVLine(x+200,45,2*x,141+x,virtual_1); + vmwDrawVLine(x+80,125-(2*x),2*x,182+x,virtual_1); + vmwDrawVLine(x+160,125-(2*x),2*x,182+x,virtual_1); + } + for(x=40;x>0;x--){ + vmwDrawVLine(x+80,45,80-(2*x),140-x,virtual_1); + vmwDrawVLine(x+160,45,80-(2*x),181-x,virtual_1); + vmwDrawVLine(x+240,45,80-(2*x),181-x,virtual_1); + vmwDrawVLine(x+120,45+(2*x),80-(2*x),222-x,virtual_1); + vmwDrawVLine(x+200,45+(2*x),80-(2*x),222-x,virtual_1); + } + + vmwTextXY("A VMW SOFTWARE PRODUCTION",60,140, + 15,15,0,game_state->graph_state->default_font,virtual_1); + + if ((game_state->sound_possible) && (game_state->music_enabled)) { + playSound(); + } + + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + pauseawhile(5); + vmwFadeToBlack(game_state->graph_state,virtual_1,0); +} + +int main(int argc,char **argv) { + + int i,grapherror,reloadpic=0; + int ch,barpos,time_sec; + int graphics_target=VMW_SDLTARGET; + FILE *fff; + char *dir_name,options_file[BUFSIZ]; + vmwVisual *virtual_1,*virtual_3;//*virtual_2 + + tb1_state *game_state; + + vmwFont *tb1_font; + + struct timeval time_info; + struct timezone dontcare; + + printf("\nTom Bombem v%s by Vince Weaver vince@deater.net\n",TB1_VERSION); + printf(" http://www.deater.net/weave/vmwprod/tb1\n\n"); + + /* Setup the game state */ + if ( (game_state=calloc(1,sizeof(tb1_state)))==NULL) { + printf("You are seriously low on RAM!\n"); + return 3; + } + + /* Some sane defaults */ + game_state->level=0; + game_state->shields=0; + game_state->score=0; + game_state->virtual_1=NULL; + //game_state->virtual_2=NULL; + game_state->virtual_3=NULL; + game_state->sound_possible=1; + game_state->music_enabled=1; + game_state->sound_enabled=1; + game_state->sound_volume=5; + game_state->music_volume=5; + game_state->default_double_size=0; + game_state->default_fullscreen=0; + + /* Load saved defaults, if any */ + dir_name=check_for_tb1_directory(game_state,0); + if (dir_name==NULL) { + printf(" + No ~/.tb1 directory. Using default options.\n"); + } + else { + sprintf(options_file,"%s/options.tb1",dir_name); + fff=fopen(options_file,"r"); + if (fff==NULL) { + printf(" + No ~/.tb1/options.tb1 file. Using defaults.\n"); + } + else { + printf(" + Reading options from ~/.tb1/options.tb1\n"); + fscanf(fff,"%i %i %i %i %i %i", + &game_state->sound_enabled, + &game_state->music_enabled, + &game_state->sound_volume, + &game_state->music_volume, + &game_state->default_double_size, + &game_state->default_fullscreen); + fclose(fff); + } + } + + + /* Parse Command Line Arguments */ + i=1; + while(idefault_fullscreen=1; + break; + case 'c': + graphics_target=VMW_CURSESTARGET; + break; + case 'd': + game_state->default_double_size=1; + break; + case 'n': + game_state->sound_possible=0; + printf(" + Sound totally disabled\n"); + break; + case 'o': + graphics_target=VMW_OPENGLTARGET; + break; + default : + command_line_help(0,argv[0]); + printf("Unknown Option: %s\n\n",argv[i]); + return 5; + } + } + else { + command_line_help(0,argv[0]); + printf("Unknown Option: %s\n\n",argv[i]); + return 5; + } + i++; + } + + /* Find the Data */ +/* FIXME : User Defined Path Info*/ + if ( (fff=fopen("./data/tb1_data_files_here","r"))!=NULL) { + strncpy(game_state->path_to_data,"./data/",20); + } + else if ( (fff=fopen("/usr/local/games/tb1/data/tb1_data_files_here","r")) + !=NULL) { + strncpy(game_state->path_to_data,"/usr/local/games/tb1/data/",40); + } + else { + char tempst[200]; + + sprintf(tempst,"%s/.tb1/data/tb1_data_files_here",getenv("HOME")); + if ( (fff=fopen(tempst,"r"))!=NULL) { + sprintf(game_state->path_to_data,"%s/.tb1/data/",getenv("HOME")); + } + else { + printf("ERROR! Could not find tb1 data!\n"); + printf(" Checked ./data, /usr/local/games/tb1/data\n"); + printf(" and %s/.tb1/data\n\n",getenv("HOME")); + return 9; + } + } + printf(" + Found tb1 data in %s\n",game_state->path_to_data); + +/* LEGACY OPERATION BOTTLECAP STUFF---> *\ +\* --> You are not meant to understand this <-- */ +/* No 9-22-94 Back to yes 10-6-94 uh_oh 2-21-95 *\ +\* gone for real long time 10-12-95 */ +/* 11-95 not AMG, but AAT *\ +\* 3-96 oh well... gave up on AAT finally */ +/* 5-11-96 Now MLP... *\ +\* 9-22-2000 :( */ +/* 3-25-2002 Now KRG ;) */ + + /* Randomize random number generator */ + srandom(time(NULL)); + printf(" + Seeding random number generator...\n"); + + /* Load/Detect sound */ + if (game_state->sound_possible) { + if (initSound(game_state->path_to_data)<0) { + game_state->sound_possible=0; + } + /* Load fanfare Music */ + if (game_state->sound_possible) { + loadSound(tb1_data_file("music/vmwfan.mod",game_state->path_to_data)); + } + printf(" + Loaded sounds...\n"); + } + + /* Setup Graphics */ + if (!game_state->default_double_size) { + if ( (game_state->graph_state= + vmwSetupSVMWGraph(graphics_target, + 320,200, + 0,1, + game_state->default_fullscreen, + 1))==NULL) { + fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); + return VMW_ERROR_DISPLAY; + } + } + else { /* We are double-sized */ + if ( (game_state->graph_state= + vmwSetupSVMWGraph(graphics_target, + 640,480, + 0,2, + game_state->default_fullscreen, + 1))==NULL) { + fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); + return VMW_ERROR_DISPLAY; + } + } + + /* Load the tom bombem font */ + game_state->graph_state->default_font= + vmwLoadFont(tb1_data_file("tbfont.tb1", + game_state->path_to_data),8,16,256); + printf(" + Loaded tb1 font...\n"); + + /* Allocate the 3 virtual screens */ + if ((game_state->virtual_1=vmwSetupVisual(320,200))==NULL) { + fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 1!\n"); + return VMW_ERROR_MEM; + } + + if ((game_state->virtual_2=vmwSetupVisual(320,400))==NULL) { + fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 2!\n"); + return VMW_ERROR_MEM; + } + + if ((game_state->virtual_3=vmwSetupVisual(320,200))==NULL) { + fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 3!\n"); + return VMW_ERROR_MEM; + } + + printf(" + Allocated virtual screens...\n"); + + /* To ease typing burden */ + virtual_1=game_state->virtual_1; + //virtual_2=game_state->virtual_2; + virtual_3=game_state->virtual_3; + tb1_font=game_state->graph_state->default_font; + + /* The "fancy" opener */ + vmw_opener(game_state,virtual_1); + + /* Load menu music */ + if (game_state->sound_possible) { + stopSound(); + loadSound(tb1_data_file("music/weave1.mod",game_state->path_to_data)); + } + + /* Load palette */ + grapherror=vmwLoadPicPacked(0,0,virtual_1,1,0, + tb1_data_file("tbomb1.tb1", + game_state->path_to_data), + game_state->graph_state); + if (grapherror) { + return -1; + } + + /* Bit of a hack to load proper unfade colors */ + vmwFadeToBlack(game_state->graph_state,virtual_1,1); + + /* Load Title Picture */ + grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1, + tb1_data_file("tbomb1.tb1", + game_state->path_to_data), + game_state->graph_state); + + /* Copy the picture over */ + vmwFlipVirtual(virtual_3,virtual_1,320,200); + + vmwUnFade(game_state->graph_state,virtual_1); + + /* Main Menu Loop */ + while(1) { + /* If virtual_3 was over-written, re-load it */ + if (reloadpic) { + if ((game_state->sound_possible) && (game_state->music_enabled)) { + loadSound(tb1_data_file("music/weave1.mod", + game_state->path_to_data)); + } + grapherror=vmwLoadPicPacked(0,0,virtual_3,1,1, + tb1_data_file("tbomb1.tb1", + game_state->path_to_data), + game_state->graph_state); + reloadpic=0; + } + + vmwFlipVirtual(virtual_1,virtual_3,320,200); + + /* Play the menu-music */ + if ((game_state->sound_possible) && (game_state->music_enabled)) { + playSound(); + } + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + + /* Don't show the menu until keypress/15s */ + pauseawhile(15); + + barpos=0; + vmwTextXY("F1 HELP",0,190,9,7,0,tb1_font,virtual_1); + coolbox(117,61,199,140,1,virtual_1); + + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + ch=0; + + while(ch!=VMW_ENTER){ + if (barpos==0) { + vmwTextXY("NEW GAME",123,67,32,0,1,tb1_font,virtual_1); + } + else { + vmwTextXY("NEW GAME",123,67,32,7,1,tb1_font,virtual_1); + } + if (barpos==1) { + vmwTextXY("OPTIONS",123,77,32,0,1,tb1_font,virtual_1); + } + else { + vmwTextXY("OPTIONS",123,77,32,7,1,tb1_font,virtual_1); + } + if (barpos==2) { + vmwTextXY("ABOUT",123,87,32,0,1,tb1_font,virtual_1); + } + else { + vmwTextXY("ABOUT",123,87,32,7,1,tb1_font,virtual_1); + } + if (barpos==3) { + vmwTextXY("LOAD GAME",123,97,32,0,1,tb1_font,virtual_1); + } + else { + vmwTextXY("LOAD GAME",123,97,32,7,1,tb1_font,virtual_1); + } + if (barpos==4) { + vmwTextXY("STORY",123,107,32,0,1,tb1_font,virtual_1); + } + else { + vmwTextXY("STORY",123,107,32,7,1,tb1_font,virtual_1); + } + if (barpos==5) { + vmwTextXY("CREDITS",123,117,32,0,1,tb1_font,virtual_1); + } + else { + vmwTextXY("CREDITS",123,117,32,7,1,tb1_font,virtual_1); + } + if (barpos==6) { + vmwTextXY("QUIT",123,127,32,0,1,tb1_font,virtual_1); + } + else { + vmwTextXY("QUIT",123,127,32,7,1,tb1_font,virtual_1); + } + + vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + + /* If at title screen too long, run credits */ + gettimeofday(&time_info,&dontcare); + time_sec=time_info.tv_sec; + + while( ((ch=vmwGetInput())==0)) { + usleep(30); + gettimeofday(&time_info,&dontcare); + if (time_info.tv_sec-time_sec>40) { + if (game_state->sound_possible) stopSound(); + credits(game_state); + ch=VMW_ENTER; + barpos=9; + reloadpic=1; + break; + } + } + + /* Change menu position based on key pressed */ + if ((ch==VMW_DOWN)||(ch==VMW_RIGHT)) barpos++; + if ((ch==VMW_UP) || (ch==VMW_LEFT)) barpos--; + if (ch==VMW_F1) {barpos=10; ch=VMW_ENTER;} /*F1*/ + if (ch=='n') barpos=0; /*N*/ + if (ch=='o') barpos=1; /*O*/ + if (ch=='a') barpos=2; /*A*/ + if (ch=='l') barpos=3; /*L*/ + if (ch=='s') barpos=4; /*S*/ + if (ch=='c') barpos=5; /*C*/ + if (ch=='q') barpos=6; /*Q*/ + if (ch==VMW_ESCAPE){ /* escape */ + barpos=6; + ch=VMW_ENTER; + } + if(barpos==7) barpos=0; + if(barpos<0) barpos=6; + } + if (game_state->sound_possible) stopSound(); + + /* Run whatever it was that the person pressed */ + switch (barpos) { + case 0: playthegame(game_state); reloadpic=1; break; + case 1: options(game_state); reloadpic=1; break; + case 2: about(game_state); reloadpic=1; break; + case 3: loadgame(game_state); reloadpic=1; break; + case 4: story(game_state); reloadpic=1; break; + case 5: credits(game_state); break; + case 6: barpos=quit(game_state); break; + case 10: help(game_state); reloadpic=1; break; + } + } +} diff --git a/tb1_linux/tblib.c b/tb1_linux/tblib.c index acfbe52..7fc42f8 100644 --- a/tb1_linux/tblib.c +++ b/tb1_linux/tblib.c @@ -1,69 +1,69 @@ -#include -#include -#include -#include -#include /* abs */ -#include "svmwgraph/svmwgraph.h" -#include "tb1_state.h" -#include "graphic_tools.h" - -void pauseawhile(int howlong) { - - struct timeval bob; - struct timezone mree; - long begin_s,begin_u; - - vmwClearKeyboardBuffer(); - gettimeofday(&bob,&mree); - begin_s=bob.tv_sec; begin_u=bob.tv_usec; - while ((bob.tv_sec-begin_s)graph_state, - game_state->graph_state->default_font, - game_state->virtual_1, - warning_1, - warning_2, - yes_option, - no_option); - - -} +#include +#include +#include +#include +#include /* abs */ +#include "svmwgraph/svmwgraph.h" +#include "tb1_state.h" +#include "graphic_tools.h" + +void pauseawhile(int howlong) { + + struct timeval bob; + struct timezone mree; + long begin_s; + + vmwClearKeyboardBuffer(); + gettimeofday(&bob,&mree); + begin_s=bob.tv_sec; + while ((bob.tv_sec-begin_s)graph_state, + game_state->graph_state->default_font, + game_state->virtual_1, + warning_1, + warning_2, + yes_option, + no_option); + + +}