This commit is contained in:
Vince Weaver 2004-09-26 15:18:00 -04:00
parent ecb266f70f
commit 74e547cb6e
16 changed files with 1308 additions and 100 deletions

45
CHANGES
View File

@ -1,3 +1,16 @@
25 September 2004
+ Started working on level3 of the game again
+ Updated title screen to reflect current girlfriend.
+ Fixed sound.
+ A paint-pro plugin I developed for "Guinea Pig Adventure"
improves productivity a lot.
2001-2004
+ Sadly a lull in tb1 development. In that time though I did develop
tb_6502 : tom bombem for the Apple IIe
tb_asm : tom bombem in x86 assembly (fits in 8k statically linked)
tbo : obfuscated C contest entry of tom bombem.
28 October 2001
+ Debugged over a few days 32bpp solaris support, with lots of help
from G. Low <unix@macrosscity.com>
@ -134,8 +147,30 @@
* Added support so it can (almost) run in both 8bpp and 16bpp mode.
* Broke a lot more than I fixed.
1994-1996
Wrote Tom Bombem in pascal and inline assembly, using the
"Flying Toaster" demo from PCGPE as a starting point.
Used Ethan Brodsky's sound libs, in addition to my own
"Paintpro" graphics program/loader.
? 1997
* Ported to the ggi graphics library
Fall 1996
* Original attempts to port to linux. Used now-defunct graphics library.
? 1996
+ Worked on level3 + level4?
+ Adding in-line 32-bit assembly to get it to run at fast enough
framerate on the 386 33MHz my family had.
? 1995
+ Got sound blaster code working, using Ethan Brodsky's
soundblaster libraries.
+ Used newest versio of my "PaintPro" Graphics format.
It is very much like PCX, but I didn't know that when I invented it
a few years earlier in BASIC.
+ Written in Turbo Pascal 6.0 with in-line 16 bit assembly.
Fall 1994
+ Gradually converted PCGPE "Flying Toaster" demo into proof-of-concept
Tom Bombem code.
+ Level 1 mostly working
Summer 1994
+ Was exchange student in Hildesheim Germany. People there gave me
a copy of the PCGPE (PC Game Programmer Encyclopedia)

View File

@ -19,9 +19,9 @@ SDL_MIXER_LIBS= -lSDL_mixer
# Uncomment the following for SDL
#
SDL_TARGET= sdl_svmwgraph.o
SDL_LIBS= -lSDL -L/usr/X11R6/lib -lX11 -lpthread
SDL_LIBS= `sdl-config --libs`
SDL_FLAGS= -DSDL_TARGET
SDL_INCLUDE= -I/usr/local/include/SDL
SDL_INCLUDE= `sdl-config --cflags`
#
# Uncomment the following for ncurses

4
TODO
View File

@ -2,6 +2,10 @@ Finish the game:
Requires:
Levels3-10. Level 3 is semi-done in pascal.
Record keypresses, have a demo mode.
Better joystick support
Other aspirations:
Some sort of "configure" type file
Audit all the code.

16
about.c
View File

@ -56,17 +56,17 @@ void about(tb1_state *game_state)
break;
case 2:
shadowrite("MY NAME IS VINCE WEAVER",10,10,10,2,tb1_font,target1);
shadowrite(" VISIT MY TALKER",10,20,10,2,tb1_font,target1);
shadowrite(" DERANGED.STUDENT.UMD.EDU 7000",10,30,10,2,tb1_font,target1);
shadowrite(" UP WHENEVER SCHOOL IS IN SESSION",10,40,10,2,tb1_font,target1);
shadowrite("UNTIL DECEMBER OF 2000 I WILL BE",10,60,13,5,tb1_font,target1);
shadowrite(" ATTENDING COLLEGE, AT THE UNIVERSITY",10,70,13,5,tb1_font,target1);
shadowrite(" OF MARYLAND, COLLEGE PARK.",10,80,13,5,tb1_font,target1);
shadowrite(" VISIT MY WEBSITE",10,20,10,2,tb1_font,target1);
shadowrite(" http://www.deater.net/weave/",10,30,10,2,tb1_font,target1);
/* shadowrite(" UP WHENEVER SCHOOL IS IN SESSION",10,40,10,2,tb1_font,target1);*/
shadowrite("UNTIL 2008 I WILL BE IN GRAD SCHOOL",10,60,13,5,tb1_font,target1);
shadowrite(" AT CORNELL UNIVERSITY.",10,70,13,5,tb1_font,target1);
shadowrite(" THEN, ONTO THE MOON!.",10,80,13,5,tb1_font,target1);
shadowrite("GET THE NEWEST VERSION OF TB1 AT",10,100,11,3,tb1_font,target1);
shadowrite(" THE OFFICIAL TB1 WEB SITE:",10,110,11,3,tb1_font,target1);
shadowrite(" http://www.glue.umd.edu/~weave/tb1/",10,120,11,3,tb1_font,target1);
shadowrite(" www.deater.net/weave/vmwprod/tb1/",10,120,11,3,tb1_font,target1);
shadowrite("I CAN BE CONTACTED VIA E-MAIL AT:",10,140,12,4,tb1_font,target1);
shadowrite(" WEAVE@ENG.UMD.EDU",10,150,9,1,tb1_font,target1);
shadowrite(" VINCE@DEATER.NET",10,150,9,1,tb1_font,target1);
shadowrite("FEEL FREE TO SEND COMMENTS.",10,160,12,4,tb1_font,target1);
break;
case 3:

View File

@ -97,8 +97,8 @@ void credits(tb1_state *game_state)
vmwTextXY(" ISAAC ASIMOV",0,290,9,0,1,tb1_font,game_state->virtual_2);
vmwTextXY(" GORDON KORMAN",0,310,9,0,1,tb1_font,game_state->virtual_2);
vmwTextXY(" THANKS TO ALL THE AGENTS",0,340,10,0,1,tb1_font,game_state->virtual_2);
vmwTextXY(" B,D,JL,L,N,P,S,W,PM,E,G,TK",0,360,10,0,1,tb1_font,game_state->virtual_2);
vmwTextXY(" AND ESPECIALLY MP",0,380,10,0,1,tb1_font,game_state->virtual_2);
vmwTextXY(" B,D,JL,L,N,P,S,W,PM,E,G,TK,MP",0,360,10,0,1,tb1_font,game_state->virtual_2);
vmwTextXY(" AND ESPECIALLY KRG",0,380,10,0,1,tb1_font,game_state->virtual_2);
if (!keypressed) for(i=0;i<200;i++){
vmwArbitraryCrossBlit(game_state->virtual_2,0,i,320,200,

Binary file not shown.

View File

@ -80,7 +80,7 @@ int map_string_to_type(char *string) {
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);
// printf("%s %i\n",string,text_mapping[i].type);
return text_mapping[i].type;
}
i++;
@ -263,6 +263,7 @@ struct obstruction_type {
int x,y;
int type;
int exploding;
int explodeprogress;
int howmanyhits;
int lastshot;
struct obstruction_type *next;
@ -271,6 +272,42 @@ struct obstruction_type {
#define BULLETS_MAX 3
struct bullet_root_type *bullet_root;
struct bullet_info_type **bullet_info;
struct bullet_info_type *temp_bullet=NULL;
void remove_bullet() {
temp_bullet->out=0;
bullet_root->howmany--;
/* Remove bullet from linked list */
if (bullet_root->head==temp_bullet) {
bullet_root->head=temp_bullet->next;
}
if (bullet_root->tail==temp_bullet) {
bullet_root->tail=temp_bullet->prev;
}
if (temp_bullet->prev!=NULL) {
if (temp_bullet->next!=NULL)
temp_bullet->prev->next=temp_bullet->next;
else temp_bullet->prev->next=NULL;
}
if (temp_bullet->next!=NULL) {
if (temp_bullet->prev!=NULL)
temp_bullet->next->prev=temp_bullet->prev;
else temp_bullet->next->prev=NULL;
}
}
void leveltwoengine(tb1_state *game_state, char *shipfile, char *levelfile,
char *spritefile,char *level_num, char *level_desc,
void *close_function)
@ -281,18 +318,17 @@ void leveltwoengine(tb1_state *game_state, char *shipfile, char *levelfile,
int shipx=36,shipy;
int whatdelay=1;
int levelover=0,j,offscreen_row=0;
struct enemyinfo *enemy;
struct bullet_root_type *bullet_root;
struct bullet_info_type **bullet_info;
struct bullet_info_type *temp_bullet=NULL;
// struct enemyinfo *enemy;
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_heap[20][12];
struct obstruction_type *obstruction_head[20];
struct obstruction_type obstructions[20][12];
struct obstruction_type *temp_obstruct;
int shipadd=0,shipframe=1;
int our_row,our_shape,rows_goneby=0;
int our_row,rows_goneby=0;
int grapherror;
int done_waiting,type;
@ -301,7 +337,7 @@ void leveltwoengine(tb1_state *game_state, char *shipfile, char *levelfile,
vmwVisual *virtual_2;
vmwSprite *ship_shape[3];
int enemies_drawn[200];
// int enemies_drawn[200];
struct level2_data *data;
@ -350,20 +386,21 @@ void leveltwoengine(tb1_state *game_state, char *shipfile, char *levelfile,
bullet_info[i]->out=0;
}
/* Initialize structures for obstructions */
/* Waste lots of RAM in name of speed. */
/* Never would have done this on the original Pascal DOS version */
// obstruction_heap=calloc(20*12,sizeof(struct obstruction_type));
// for(i=0;i<20;i++) {
// obstructions[i]=obstruction_heap+(i*12*sizeof(struct obstruction_type));
// }
/* Initialize obstruction heap to 0 */
for(j=0;j<20;j++) {
for(i=0;i<12;i++) {
// obstructions[j][i].next=NULL;
obstructions[j][i].next=NULL;
}
}
for(i=0;i<12;i++) {
obstruction_head[i]=NULL;
}
@ -415,16 +452,17 @@ void leveltwoengine(tb1_state *game_state, char *shipfile, char *levelfile,
(type==SPRITE_ENEMY_SHOOT) ||
(type==SPRITE_ENEMY_REFLECT)) {
k=0;
// temp_obstruct=obstructions[j];
// while(temp_obstruct->next!=NULL) temp_obstruct=temp_obstruct->next;
// temp_obstruct->next=temp_obstruct+1;
// temp_obstruct=temp_obstruct->next;
// temp_obstruct->x=i*20;
// temp_obstruct->y=j*20;
// temp_obstruct->type=type;
// temp_obstruct->exploding=0;
// temp_obstruct->lastshot=0;
// temp_obstruct->next=NULL;
obstruction_head[j]=obstructions[j][0];
temp_obstruct=obstructions[j][0];
while(temp_obstruct->next!=NULL) temp_obstruct=temp_obstruct->next;
temp_obstruct->next=temp_obstruct+1;
temp_obstruct=temp_obstruct->next;
temp_obstruct->x=i*20;
temp_obstruct->y=j*20;
temp_obstruct->type=type;
temp_obstruct->exploding=0;
temp_obstruct->lastshot=0;
temp_obstruct->next=NULL;
}
}
}
@ -460,36 +498,39 @@ void leveltwoengine(tb1_state *game_state, char *shipfile, char *levelfile,
if (rows_goneby%10==0) {
/* move all rows down by one, dropping old off end */
// memmove(obstructions[1],obstructions[0],19*20*sizeof(struct obstruction_type));
// obstructions[0]->next=NULL;
memmove(obstructions[1],obstructions[0],
19*12*sizeof(struct obstruction_type));
memmove(obstruction_head[1],obstruction_head[0],
19*sizeof(struct *obstruction_type));
obstructions[0]->next=NULL;
our_row--;
printf("ROW %i\n",our_row);
// temp_obstruct=obstructions[0];
// printf("ROW %i\n",our_row);
temp_obstruct=obstructions[0];
for(i=0;i<12;i++) {
type=data->sprites[*(data->level_data[our_row]+i)]->type;
printf("%3i ",type);
// printf("%3i ",type);
if ((type==SPRITE_OBSTRUCTION) ||
(type==SPRITE_ENEMY_SHOOT) ||
(type==SPRITE_ENEMY_REFLECT)) {
printf("*");
// printf("*");
// printf("Enemy %i on row %i\n",type,our_row);
// fflush(stdout);
// while(temp_obstruct->next!=NULL) temp_obstruct=temp_obstruct->next;
// temp_obstruct->next=temp_obstruct+1;
// temp_obstruct=temp_obstruct+1;
// temp_obstruct->x=i*20;
// temp_obstruct->y=j*20;
// temp_obstruct->type=type;
// temp_obstruct->exploding=0;
// temp_obstruct->lastshot=0;
// temp_obstruct->next=NULL;
while(temp_obstruct->next!=NULL) temp_obstruct=temp_obstruct->next;
temp_obstruct->next=temp_obstruct+1;
temp_obstruct=temp_obstruct+1;
temp_obstruct->x=i*20;
temp_obstruct->y=j*20;
temp_obstruct->type=type;
temp_obstruct->exploding=0;
temp_obstruct->lastshot=0;
temp_obstruct->next=NULL;
}
}
printf("\n"); fflush(stdout);
// printf("\n"); fflush(stdout);
}
#if 0
#if 0
if (!enemies_drawn[our_row]) {
enemies_drawn[our_row]=1;
for(i=0;i<12;i++) {
@ -509,24 +550,48 @@ void leveltwoengine(tb1_state *game_state, char *shipfile, char *levelfile,
}
}
}
#endif
#endif
/* Flip the far background to regular background */
vmwArbitraryCrossBlit(virtual_2,0,0+howmuchscroll,240,200,
virtual_1,0,0);
/***Collision Check***/
for(i=0;j<bullet_root->howmany;j++) {
// temp_obstruct=obstructions[ (bullet_info[i]->y)/10];
for(i=0;i<bullet_root->howmany;i++) {
temp_obstruct=obstructions[ (bullet_info[i]->y)/10];
// printf("%p %p\n",temp_obstruct,temp_obstruct->next);
printf("Row %i\n",(bullet_info[i]->y)/10); fflush(stdout);
// while (temp_obstruct->next!=NULL) {
// temp_obstruct=temp_obstruct->next;
// if ( ( (bullet_info[i]->x-3) >= temp_obstruct->x) &&
// ( bullet_info[i]->x <= (temp_obstruct->x+20))) {
// printf("BOOM\n"); fflush(stdout);
// }
// }
// printf("Row %i\n",(bullet_info[i]->y)/10); fflush(stdout);
while (temp_obstruct->next!=NULL) {
temp_obstruct=temp_obstruct->next;
if ( ( (bullet_info[i]->x-3) >= temp_obstruct->x) &&
( bullet_info[i]->x <= (temp_obstruct->x+20))) {
if (temp_obstruct->type!=SPRITE_ENEMY_REFLECT) {
if ((game_state->sound_possible)&&(game_state->sound_enabled))
playGameFX(SND_KAPOW);
temp_obstruct->exploding=1;
temp_obstruct->explodeprogress=0;
temp_bullet=bullet_info[i];
remove_bullet();
game_state->score+=10;
changescore(game_state);
}
else {
// bullet[j].out=0;
// k=0;
// while ((!enemy[k].out) && (k<10)) k++;
// if (k<9) {
// enemy[k].out=1;
// enemy[k].y=bullet[j].y;
// enemy[k].x=bullet[j].x;
// enemy[k].yspeed=7;
// enemy[k].kind=21;
// }
}
// printf("BOOM\n"); fflush(stdout);
}
}
}
@ -619,32 +684,10 @@ void leveltwoengine(tb1_state *game_state, char *shipfile, char *levelfile,
if (speed_factor>1) temp_bullet->y-=(5*speed_factor);
else temp_bullet->y-=5;
if (temp_bullet->y<5) {
temp_bullet->out=0;
bullet_root->howmany--;
/* Remove bullet from linked list */
if (bullet_root->head==temp_bullet) {
bullet_root->head=temp_bullet->next;
}
remove_bullet();
if (bullet_root->tail==temp_bullet) {
bullet_root->tail=temp_bullet->prev;
}
if (temp_bullet->prev!=NULL) {
if (temp_bullet->next!=NULL)
temp_bullet->prev->next=temp_bullet->next;
else temp_bullet->prev->next=NULL;
}
if (temp_bullet->next!=NULL) {
if (temp_bullet->prev!=NULL)
temp_bullet->next->prev=temp_bullet->prev;
else temp_bullet->next->prev=NULL;
}
}
else vmwPutSprite(data->sprites[temp_bullet->type]->data,
temp_bullet->x,temp_bullet->y,virtual_1);

12
level3/Makefile Normal file
View File

@ -0,0 +1,12 @@
C_FLAGS=-Wall -O2 -g
all: level3
level3: level3.o
gcc $(L_FLAGS) -o level3 level3.o
level3.o: level3.c game_sprites.h
gcc $(C_FLAGS) -c level3.c
clean:
rm -f *~ *.o level3 core

36
level3/game_sprites.h Normal file
View File

@ -0,0 +1,36 @@
char tom_sprite[1][1]=
{
{ 0x9}
}
;
char wall[1][1]=
{
{ 0x7}
}
;
char gun[1][1]=
{
{
0x3
}
}
;
char door[1][1]=
{
{
0xb
}
}
;
char wisp[1][1]=
{
{
0xe
}
}
;

26
level3/level1 Normal file
View File

@ -0,0 +1,26 @@
;
;
;
;012345678901234567890123
0########### ##########0
1# # # #1
2# G # # S #2
3# # # #3
4# # # #4
5# # # #5
6# # # #6
7# #### #### #7
8# # w # #8
9# #9
0# #0
1# #1
2# # # #2
3# # w # #3
4# #### #### #4
5# # # #5
6# # # #6
7# A # # #7
8# # T # #8
9###########///##########9
;012345678901234567890123

794
level3/level3.c Normal file
View File

@ -0,0 +1,794 @@
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#define SCREEN_WIDTH 24
#define SCREEN_HEIGHT 20
#define BYTES_PER_PIXEL 2
#include "game_sprites.h"
int dump_screen=0;
int clear_framebuffer(char *buffer,char color,char value) {
int i=0;
while(i<SCREEN_WIDTH*SCREEN_HEIGHT*BYTES_PER_PIXEL) {
buffer[i]=color;
buffer[i+1]=value;
i+=BYTES_PER_PIXEL;
}
return 0;
}
int blit(char *sprite, char *framebuffer, char ascii,int x, int y,int xsize,int ysize) {
int xx=0,yy=0,offset;
offset=((y*SCREEN_WIDTH)+x)*BYTES_PER_PIXEL;
while(yy<ysize) {
if (sprite[(yy*xsize)+xx]) {
framebuffer[offset]=sprite[(yy*xsize)+xx];
framebuffer[offset+1]=ascii;
}
offset+=BYTES_PER_PIXEL;
xx++;
if (xx>=xsize) {
offset+=((SCREEN_WIDTH-xsize)*BYTES_PER_PIXEL);
xx=0;
yy++;
}
}
return 0;
}
int put_text_xy(char *text,int x,int y,int color, char *framebuffer) {
int offset,i;
offset=(y*SCREEN_WIDTH+x)*BYTES_PER_PIXEL;
i=0;
while(i<strlen(text)) {
framebuffer[offset]=(char)color;
framebuffer[offset+1]=text[i];
i++;
offset+=2;
}
return 0;
}
int to_buffer(char *buffer,char *string) {
strncat(buffer,string,BUFSIZ);
return strlen(string);
}
int to_buffer_color(char *buffer,int bold, int color) {
char temp_string[BUFSIZ];
sprintf(temp_string,"\033[%i;%im",bold,color);
strncat(buffer,temp_string,BUFSIZ);
return strlen(temp_string);
}
int dump_to_screen(char *framebuffer) {
static char out_buffer[40*44*10];
char colors[8]={30,34,32,36,31,35,33,37};
unsigned char temp_string[2]={0,0};
int size=0,i,j,color,old_color=-1;
int block_mode;
block_mode=0;
out_buffer[0]='\0';
/* home cursor */
size+=to_buffer(out_buffer,"\033[0;0H");
for(j=0;j<SCREEN_HEIGHT;j++) {
for(i=0;i<SCREEN_WIDTH;i++) {
color=framebuffer[(i+j*SCREEN_WIDTH)*BYTES_PER_PIXEL];
if (color!=old_color) {
size+=to_buffer_color(out_buffer,color>7,colors[color&7]);
old_color=color;
}
temp_string[0]=framebuffer[((i+j*SCREEN_WIDTH)*BYTES_PER_PIXEL)+1];
if (temp_string[0]==219) {
if (!block_mode){
block_mode=1;
size+=to_buffer(out_buffer,"\016");
}
temp_string[0]='0';
}
else {
if (block_mode) {
block_mode=0;
size+=to_buffer(out_buffer,"\017");
}
}
size+=to_buffer(out_buffer,temp_string);
}
size+=to_buffer(out_buffer,"\n");
}
if (size>40*44*10) {
printf("\a\a\a\n");
exit(10);
}
write(1,out_buffer,size);
if (dump_screen) {
int fd;
fd=creat("screen",0x666);
write(fd,out_buffer,size);
close(fd);
dump_screen=0;
}
// fdatasync(1);
return 0;
}
int get_timer() {
static int initialized=0;
static int startseconds,startusecs;
struct timeval our_time;
int temp_time;
if (!initialized) {
gettimeofday(&our_time,NULL);
startseconds=time(NULL);
startusecs=our_time.tv_usec;
initialized=1;
}
gettimeofday(&our_time,NULL);
temp_time=(time(NULL)-startseconds)*1000;
temp_time+=(our_time.tv_usec/1000);
return temp_time;
}
void clear_keyboard_buffer()
{
int ch;
while(read(0,&ch,1)==1);
}
void pause_a_while(int msecs) {
int ch,our_time;
our_time=get_timer();
while ( read(0,&ch,1)!=1) {
usleep(1);
if ( (get_timer()-our_time) > msecs ) break;
}
clear_keyboard_buffer();
}
int get_char() {
char ch;
int result;
result=read(0,&ch,1);
if (result<1) return 0;
else return ch;
}
int get_a_char() {
char ch,ch1,ch2,ch3;
ch=get_char();
if (ch==27) {
ch1=get_char();
ch2=get_char();
ch3=get_char();
if ((ch1==0) && (ch2==0)) return 'q';
if ((ch1==91) && (ch2==66)) return 'm';
if ((ch1==91) && (ch2==65)) return 'i';
if ((ch1==91) && (ch2==67)) return 'k';
if ((ch1==91) && (ch2==68)) return 'j';
if ((ch1==91) && (ch2==91)) {
if (ch3==65) return 'h';
}
{
FILE *fff;
fff=fopen("bob","w");
fprintf(fff,"%i %i %i\n",ch1,ch2,ch3);
fclose(fff);
}
// }
}
return ch;
}
void null()
{
}
void put_attention_block(char *framebuffer,int color) {
int i,j;
for(i=5;i<12;i++)
for(j=0;j<40;j++)
put_text_xy("*",j,i,color,framebuffer);
}
int verify_quit(char *framebuffer) {
int quit_bar=0;
char ch;
put_attention_block(framebuffer,14);
put_text_xy(" QUIT? Are you sure? ",9,7,12,framebuffer);
put_text_xy(" NO!",9,8,12,framebuffer);
put_text_xy(" YES!",9,9,12,framebuffer);
quit_loop:
if (quit_bar==0) {
put_text_xy(" --> NO! ",9,8,13,framebuffer);
put_text_xy(" YES ",9,9,5,framebuffer);
}
else {
put_text_xy(" NO ",9,8,5,framebuffer);
put_text_xy(" --> YES! ",9,9,13,framebuffer);
}
dump_to_screen(framebuffer);
while ((ch=get_a_char())==0) usleep(5000);
if ((ch=='i') || (ch=='j') || (ch=='k') || (ch=='m')) quit_bar=!quit_bar;
if (ch=='y') quit_bar=1;
if (ch=='n') quit_bar=0;
if (ch=='\n') {
return quit_bar;
}
goto quit_loop;
return 0;
}
int help(char *framebuffer) {
clear_framebuffer(framebuffer,0,' ');
put_text_xy("TOM BOMBEM",10,0,15,framebuffer);
put_text_xy("by",14,1,7,framebuffer);
put_text_xy("Vince Weaver",9,2,15,framebuffer);
put_text_xy("Key Bindings:",0,4,15,framebuffer);
put_text_xy("UP or 'i' : Move menu up",2,6,7,framebuffer);
put_text_xy("DOWN or 'm' : Move menu down",2,7,7,framebuffer);
put_text_xy("ENTER : Selects current option",2,8,7,framebuffer);
put_text_xy("RIGHT or 'k' : Move ship right",2,10,7,framebuffer);
put_text_xy("LEFT or 'j' : Move ship left",2,11,7,framebuffer);
put_text_xy("SPACEBAR : Shoots",2,12,7,framebuffer);
put_text_xy("F1 or 'h' : Displays help",2,14,7,framebuffer);
put_text_xy("ESC or 'q' : Quits",2,15,7,framebuffer);
put_text_xy("'p' : Pauses",2,16,7,framebuffer);
put_text_xy("'s' : Toggles sound",2,17,7,framebuffer);
dump_to_screen(framebuffer);
while(get_char()==0) usleep(30);
return 0;
}
int map_ch;
void skip_line(FILE *fff) {
map_ch=fgetc(fff);
while((map_ch!='\n') && (map_ch!=-1)) map_ch=fgetc(fff);
}
int get_int(FILE *fff) {
int result=0;
map_ch=fgetc(fff);
while(map_ch!=-1) {
while ((map_ch<=' ')&&(map_ch!=-1)) map_ch=fgetc(fff);
if (map_ch==';') skip_line(fff);
if ((map_ch>='0') && (map_ch<='9')) {
while ((map_ch>='0') && (map_ch<='9')) {
result=result*10;
result+=map_ch-'0';
map_ch=fgetc(fff);
}
return result;
}
}
return -1;
}
void panic_oom(char *string) {
printf("Out of Memory: %s\n",string);
exit(1);
}
int new_game(char *framebuffer) {
int quit=0,game_paused=0,sound=1,done_waiting=0;
int ch;
int time_spent,oldusec=0,oldsec=0;
struct timeval timing_info;
struct tom_struct {
int x,y,xadd,yadd;
int roomx,roomy,roomz;
} tom;
struct enemies_struct {
int x,y,xadd,yadd;
char type;
} enemies[2];
int total_enemies=0;
int x,y,z,i,j,k,tempx,tempy;
int roomx,roomy,roomz,offset;
char *current_room;
FILE *level_file;
struct map_type {
int xsize,ysize,zsize;
int roomx,roomy;
char **rooms;
} map;
tom.xadd=0; tom.yadd=0;
/* Load Level */
level_file=fopen("level3.map","r");
if (level_file==NULL) {
printf("File not found!\n");
exit(1);
}
/* Get header info */
map.xsize=get_int(level_file);
map.ysize=get_int(level_file);
map.zsize=get_int(level_file);
map.roomx=get_int(level_file);
map.roomy=get_int(level_file);
printf("Found map of %i,%i,%i\n",map.xsize,map.ysize,map.zsize);
printf("Roomsize of %ix%i\n",map.roomx,map.roomy);
map.rooms=calloc(map.xsize*map.ysize*map.zsize,sizeof(char *));
if (map.rooms==NULL) panic_oom("map.rooms");
for(i=0;i<map.xsize;i++) {
for(j=0;j<map.ysize;j++) {
for(k=0;k<map.zsize;k++) {
map.rooms[i+(j*map.xsize)+(k*map.xsize*map.ysize)]
=calloc(1,sizeof(char)*map.roomx*map.roomy);
if (map.rooms[i+(j*map.xsize)+(k*map.xsize*map.ysize)]==NULL)
panic_oom("map.rooms2");
}
}
}
/*
f f f
z z z f
x x x z f
x x x z
x x x
*/
while(map_ch!=-1) {
roomx=get_int(level_file);
roomy=get_int(level_file);
roomz=get_int(level_file);
// skip_line(level_file);
printf("Loading room %i,%i,%i\n",roomx,roomy,roomz);
if ((roomx>map.xsize) || (roomy>map.ysize) || (roomz>map.zsize)) {
printf("Room horribly out of bounds!\n");
exit(1);
}
offset=roomx+(roomy*map.xsize)+(roomz*map.xsize*map.ysize);
printf("Offset=%i\n",offset);
current_room=map.rooms[offset];
x=0;y=0;
for(i=0;i<map.roomx;i++) {
for(j=0;j<map.roomy;j++) {
current_room[j*map.roomx+i]=' ';
}
}
while(map_ch<' ') map_ch=fgetc(level_file); // skip last '\n'
if (map_ch=='\n') map_ch=fgetc(level_file); // skip last '\n'
// printf("Next=%i %c\n",map_ch,map_ch);
while(y<map.roomy) {
// printf("%c",map_ch);
switch(map_ch) {
case 'T': tom.x=x; tom.y=y;
tom.roomx=roomx;
tom.roomy=roomy;
tom.roomz=roomz;
printf("Found Tom at %i,%i,%i\n",roomx,roomy,roomz);
map_ch=fgetc(level_file);
x++;
break;
case '#': current_room[y*map.roomx+x]='#';
map_ch=fgetc(level_file);
x++;
break;
case ' ':
map_ch=fgetc(level_file);
x++;
break;
case '/': current_room[y*map.roomx+x]='/';
map_ch=fgetc(level_file);
x++;
break;
case 'A': case 'G': case 'S':
map_ch=fgetc(level_file);
x++;
break;
case 'w':
map_ch=fgetc(level_file);
/* enemies[total_enemies].x=x;
enemies[total_enemies].y=y;
enemies[total_enemies].xadd=0;
enemies[total_enemies].yadd=1;
enemies[total_enemies].type='*';
total_enemies++;
*/
x++;
break;
case '\n': y++; x=0; map_ch=fgetc(level_file);break;
default:
printf("Unknown char '%c' (%i)\n",map_ch,map_ch);
map_ch=fgetc(level_file);
}
if (x>=map.roomx) {
while(map_ch!='\n') map_ch=fgetc(level_file);
map_ch=fgetc(level_file);
// printf("SKIP LINE, ch=%i\n",map_ch);
y++;
x=0;
}
}
}
clear_keyboard_buffer();
clear_framebuffer(framebuffer,0x0,' ');
for(i=0;i<map.roomx;i++) {
for(j=0;j<map.roomy;j++) {
printf("%c",current_room[i+j*map.roomx]);
}
printf("\n");
}
/* RANDOMIZE TIMER */
srand(time(NULL));
offset=tom.roomx+(tom.roomy*map.xsize)+(tom.roomz*map.xsize*map.ysize);
printf("Tom starting in room offset %i\n",offset);
current_room=map.rooms[offset];
while(!quit) {
clear_framebuffer(framebuffer,0x0,' ');
ch=0;
while( (ch=get_a_char()) ) {
switch(ch) {
case 'd': dump_screen=1; break;
case 'q': case 'Q':
if (verify_quit(framebuffer)) {
quit=1;
}
else {
game_paused=1;
}
break;
case 'j': if (tom.x>0) tom.xadd=-1;
else {
tom.xadd=0;
tom.x=(map.roomx-1);
tom.roomx--;
offset=tom.roomx+(tom.roomy*map.xsize)+(tom.roomz*map.xsize*map.ysize);
// printf("Tom starting in room offset %i\n",offset);
current_room=map.rooms[offset];
}
break;
case 'k': if (tom.x<SCREEN_WIDTH-1) tom.xadd=1;
else {
tom.xadd=0;
tom.x=0;
tom.roomx++;
offset=tom.roomx+(tom.roomy*map.xsize)+(tom.roomz*map.xsize*map.ysize);
// printf("Tom starting in room offset %i\n",offset);
current_room=map.rooms[offset];
}
break;
case 'i': if (tom.y>0) tom.yadd=-1;
else {
tom.yadd=0;
tom.y=(map.roomy-1);
tom.roomy--;
offset=tom.roomx+(tom.roomy*map.xsize)+(tom.roomz*map.xsize*map.ysize);
// printf("Tom starting in room offset %i\n",offset);
current_room=map.rooms[offset];
}
break;
case 'm': if (tom.y<SCREEN_HEIGHT-1) tom.yadd=1;
else {
tom.yadd=0;
tom.y=0;
tom.roomy++;
offset=tom.roomx+(tom.roomy*map.xsize)+(tom.roomz*map.xsize*map.ysize);
// printf("Tom starting in room offset %i\n",offset);
current_room=map.rooms[offset];
}
break;
case 'p':
put_attention_block(framebuffer,14);
put_text_xy(" GAME PAUSED! ",13,8,12,framebuffer);
dump_to_screen(framebuffer);
while (get_char()==0) usleep(5000);
game_paused=1;
break;
case 's': sound=!sound; /*level++;*/ break;
case 'h': help(framebuffer); /*game_paused=1;*/ break;
case ' ':
break;
}
}
/* Collision Detect Tom */
tempx=tom.x+tom.xadd;
tempy=tom.y+tom.yadd;
if (current_room[tempx+tempy*map.roomx]==' ') {
tom.x=tempx;
tom.y=tempy;
}
tom.xadd=0; tom.yadd=0;
/* Collision Detect Enemies */
for(i=0;i<total_enemies;i++) {
tempx=enemies[i].x+enemies[i].xadd;
if (current_room[tempx+enemies[i].y*map.roomx]==' ') {
enemies[i].x=tempx;
}
else enemies[i].xadd= -enemies[i].xadd;
tempy=enemies[i].y+enemies[i].yadd;
if (current_room[enemies[i].x+tempy*map.roomx]==' ') {
enemies[i].y=tempy;
}
else enemies[i].yadd= -enemies[i].yadd;
}
/* draw level */
for(i=0;i<map.roomx;i++) {
for(j=0;j<map.roomy;j++) {
switch(current_room[i+j*map.roomx]) {
case '#': blit( (char *)wall,framebuffer,'#',
i,j,1,1);
break;
case '/': blit( (char *)door,framebuffer,'/',
i,j,1,1);
break;
}
}
}
/* draw items */
/* draw enemies */
for(i=0;i<total_enemies;i++) {
blit( (char *)wisp,framebuffer,enemies[i].type,
enemies[i].x,enemies[i].y,1,1);
}
/* draw tom */
blit( (char *)tom_sprite,framebuffer,'T',
tom.x,tom.y,1,1);
dump_to_screen(framebuffer);
done_waiting=0;
while (!done_waiting) {
gettimeofday(&timing_info,NULL);
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_paused) {
gettimeofday(&timing_info,NULL);
oldusec=timing_info.tv_usec;
oldsec=timing_info.tv_sec;
game_paused=0;
}
}
put_attention_block(framebuffer,14);
put_text_xy(" GAME OVER! ",14,8,12,framebuffer);
dump_to_screen(framebuffer);
clear_keyboard_buffer();
clear_framebuffer(framebuffer,0,' ');
return 0;
}
int main(int argc, char **argv) {
static struct termios new_tty,old_tty;
char *framebuffer;
framebuffer=calloc(SCREEN_WIDTH*SCREEN_HEIGHT*BYTES_PER_PIXEL,sizeof(char));
/* setup non-blocking non-echo mode */
tcgetattr(0,&old_tty);
new_tty=old_tty;
new_tty.c_lflag&=~ICANON;
new_tty.c_cc[VMIN]=1;
new_tty.c_lflag&=~ECHO;
tcsetattr(0,TCSANOW,&new_tty);
fcntl(0,F_SETFL,fcntl(0,F_GETFL) | O_NONBLOCK);
/* clear screen */
printf("\033[2J\n");
new_game(framebuffer);
// done_the_game:
printf("%c\n",15);
tcsetattr(0,TCSANOW,&old_tty);
printf("%c[0m%c[255D\n",27,27);
return 0;
}

223
level3/level3.map Normal file
View File

@ -0,0 +1,223 @@
;
; Level 3 Map
;
; Xsize, Ysize, Zsize
3 3 1
; Roomx Roomy
24 20
; Room 0,0,0
0 0 0
########################
# # # #
# G # # S #
# # # #
# # # #
# # # #
# # # #
# #### #### #
# # w # #
#
#
#
# # # #
# # w # #
# #### #### #
# # # #
# # # #
# A # # #
# # # #
########### ##########
; Room 1,0,0
1 0 0
########################
# # # #
# G # # S #
# # # #
# # # #
# # # #
# # # #
# #### #### #
# # w # #
# # # #
# # w # #
# #### #### #
# # # #
# # # #
# A # # #
# # # #
########### ##########
; Room 2,0,0
2 0 0
########################
# # # #
# G # # S #
# # # #
# # # #
# # # #
# # # #
# #### #### #
# # w # #
#
#
#
# # # #
# # w # #
# #### #### #
# # # #
# # # #
# A # # #
# # # #
########### ##########
; Room 0,1,0
0 1 0
########### ##########
# # # #
# G # # S #
# # # #
# # # #
# # # #
# # # #
# #### #### #
# # w # #
#
#
#
# # # #
# # w # #
# #### #### #
# # # #
# # # #
# A # # #
# # # #
########### ##########
; Room 1,1,0
1 1 0
########### ##########
# # # #
# G # # S #
# # # #
# # # #
# # # #
# # # #
# #### #### #
# # w # #
# # # #
# # w # #
# #### #### #
# # # #
# # # #
# A # # #
# # # #
########### ##########
; Room 2,1,0
2 1 0
########### ##########
# # # #
# G # # S #
# # # #
# # # #
# # # #
# # # #
# #### #### #
# # w # #
#
#
#
# # # #
# # w # #
# #### #### #
# # # #
# # # #
# A # # #
# # # #
########### ##########
; Room 0,2,0
0 2 0
########### ##########
# # # #
# G # # S #
# # # #
# # # #
# # # #
# # # #
# #### #### #
# # w # #
#
#
#
# # # #
# # w # #
# #### #### #
# # # #
# # # #
# A # # #
# # # #
########################
; Room 1,2,0
1 2 0
########### ##########
# # # #
# G # # S #
# # # #
# # # #
# # # #
# # # #
# #### #### #
# # w # #
# # # #
# # w # #
# #### #### #
# # # #
# # # #
# A # # #
# # T # #
###########///##########
; Room 2,2,0
2 2 0
########### ##########
# # # #
# G # # S #
# # # #
# # # #
# # # #
# # # #
# #### #### #
# # w # #
#
#
#
# # # #
# # w # #
# #### #### #
# # # #
# # # #
# A # # #
# # # #
########################

View File

@ -29,7 +29,7 @@ void playthegame(tb1_state *game_state)
if (game_state->level==2) {
leveltwoengine(game_state,"level1/ships.tb1","level2/level2.dat",
"level2/tbaship.tb1"," LEVEL TWO:",
"THE \"PEASE ENVOY\"",NULL);
"THE \"PEACE ENVOY\"",NULL);
if (game_state->level==3) LevelThreeLittleOpener(game_state);
}
if (game_state->level==3) {

35
sound.c
View File

@ -50,10 +50,45 @@ void loadFX(char *path_to_data) {
int initSound(char *path_to_data) {
/* open the audio device */
#ifdef SDL_MIXER_SOUND
int audio_rate;
Uint16 audio_format;
int audio_channels;
/* Initialize variables */
audio_rate = MIX_DEFAULT_FREQUENCY;
audio_format = MIX_DEFAULT_FORMAT;
audio_channels = 2;
/* Initialize the SDL library */
if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
return(255);
}
/* Open the audio device */
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, 4096) < 0) {
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
return(2);
} else {
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
printf("+ Opened audio at %d Hz %d bit %s\n", audio_rate,
(audio_format&0xFF),
(audio_channels > 1) ? "stereo" : "mono");
}
/*
if(Mix_OpenAudio(22050, AUDIO_U16, 1, 1024) < 0) {
fprintf(stderr, "can't open audio: %s\n", SDL_GetError());
return -1;
}
*/
loadFX(path_to_data);
#endif
return 0;

View File

@ -1,14 +1,14 @@
Begin3
Title: tb1
Version: 2.9.14
Entered-date: 02JUN01
Version: 2.9.15
Entered-date: 28SEP04
Description: A 2d, sci-fi arcade game.
Shoot the aliens, save the world.
Keywords: tom bombem alien game arcade SDL curses
Author: vince@deater.net (Vince Weaver)
Maintained-by: vince@deater.net (Vince Weaver)
Primary-site: metalab.unc.edu /pub/Linux/games/arcade
400kB tb1-2.9.14.tar.gz
400kB tb1-2.9.15.tar.gz
Alternate-site: http://www.deater.net/weave/tb1
Original-site:
Platforms: Linux

2
tb1.c
View File

@ -230,7 +230,7 @@ int main(int argc,char **argv)
\* 3-96 oh well... gave up on Gus finally */
/* 5-11-96 Now Marie... *\
\* 9-22-2000 :( */
/* 3-25-2002 Now Kristina ;) */
/* Randomize random number generator */
srandom(time(NULL));