This commit is contained in:
Vince Weaver 2001-06-03 01:14:00 -04:00
parent 0b00dd2489
commit ec2657574c
16 changed files with 1148 additions and 330 deletions

View File

@ -1,3 +1,11 @@
2 June 2001
+ Made a super fancy level2 level editor. it's in the ./tools directory.
+ Verified that tb1 will in fact compile and run under windows with
the cygwin utils.
? April 2001
+ Added some minimal joypad support
11 November 2000
+ Got opengl sorta working, when I should be working on my
OS project involving semaphores. Oops.

View File

@ -73,3 +73,8 @@ A8). For game balancing issues. [And also because of speed/memory
If you really must have more, then you can probably find the
proper define in the source code and up the limit yourself.
Q9). Is the name "Tom Bombem" alliterative, shamelessly copying
a name like "Duke Nukem"?
A9). Yes

View File

@ -5,9 +5,9 @@ Hairold
Kevin
Leonard
Lizann
Vinnie
Pete
Vince
Jim
Vinnie
5000
4500
4000
@ -15,6 +15,6 @@ Jim
3000
2500
2000
1740
1500
1160
1000
1490

273
data/level2/level2.dat.new Normal file
View File

@ -0,0 +1,273 @@
# Level 2 data
%SPRITEFILE tbaship.tb1
%SPRITEXSIZE 20
%SPRITEYSIZE 10
%SPRITEROWS 4
%SPRITECOLS 10
# NUM TYPE
%SPRITE 0 BACKGROUND
%SPRITE 1 BACKGROUND
%SPRITE 2 BACKGROUND
%SPRITE 3 BACKGROUND
%SPRITE 4 BACKGROUND
%SPRITE 5 BACKGROUND
%SPIRTE 6 BACKGROUND
%SPRITE 7 BACKGROUND
%SPRITE 8 BACKGROUND
%SPRITE 9 BACKGROUND
# Shoots ExplodesTo
%SPRITE 10 ENEMY_REFLECT 21 34
%SPRITE 11 ENEMY_SHOOT 26 34
%SPRITE 12 ENEMY_SHOOT 25 34
%SPRITE 13 ENEMY_SHOOT 25 34
%SPRITE 14 ENEMY_SHOOT 25 34
%SPRITE 15 OBSTRUCTION 34
%SPRITE 16 OBSTRUCTION 34
%SPRITE 17 OBSTRUCTION 34
%SPRITE 18 OBSTRUCTION 34
%SPRITE 19 OBSTRUCTION 34
%SPRITE 20 WEAPON 0
%SPRITE 21 ENEMY_WEAPON
%SPRITE 22
%SPRITE 23
%SPRITE 24
%SPRITE 25 ENEMY_WEAPON
%SPRITE 26 ENEMY_WEAPON
%SPRITE 27
%SPRITE 28
%SPRITE 29 BACKGROUND
%SPRITE 30 BACKGROUND
%SPRITE 31 BACKGROUND
%SPRITE 32 BACKGROUND
%SPRITE 33 BACKGROUND
# exploded, but same as backgroud
%SPRITE 34 BACKGROUND
%SPRITE 35 EXPLOSION 0
%SPRITE 36 EXPLOSION 1
%SPRITE 37 EXPLOSION 2
%SPRITE 38 EXPLOSION 3
%SPRITE 39 EXPLOSION 4
%DATALENGTH 202
%DATAWIDTH 12
%DATABEGIN
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 1 0 4 0 0 0 4 0 0
0 1 0 1 0 4 0 0 0 4 0 0
0 1 0 1 0 4 0 4 0 4 0 0
0 0 1 0 0 0 4 0 4 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
30 30 30 30 30 30 30 30 30 30 30 30
15 0 10 0 10 4 4 10 0 10 0 15
15 0 0 0 10 10 10 10 0 0 0 15
15 0 0 10 3 3 3 3 10 0 0 15
15 10 0 0 0 0 0 0 0 0 10 15
15 5 5 5 5 5 5 5 5 5 5 15
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
16 13 16 16 16 16 16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 5 30 30 30 30 5 3 5 5
5 7 5 5 5 5 5 5 5 5 7 5
31 31 31 31 31 31 31 31 31 31 31 31
%DATAEND
5 5 5 5 4 4 4 4 5 5 5 5
5 5 3 5 30 30 30 30 5 3 5 5
5 7 5 5 5 5 5 5 5 5 7 5
31 31 31 31 31 31 31 31 31 31 31 31
%DATAEND

View File

@ -24,7 +24,7 @@
#include "graphic_tools.h"
/* Define this to get a frames per second readout */
#define DEBUG_ON
/*#define DEBUG_ON */
/* The sounds */
@ -88,6 +88,7 @@ typedef struct {
}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},

View File

@ -5,13 +5,16 @@ LIBS= $(LIBS_GLOBAL)
all: libsvmwgraph.a
libsvmwgraph.a: vmw_core.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_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)
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
vmw_dialogs.o: vmw_dialogs.c
$(CC) $(INCLUDE) -c vmw_dialogs.c
vmw_flip.o: vmw_flip.c
$(CC) $(INCLUDE) -c vmw_flip.c

View File

@ -11,12 +11,13 @@ void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp,
{
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) < 0 ) {
if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 ) {
fprintf(stderr,
"Couldn't initialize SDL: %s\n", SDL_GetError());
return NULL;
@ -25,6 +26,18 @@ void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp,
/* 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 */
@ -253,11 +266,52 @@ void SDL_clearKeyboardBuffer() {
int SDL_getInput() {
SDL_Event event;
int keypressed;
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) {
@ -272,6 +326,10 @@ int SDL_getInput() {
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;

View File

@ -75,7 +75,10 @@ typedef struct {
#define VMW_F3 1032
#define VMW_PGUP 1050
#define VMW_PGDN 1051
#define VMW_HOME 1052
#define VMW_END 1053
#define VMW_INS 1054
#define VMW_DEL 1055
/* Function declarations */
@ -173,3 +176,12 @@ void vmwPutPartialSprite(vmwVisual *destination,
int x_start,int x_stop,
int y_start,int y_stop);
/* vmw_dialogs.c */
void vmwCoolBox(int x1,int y1,int x2,int y2,int fill,vmwVisual *target);
int vmwAreYouSure(vmwSVMWGraphState *graph_state,
vmwFont *tb1_font,
vmwVisual *target,
char *warning_1,
char *warning_2,
char *yes_option,
char *no_option);

56
svmwgraph/vmw_dialogs.c Normal file
View File

@ -0,0 +1,56 @@
#include "svmwgraph.h"
#include <unistd.h> /* usleep */
/* MAKE SURE YOU DO A COOLBOX TO 319,199, not 320,200!!! */
/* This will cause HARD TO DEBUG BUGS!!! */
/* I should add a check here I suppose */
void vmwCoolBox(int x1,int y1,int x2,int y2,int fill,vmwVisual *target)
{
int i;
for(i=0;i<5;i++) {
vmwDrawHLine(x1+i,y1+i,(x2-x1-i-i),31-i,target);
vmwDrawHLine(x1+i,y2-i,(x2-x1-i-i),31-i,target);
vmwDrawVLine(x1+i,y1+i,(y2-y1-i-i)+1,31-i,target);
vmwDrawVLine(x2-i,y1+i,(y2-y1-i-i)+1,31-i,target);
}
if (fill) {
for(i=y1+5;i<y2-4;i++) vmwDrawHLine(x1+5,i,(x2-x1-9),7,target);
}
}
int vmwAreYouSure(vmwSVMWGraphState *graph_state,
vmwFont *tb1_font,
vmwVisual *target,
char *warning_1,
char *warning_2,
char *yes_option,
char *no_option) {
int barpos=0,ch=0;
vmwCoolBox(90,75,230,125,1,target);
vmwTextXY(warning_1,97,82,9,7,0,tb1_font,target);
vmwTextXY(warning_2,97,90,9,7,0,tb1_font,target);
while (ch!=VMW_ENTER){
if (barpos==0) vmwTextXY(yes_option,97,98,150,0,1,tb1_font,target);
else vmwTextXY(yes_option,97,98,150,7,1,tb1_font,target);
if (barpos==1) vmwTextXY(no_option,97,106,150,0,1,tb1_font,target);
else vmwTextXY(no_option,97,106,150,7,1,tb1_font,target);
vmwBlitMemToDisplay(graph_state,target);
while ( !(ch=vmwGetInput()) ) {
usleep(30);
}
if ((ch==VMW_UP)||(ch==VMW_DOWN)||(ch==VMW_LEFT)||(ch==VMW_RIGHT)) barpos++;
if (ch=='y') barpos=0;
if (ch=='n') barpos=1;
if (barpos==2) barpos=0;
}
return !barpos;
}

View File

@ -1,15 +1,15 @@
Begin3
Title: tb1
Version: 2.9.12
Entered-date: 03NOV00
Version: 2.9.14
Entered-date: 02JUN01
Description: A 2d, sci-fi arcade game.
Shoot the aliens, save the world.
Keywords: tom bombem alien game arcade SDL curses
Author: weave@eng.umd.edu (Vince Weaver)
Maintained-by: weave@eng.umd.edu (Vince Weaver)
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.12.tar.gz
Alternate-site: http://www.glue.umd.edu/~weave/tb1
400kB tb1-2.9.14.tar.gz
Alternate-site: http://www.deater.net/weave/tb1
Original-site:
Platforms: Linux
Copying-policy: GPL

10
tb1.c
View File

@ -1,7 +1,7 @@
/****************************************************************\
\* TOM BOMBEM AND THE INVASION OF THE INANIMATE_OBJECTS */
/* version 2.9.12 3 November 2000 *\
\* by Vince Weaver weave@eng.umd.edu */
/* version 2.9.14 3 June 2001 *\
\* by Vince Weaver vince@deater.net */
/* *\
\* Originally written in Pascal and x86 assembly for DOS */
/* using the PCGPE code as an example in 1994 *\
@ -10,7 +10,7 @@
\* This source is released under the GPL */
/****************************************************************/
#define TB1_VERSION "2.9.13"
#define TB1_VERSION "2.9.14"
#include <stdio.h>
#include <stdlib.h> /* for calloc */
@ -112,8 +112,8 @@ int main(int argc,char **argv)
struct timeval time_info;
struct timezone dontcare;
printf("\nTom Bombem v%s by Vince Weaver weave@eng.umd.edu\n",TB1_VERSION);
printf(" http://www.glue.umd.edu/~weave/tb1\n\n");
printf("\nTom Bombem v%s by Vince Weaver vince@deater.net\n",TB1_VERSION);
printf(" http://www.deater.net/weave/tb1\n\n");
/* Setup the game state */
if ( (game_state=calloc(1,sizeof(tb1_state)))==NULL) {

35
tblib.c
View File

@ -56,32 +56,13 @@ int are_you_sure(tb1_state *game_state,
char *no_option) {
int barpos=0,ch=0;
return vmwAreYouSure(game_state->graph_state,
game_state->graph_state->default_font,
game_state->virtual_1,
warning_1,
warning_2,
yes_option,
no_option);
vmwFont *tb1_font;
vmwVisual *target;
tb1_font=game_state->graph_state->default_font;
target=game_state->virtual_1;
coolbox(90,75,230,125,1,target);
vmwTextXY(warning_1,97,82,9,7,0,tb1_font,target);
vmwTextXY(warning_2,97,90,9,7,0,tb1_font,target);
while (ch!=VMW_ENTER){
if (barpos==0) vmwTextXY(yes_option,97,98,150,0,1,tb1_font,target);
else vmwTextXY(yes_option,97,98,150,7,1,tb1_font,target);
if (barpos==1) vmwTextXY(no_option,97,106,150,0,1,tb1_font,target);
else vmwTextXY(no_option,97,106,150,7,1,tb1_font,target);
vmwBlitMemToDisplay(game_state->graph_state,target);
while ( !(ch=vmwGetInput()) ) {
usleep(30);
}
if ((ch==VMW_UP)||(ch==VMW_DOWN)||(ch==VMW_LEFT)||(ch==VMW_RIGHT)) barpos++;
if (ch=='y') barpos=0;
if (ch=='n') barpos=1;
if (barpos==2) barpos=0;
}
return !barpos;
}

1
tools/LEVEL2_EDIT.TODO Normal file
View File

@ -0,0 +1 @@
* XOR'd cursor instead of white

View File

@ -3,8 +3,11 @@ include ../Makefile.inc
INCLUDE= $(INCLUDE_GLOBAL) -I../svmwgraph
LIBS= $(LIBS_GLOBAL)
all: ppro_view pcx2ppp
all: ppro_view pcx2ppp level2_editor
level2_editor: level2_editor.o ../svmwgraph/libsvmwgraph.a
gcc -o level2_editor level2_editor.o ../svmwgraph/libsvmwgraph.a $(LIBS)
benchmark: benchmark.o ../svmwgraph/libsvmwgraph.a
gcc -o benchmark benchmark.o ../svmwgraph/libsvmwgraph.a $(LIBS)
@ -17,6 +20,9 @@ pcx2ppp: pcx2ppp.o ../svmwgraph/libsvmwgraph.a
../svmwgraph/libsvmwgraph.a:
cd ../svmwgraph && make
level2_editor.o: level2_editor.c
gcc -c level2_editor.c $(INCLUDE)
benchmark.o: benchmark.c
gcc -c benchmark.c $(INCLUDE)
@ -27,4 +33,4 @@ ppro_view.o: ppro_view.c
gcc -c ppro_view.c $(INCLUDE)
clean:
rm -f ppro_view pcx2ppp benchmark *.o *~
rm -f ppro_view pcx2ppp benchmark level2_editor *.o *~

View File

@ -1,279 +0,0 @@
#define TB1_VERSION "2.9.0"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include <ggi/libggi.h>
#include "../svmwgrap.h"
#include "../gtblib.h"
/* Exported Global Variables */
ggi_visual_t vis,vaddr,vaddr2;
vmw_font *tb1_font;
uint white;
ggi_color eight_bit_pal[256];
ggi_pixel tb1_pal[256];
int color_depth;
ggi_directbuffer_t dbuf_vis,dbuf_vaddr,dbuf_vaddr2;
ggi_pixellinearbuffer *plb_vis = NULL,*plb_vaddr= NULL,*plb_vaddr2=NULL;
int stride_factor=1;
int sound_enabled=1,sound_possible=1,read_only_mode=0;
char path_to_data[256];
struct timeval time_info;
struct timezone dontcare;
/*----------------*/
int game_map[12][200];
int max_x,max_y,u_x,u_y,x_pos=0,y_pos=0,x,y;
char tempst[40];
/* Setup the Graphics */
int setup_graphics(int force_8bpp)
{
int err;
ggi_mode mode;
int vx,vy,sx,sy;
ggiInit();
vis=ggiOpen(NULL);
if (force_8bpp)
err=ggiSetGraphMode(vis,320,200,320,200,GT_8BIT);
else
err=ggiSetGraphMode(vis,320,200,320,200,GGI_AUTO);
if (err) {
fprintf(stderr,"ERROR! Problem opening 320x200 vis\n\n");
return 2;
}
ggiGetMode(vis,&mode);
vx=mode.virt.x; vy=mode.virt.y;
sx=mode.visible.x;sy=mode.visible.y;
switch (mode.graphtype) {
case GT_1BIT: color_depth=1;break;
case GT_4BIT: color_depth=4;break;
case GT_8BIT: color_depth=8;break;
case GT_15BIT: color_depth=15;break;
case GT_16BIT: color_depth=16;break;
case GT_24BIT: color_depth=24;break;
case GT_32BIT: color_depth=32;break;
default: break;
}
printf(" + Opened a %d x %d (%d x %d) mode with %d bpp\n",
sx,sy,vx,vy,color_depth);
err = ggiDBGetBuffer (vis, &dbuf_vis);
if (err) {
printf("Error! Could not get directbuffer\n");
return 2;
}
if (!(ggiDBGetLayout (dbuf_vis) == blPixelLinearBuffer)) {
printf("Error! Nonlinear Display Buffer.\n");
return 2;
}
if (!(plb_vis = ggiDBGetPLB (dbuf_vis)) ) {
printf("Error! Problem getting pixel linear buffer.\n");
return 2;
}
vaddr=ggiOpen("display-memory",NULL);
err=ggiSetGraphMode(vaddr,320,200,320,200,mode.graphtype);
if (err) {
printf("ERROR! Problem opening 320x200x%d vaddr\n",color_depth);
return 2;
}
err = ggiDBGetBuffer (vaddr, &dbuf_vaddr);
if (err) {
printf("Error! Could not get directbuffer\n");
return 2;
}
if (!(ggiDBGetLayout (dbuf_vaddr) == blPixelLinearBuffer)) {
printf("Error! Nonlinear Display Buffer.\n");
return 2;
}
if (!(plb_vaddr = ggiDBGetPLB (dbuf_vaddr)) ) {
printf("Error! Problem getting pixel linear buffer.\n");
return 2;
}
vaddr2=ggiOpen("display-memory",NULL);
err=ggiSetGraphMode(vaddr2,320,400,320,400,mode.graphtype);
if (err){
printf("ERROR! Problem opening 320x400x%d vaddr2\n",color_depth);
return 2;
}
err = ggiDBGetBuffer (vaddr2, &dbuf_vaddr2);
if (err) {
printf("Error! Could not get directbuffer\n");
return 2;
}
if (!(ggiDBGetLayout (dbuf_vaddr2) == blPixelLinearBuffer)) {
printf("Error! Nonlinear Display Buffer.\n");
return 2;
}
if (!(plb_vaddr2 = ggiDBGetPLB (dbuf_vaddr2)) ) {
printf("Error! Problem getting pixel linear buffer.\n");
return 2;
}
stride_factor=(plb_vis->stride)/320;
printf(" + Using a stride factor of %d\n",stride_factor);
printf(" + GGI Graphics Initialization successful...\n");
printf(" + Running TB1 in %dbpp Mode...\n",color_depth);
return 0;
}
int command_line_help(int show_version,char *runas)
{
if (!show_version) {
printf("Usage: %s [-force8bpp] [-nosound] [-readonly]"
" [-version] [-?]\n\n",runas);
printf(" -force8bpp : force to run in 8bpp mode\n");
printf(" -version : print version\n");
printf(" -? : print this help message\n");
printf("\n");
}
return 0;
}
int main(int argc,char **argv)
{
int i,grapherror,reloadpic=0,force_8bpp=0;
int ch,ch2,x,barpos,time_sec;
char *tempst[300];
FILE *fff;
printf("\nTom Bombem Level Editor by Vince Weaver weave@eng.umd.edu\n");
printf(" http://www.glue.umd.edu/~weave/tb1\n\n");
/* Parse Command Line Arguments */
i=1;
while(i<argc) {
if (argv[i][0]=='-') {
switch (argv[i][1]) {
case 'h': case '?':
command_line_help(0,argv[0]); return 5; break;
case 'v':
command_line_help(1,argv[0]); return 5; break;
case 'f':
force_8bpp=1; 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*/
/* Randomize random number generator */
srandom(time(NULL));
/* Load the tom bombem font */
tb1_font=LoadVMWFont("../data/tbfont.tb1",8,16,256);
/* Setup Graphics */
if (setup_graphics(force_8bpp)==2) {
fprintf(stderr,"ERROR: Couldn't get display set up properly.\n");
return 2;
}
/* ggiDrawVLine(vis,x+200,45+(2*x),80-(2*x));
}
ggiSetGCForeground(vis,tb1_pal[15]);
VMWtextxy("A VMW SOFTWARE PRODUCTION",60,140,
tb1_pal[15],tb1_pal[15],0,tb1_font,vis);
ggiFlush(vis);
pauseawhile(5);
ggiSetGCForeground(vis,tb1_pal[0]);
ggiFillscreen(vis);
Load the title screen */
grapherror=GGILoadPicPacked(0,0,vis,1,1,
"../data/tbomb1.tb1",
(ggi_color *)&eight_bit_pal,
(ggi_pixel *)&tb1_pal,color_depth);
grapherror=GGILoadPicPacked(0,0,vaddr2,1,1,
"../data/tbomb1.tb1",
(ggi_color *)&eight_bit_pal,
(ggi_pixel *)&tb1_pal,color_depth);
ggiFlush(vis);
ggiFlush(vaddr2);
pauseawhile(5);
max_x=12;max_y=200;
x_pos=0; y_pos=0;
for(x=0;x<max_x;x++)
for(y=0;y<max_y;y++)
game_map[x][y]=(rand()%26)+65;
/* Main Menu Loop */
while (1) {
vmwCrossBlit(plb_vis->write,plb_vaddr->read,plb_vis->stride,200);
ggiFlush(vis);
barpos=0;
ggiFlush(vis);
ch=0;
while( ((ch=get_input())==0)) {
usleep(10);
}
/* Change menu position based on key pressed */
ch2=toupper(ch);
if (ch==TB_DOWN) y_pos++;
if (ch==TB_RIGHT) x_pos++;
if (ch==TB_UP) y_pos--;
if (ch==TB_LEFT) x_pos--;
if (y_pos<0) y_pos=0; if(x_pos<0) x_pos=0;
if (y_pos>(max_y-20)) y_pos=max_y-20;
if (x_pos>(max_x)) x_pos=max_x;
ggiSetGCForeground(vaddr,tb1_pal[0]);
ggiFillscreen(vaddr);
for(x=0;x<max_x;x++)
for(y=y_pos;y<(y_pos+20);y++) {
sprintf(tempst,"%c",game_map[x][y]);
VMWtextxy(tempst,x*20,(y-y_pos)*10,
tb1_pal[32],tb1_pal[0],1,tb1_font,vaddr);
}
if (ch2=='Q') barpos=6; /*Q*/
if (ch==27){ /* escape */
barpos=6;
ch=TB_ENTER;
}
if(barpos==7) barpos=0;
if(barpos<0) barpos=6;
/* Run whatever it was that the person pressed */
if(barpos==6) quit();
}
}

693
tools/level2_editor.c Normal file
View File

@ -0,0 +1,693 @@
#include <stdio.h>
#include <string.h> /* strncmp */
#include <unistd.h> /* usleep */
#include <stdlib.h> /* free */
#include "../svmwgraph/svmwgraph.h"
#define ROW_WIDTH 12
/* #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 UNDO_DEPTH 10
int undo_head=0;
int undo_tail=0;
int modified_since_save=0;
struct undo_type {
int type;
int x,y;
int value;
int row[ROW_WIDTH];
} undo_data[UNDO_DEPTH];
#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)) {
return text_mapping[i].type;
}
i++;
}
return -1;
}
int print_level(FILE *fff,struct level2_data *data) {
int i,j;
fprintf(fff,"%%DATALENGTH %i\n",data->level_length);
fprintf(fff,"%%DATAWIDTH %i\n",data->level_width);
fprintf(fff,"%%DATABEGIN\n");
for(j=0;j<data->level_length;j++) {
for(i=0;i<data->level_width;i++) {
fprintf(fff,"%3d ",*(data->level_data[j]+i));
}
fprintf(fff,"\n");
}
fprintf(fff,"%%DATAEND\n");
return 0;
}
int save_data(char *filename,struct level2_data *data) {
FILE *fff;
char tempst[255];
long filepos,good_pos=-1;
fff=fopen(filename,"r+");
do {
filepos=ftell(fff);
fgets(tempst,254,fff);
if (!strncmp(tempst,"%DATA",5)) {
good_pos=filepos;
break;
}
} while(!feof(fff));
if (good_pos<0) return -1;
fseek(fff,good_pos,SEEK_SET);
print_level(fff,data);
return 0;
}
int print_level_reverse(struct level2_data *data) {
int i,j;
for(j=data->level_length-1;j>=0;j--) {
for(i=0;i<data->level_width;i++) {
printf("%3d ",*(data->level_data[j]+i));
}
printf("\n");
}
return 0;
}
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;i<data->level_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(i<data->level_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;
}
int draw_all_sprites(int y_offset,struct level2_data *data,
vmwVisual *virtual_1){
int i,j;
for(i=0;i<12;i++) {
for(j=0;j<20;j++) {
vmwPutSpriteNonTransparent(data->sprites[(int) *(data->level_data[j+y_offset]+i)
]->data,i*20,j*10,virtual_1);
}
}
return 0;
}
int delete_line(struct level2_data *data, int y) {
unsigned char **temp_data;
int i;
/* Overly Complicated way of deleting line */
/* Create new data, 1 line shorter */
temp_data=calloc(data->level_length-1, sizeof(char *));
temp_data[0]=calloc( (data->level_length-1) * data->level_width,sizeof(char));
/* Copy old data over, removing the one line */
memcpy(temp_data[0],data->level_data[0],(y*ROW_WIDTH));
memcpy(temp_data[0]+(y*ROW_WIDTH),data->level_data[0]+((y+1)*ROW_WIDTH),((data->level_length-y)-1)*ROW_WIDTH);
/* Free the old data */
free(data->level_data[0]);
free(data->level_data);
/* We are now one line shorter */
data->level_length--;
/* New data magically becomes real data */
data->level_data=temp_data;
/* Setup pointers so we can pretend we have an array */
for(i=1;i<data->level_length;i++) {
data->level_data[i]=data->level_data[0]+ (i*data->level_width*sizeof(char));
}
return 0;
}
int insert_line(struct level2_data *data, int y) {
unsigned char **temp_data;
int i;
/* Overly Complicated way of inserting line */
/* Create new data, 1 line longer */
temp_data=calloc(data->level_length+1, sizeof(char *));
temp_data[0]=calloc( (data->level_length+1) * data->level_width,sizeof(char));
/* Copy old data over, adding one line */
memcpy(temp_data[0],data->level_data[0],(y*ROW_WIDTH));
memcpy(temp_data[0]+((y+1)*ROW_WIDTH),data->level_data[0]+(y*ROW_WIDTH),((data->level_length-y))*ROW_WIDTH);
/* Free the old data */
free(data->level_data[0]);
free(data->level_data);
/* We are now one line shorter */
data->level_length++;
/* New data magically becomes real data */
data->level_data=temp_data;
/* Setup pointers so we can pretend we have an array */
for(i=1;i<data->level_length;i++) {
data->level_data[i]=data->level_data[0]+ (i*data->level_width*sizeof(char));
}
return 0;
}
#define CHANGE_SPRITE 0
#define INSERT_LINE 1
#define DELETE_LINE 2
int undo(struct level2_data *data) {
int i;
/* Cicrular buffer. Avoid overflows. Any data older than */
/* UNDO_DEPTH is lost */
if (undo_data[undo_head].type==CHANGE_SPRITE) {
*(data->level_data[undo_data[undo_head].y]+undo_data[undo_head].x)=
undo_data[undo_head].value;
}
if (undo_data[undo_head].type==INSERT_LINE) {
delete_line(data,undo_data[undo_head].y);
}
if (undo_data[undo_head].type==DELETE_LINE) {
/* Re-insert line */
insert_line(data,undo_data[undo_head].y);
/* Restore data */
for(i=0;i<ROW_WIDTH;i++) {
*(data->level_data[undo_data[undo_head].y]+i)=undo_data[undo_head].row[i];
}
}
if (undo_head!=undo_tail) {
undo_head--;
if (undo_head<0) undo_head=UNDO_DEPTH;
}
return 0;
}
int modify_level(struct level2_data *data,int x,int y,int type,int value) {
int i;
modified_since_save++;
/* Protect if you've made more than 2billion changes */
/* Unlikely, but the fix is shorter than the comment */
/* I was originally going to make about "broken if you*/
/* change more than 2 billion things" */
if (modified_since_save<0) modified_since_save=1;
/* Cicrular buffer. Avoid overflows. Any data older than */
/* UNDO_DEPTH is lost */
undo_head++;
if (undo_head>=UNDO_DEPTH) undo_head=0;
if (undo_head==undo_tail) {
undo_tail=undo_head+1;
if (undo_tail>=UNDO_DEPTH) undo_tail=0;
}
if (type==CHANGE_SPRITE) {
undo_data[undo_head].type=CHANGE_SPRITE;
undo_data[undo_head].x=x;
undo_data[undo_head].y=y;
undo_data[undo_head].value= *(data->level_data[y]+x);
*(data->level_data[y]+x)=value;
}
if (type==DELETE_LINE) {
undo_data[undo_head].type=DELETE_LINE;
undo_data[undo_head].y=y;
for(i=0;i<ROW_WIDTH;i++)
undo_data[undo_head].row[i]=*(data->level_data[y]+i);
delete_line(data,y);
}
if (type==INSERT_LINE) {
undo_data[undo_head].type=INSERT_LINE;
undo_data[undo_head].y=y;
insert_line(data,y);
}
return 0;
}
int main(int argc, char **argv) {
struct level2_data *data;
vmwSVMWGraphState *graph_state;
vmwVisual *virtual_1;
int ch,i,j,y_offset=0;
int x=0,y=0;
char tempst[10];
int sprite_array[16];
int sprite_offset=0;
int doublesize=1,fullscreen=0;
int argsfound=0;
char filename[255],spritefile[255];
/* Parse command line arguments */
i=1;
while(i<argc) {
if (argv[i][0]=='-') {
if (argv[i][1]=='d') doublesize=2;
if (argv[i][1]=='f') fullscreen=1;
}
else {
argsfound++;
if (argsfound==1) strncpy(filename,argv[i],254);
if (argsfound==2) strncpy(spritefile,argv[i],254);
}
i++;
}
if (argsfound<2) {
printf("\nUSAGE: %s [-f] [-d] data_file sprite_file\n\n",argv[0]);
return -1;
}
printf("Editing datafile=%s spritefile=%s\n",filename,spritefile);
data=parse_data_file(filename);
graph_state=vmwSetupSVMWGraph(VMW_SDLTARGET,doublesize*320,doublesize*200,0,doublesize,fullscreen,1);
graph_state->default_font=vmwLoadFont("../data/tbfont.tb1",8,16,256);
virtual_1=vmwSetupVisual(320,200);
if (vmwLoadPicPacked(0,0,virtual_1,1,1,spritefile,graph_state)!=0) {
printf("ERROR LOADING %s\n",spritefile);
return -1;
}
for(j=0;j<data->rows;j++)
for(i=0;i<data->cols;i++)
data->sprites[j*10+i]->data=vmwGetSprite(1+i*21,1+j*11,20,10,virtual_1);
vmwDrawBox(0,0,319,199,0,virtual_1);
draw_all_sprites(0,data,virtual_1);
vmwBlitMemToDisplay(graph_state,virtual_1);
ch=' ';
while(1) {
switch(ch) {
case 'A'...'P' : if (sprite_array[ch-0x41]!=-1)
modify_level(data,x,y+y_offset,CHANGE_SPRITE,
sprite_array[ch-0x41]);
break;
case 'a'...'p' : if (sprite_array[ch-0x61]!=-1)
modify_level(data,x,y+y_offset,CHANGE_SPRITE,
sprite_array[ch-0x61]);
break;
case 's': case 'S': save_data(filename,data);
modified_since_save=0;
break;
case 'u': case 'U': undo(data);
break;
case 'q': case 'Q': if (modified_since_save) {
if (vmwAreYouSure(graph_state,
graph_state->default_font,
virtual_1,
"FILE HAS CHANGED",
"QUIT W/O SAVING?",
"YES-QUIT ANYWAY",
"NO!-LET ME SAVE")) return 0;
}
else return 0;
break;
case '>': case '.': i=0; j=sprite_offset;
while ( (i<16) && (j<data->numsprites)) {
if ((data->sprites[j]->initialized)
&& (belongs_on_map(data->sprites[j]->type))) {
i++;
}
j++;
}
if (j<data->numsprites) sprite_offset=j;
break;
case '<': case ',': i=0; j=sprite_offset;
while ( (i<16) && (j>0)) {
if ((data->sprites[j]->initialized) &&
(belongs_on_map(data->sprites[j]->type))) {
i++;
}
j--;
}
if (j>=0) sprite_offset=j;
break;
case VMW_UP: if (y>0) y--;
else if (y_offset>0) y_offset--;
break;
case VMW_DOWN: if (y>=19) {
if (y_offset<data->level_length-21) y_offset++;
}
else y++;
break;
case VMW_RIGHT: if (x<11) x++; break;
case VMW_LEFT: if (x>0) x--; break;
case VMW_PGUP: if (y_offset>20) y_offset-=20;
else (y_offset=0);
break;
case VMW_PGDN: if (y_offset<data->level_length-41) y_offset+=20;
else y_offset=data->level_length-20;
break;
case VMW_HOME: y_offset=0; break;
case VMW_END: y_offset=data->level_length-20; break;
case VMW_INS: modify_level(data,0,y+y_offset,INSERT_LINE,0);
break;
case VMW_DEL: modify_level(data,0,y+y_offset,DELETE_LINE,0);
break;
}
/* Make sure if we delete a line it doesn't make us */
/* try to display off the end of the screen */
if (y_offset>=data->level_length-20) y_offset=data->level_length-20;
draw_all_sprites(y_offset,data,virtual_1);
/* Draw cursor box */
vmwDrawHLine(x*20,y*10,20,15,virtual_1);
vmwDrawHLine(x*20,(y*10)+9,20,15,virtual_1);
vmwDrawVLine(x*20,y*10,10,15,virtual_1);
vmwDrawVLine((x*20)+19,y*10,10,15,virtual_1);
vmwDrawBox(240,0,79,199,0,virtual_1);
sprintf(tempst,"X: %4d",x);
vmwTextXY(tempst,245,5,9,0,0,graph_state->default_font,virtual_1);
sprintf(tempst,"Y: %4d",y+y_offset);
vmwTextXY(tempst,245,15,9,0,0,graph_state->default_font,virtual_1);
sprintf(tempst,"L: %4d",data->level_length);
vmwTextXY(tempst,245,25,9,0,0,graph_state->default_font,virtual_1);
vmwDrawHLine(243,38,74,12,virtual_1);
vmwDrawHLine(243,150,74,12,virtual_1);
sprintf(tempst,"%c",'<');
vmwTextXY(tempst,275,40,11,0,0,graph_state->default_font,virtual_1);
sprintf(tempst,"%c",'>');
vmwTextXY(tempst,275,140,11,0,0,graph_state->default_font,virtual_1);
if (sprite_offset>=data->numsprites) sprite_offset=0;
if (sprite_offset<0) sprite_offset=0;
j=sprite_offset;
for(i=0;i<16;i++) {
sprintf(tempst,"%c",0x41+i);
while ((j<data->numsprites) &&
((!data->sprites[j]->initialized) || (!belongs_on_map(data->sprites[j]->type)))) {
j++;
}
if (j<data->numsprites) {
sprite_array[i]=j;
vmwTextXY(tempst,((i/8)*61)+245,((i%8)*11)+50,11,0,0,graph_state->default_font,virtual_1);
vmwPutSpriteNonTransparent(data->sprites[j]->data,
((i/8)*21)+260, ((i%8)*11)+50,virtual_1);
j++;
}
else sprite_array[i]=-1;
}
vmwTextXY("INS DEL",245,155,11,0,0,graph_state->default_font,virtual_1);
vmwTextXY(" , ",245,155,9,0,0,graph_state->default_font,virtual_1);
vmwTextXY(" ndo",245,165,9,0,0,graph_state->default_font,virtual_1);
vmwTextXY("U",245,165,11,0,0,graph_state->default_font,virtual_1);
vmwTextXY(" ave",245,175,9,0,0,graph_state->default_font,virtual_1);
vmwTextXY("S",245,175,11,0,0,graph_state->default_font,virtual_1);
if (modified_since_save)
vmwTextXY(" *",245,175,12,0,0,graph_state->default_font,virtual_1);
vmwTextXY(" uit",245,185,9,0,0,graph_state->default_font,virtual_1);
vmwTextXY("Q",245,185,11,0,0,graph_state->default_font,virtual_1);
vmwBlitMemToDisplay(graph_state,virtual_1);
while( ((ch=vmwGetInput())==0)) {
usleep(30);
}
}
return 0;
}