DYNA/DYNA_TBL.CPP
2021-09-08 21:02:03 +02:00

963 lines
39 KiB
C++
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**************************************************************************\
|* *|
|* DYNA_TBL *|
|* *|
|* Descripci¢n: *|
|* M¢dulo encargado de cargar los elementos del tablero y *|
|* enemigos del juegos. Tambin se encarga de generar el *|
|* tablero seg£n preferencias de usuario... *|
|* *|
|* Fecha: 17-07-96 00.08 / 01.34 *|
|* 18-07-96 12.51 / 14.24 *|
|* 15.10 / *|
|* 19-07-96 *|
\**************************************************************************/
#include "..\libs\int_key\int_key.h"
#include <dos.h>
#include <alloc.h>
#include <stdio.h>
#include "Dyna_tbl.h"
#include "..\modex\modex.h"
#include "..\modex\c_utils.h"
#include <conio.h>
#include <stdlib.h>
//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û
///ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ
//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û
#define KEYBOARDINTR 9
#define KEYBOARDPORT 0x60
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
void interrupt (*BIOSKeyboardHandler)(__CPPARGS);
char CallBIOSHandler = 0;
//( int Flags, int CS, int IP, int AX, int BX, int CX, int DX, int SI, int DI, int DS, int ES, int BP );
void interrupt KeyboardHandler(__CPPARGS);
//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û
///ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ/ÛÛ
//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û//Û
int NObjetos=0; // # de objetos ya contenidos en Sprite
SPRITE *Sprite;
// Esta informaci¢n es constante y sirve para saber como tratar a los Sprite's
const DatosTipo InfoSprites[] = {
// 00 > Cuadros est ticos 16x16 ( Power UPs )
0x02,
{ 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x12, 0x00, 0x00, 0x00, 0x00 },
0x10, 0x10, 0x00, 0x00, 0x02,
// 01 > Cuadros est ticos 16x16 ( Unidades )
0x02,
{ 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x01, 0x00, 0x00, 0x00, 0x00 },
0x10, 0x10, 0x00, 0x00, 0x02,
// 02 > Cuadros est ticos 16x16 ( Mapas )
0x02,
{ 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x2D, 0x00, 0x00, 0x00, 0x00 },
0x10, 0x10, 0x00, 0x00, 0x02,
// 03 > Cuadros est ticos 16x18 ( Numeros )
0x02,
{ 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x0A, 0x00, 0x00, 0x00, 0x00 },
0x10, 0x12, 0x00, 0x00, 0x02,
// 04 > Anim. como Bomba, TelePort... 16x18
0x02,
{ 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x03, 0x00, 0x00, 0x00, 0x00 },
0x10, 0x12, 0x00, 0x00, 0x05,
// 05 > Monstruos como Globo y Fantasma 16x18
0x02,
{ 0x00, 0x00, 0x00, 0x00, 0x03 },
{ 0x03, 0x00, 0x00, 0x00, 0x06 },
0x10, 0x12, 0x00, -4, 0x04,
// 06 > Monstruos 4dir. Estrella... 16x18
0x05,
{ 0x00, 0x03, 0x06, 0x09, 0x0C },
{ 0x03, 0x03, 0x03, 0x03, 0x06 },
0x10, 0x12, 0x00, 0x00, 0x02,
// 07 > Perfil de los Jugadores 23x23
0x05,
{ 0x00, 0x03, 0x06, 0x09, 0x0C },
{ 0x03, 0x03, 0x03, 0x03, 0x08 },
0x17, 0x17, -3, -5, 0x03,
// 08 > animaciones fuego vertical
0x05,
{ 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00, 0x06 },
0x10, 0x10, 0, 0, 0x03
};
char prt_tbl[13+1][21+1] =
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00 },
{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 00 },
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 00 },
{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 00 },
{ 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 00 },
{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 00 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 00 },
{ 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 00 },
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00 },
{ 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 00 },
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00 },
{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 00 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00 },
{ 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00, 00 },
};
char prt_tbl2[13+1][21+1];
char far *TmpBuffer;
void GetBitmap( char far *BitMapSRC, char far *TRG, int X, int Y, int Xw1, int Yw1, int Xw2 );
int TECLAr;
int main( void )
{
printf( "\n> Inicializando ModoX" );
printf( "\n> Jos David Guillen" );
init_random ();
if ( ( TmpBuffer = (char far *)farmalloc( sizeof( char ) * 320 * 200 ) ) == NULL )
return -1;
// Pido memoria para los elementos b sicos
if ( InicializaElementosBasicos() != OK ) return ERROR;
printf( "\nPreparado para comenzar...");
getch();
if (set_vga_modex( Mode_360x240, 360, 240, 3) == 0) Error(0x00);
if ( MuestraMensajeCargando() != OK ) Error(0x10);
InicializaJuego();
set_display_page( 0 );
if ( CargaPaleta("images\\dyna_tbl.pcx") !=OK ) Error(0x11);
copy_page( 2, 1 );
copy_page( 2, 0 );
BIOSKeyboardHandler = getvect(KEYBOARDINTR);
setvect(KEYBOARDINTR, KeyboardHandler);
ComienzaJuego();
setvect(KEYBOARDINTR, BIOSKeyboardHandler);
farfree( TmpBuffer );
set_video_mode (3);
LiberaMemoriaObjetos();
printf( "\n>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" );
printf( "\n> Gracias a todos los que han echo posible este juego. " );
printf( "\n> En especial a mi hermano Antonio. " );
printf( "\n> Jos David Guillen || _-ù FuTuRe ViSiOn ù-_ || InfoMundo" );
printf( "\n>_ " );
fflush( stdin );
return OK;
}
/**************************************************************************\
|* *|
|* CargaObjetosBasicos *|
|* *|
|* Descripci¢n: *|
|* Carga los objetos Basicos del fichero Dyna_tbl.PCX *|
|* *|
|* *|
|* Entradas: (ninguna) *|
|* *|
|* Salidas: OK Todo ha ido bien *|
|* ERROR Algo va mal *|
|* *|
\**************************************************************************/
int CargaObjetosBasicos( void )
{
FILE *fp;
int ancho, alto;
int contador;
unsigned char byte;
// Abrimos el fichero
if ( (fp = fopen("images\\dyna_tbl.pcx","rb")) == NULL ) return ERROR;
// Saltamos la cabecera
fseek( fp, 128, SEEK_SET );
for(alto=0; alto<200; alto++)
{
for(ancho=0; ancho<320; )
{
byte=getc(fp);
if(byte<=0xC0)
{
byte = byte == 254 ? 0 : byte;
ProcesaPuntoBasico( ancho, alto, byte );
ancho++;
}
else
{
contador=byte&0x3F; byte=getc(fp);
byte = byte == 254 ? 0 : byte;
for(; contador>0; contador--)
{
ProcesaPuntoBasico( ancho, alto, byte );
ancho++;
}
}
}
}
fclose( fp );
// Abrimos el fichero
if ( (fp = fopen("images\\dyna_jgd.pcx","rb")) == NULL ) return ERROR;
// Saltamos la cabecera
fseek( fp, 128, SEEK_SET );
for(alto=0; alto<200; alto++)
{
for(ancho=0; ancho<320; )
{
byte=getc(fp);
if(byte<=0xC0)
{
byte = byte == 254 ? 0 : byte;
TmpBuffer[ancho + 320*alto] = byte;
// ProcesaPuntoJugador( ancho, alto, byte );
ancho++;
}
else
{
contador=byte&0x3F; byte=getc(fp);
byte = byte == 254 ? 0 : byte;
for(; contador>0; contador--)
{
TmpBuffer[ancho + 320*alto] = byte;
// ProcesaPuntoJugador( ancho, alto, byte );
ancho++;
}
}
}
}
fclose(fp);
ProcesaPuntoJugador( ancho, alto, byte );
return OK;
}
/**************************************************************************\
|* *|
|* ProcesaPuntoBasico *|
|* *|
|* Descripci¢n: *|
|* inserta la imagen en su lugar correspondiente *|
|* *|
|* Entradas: x,y coordenadas actuales del punto *|
|* byte color *|
|* Salidas: (ninguna) *|
|* *|
\**************************************************************************/
void ProcesaPuntoBasico( int x, int y, char color )
{
int i, j, Xw, Yw;
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// Guarda al Globo 16x18
Xw = InfoSprites[ SPR_GLOBO ].Ancho;
Yw = InfoSprites[ SPR_GLOBO ].Alto;
for ( i=0; i<3; i++ )
if ( x >= (0 + (Xw+1)*i) && x < (Xw + (Xw+1)*i) && y >= 0 && y < 18 )
{
Sprite[POS_GLOBO].Sprite[0][( ( x - (Xw+1)*i ) + (Xw*y) ) + (Xw*Yw*i)] = color;
return;
}
for ( i=3; i<9; i++ )
if ( x >= (0 + (Xw+1)*i) && x < (Xw + (Xw+1)*i) && y >= 0 && y < 18 )
{
Sprite[POS_GLOBO].Sprite[4][( ( x - (Xw+1)*i ) + (Xw*y) ) + (Xw*Yw*(i-3))] = color;
return;
}
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// Guarda al Baquero 16x18
Xw = InfoSprites[ SPR_BAQUERO ].Ancho;
Yw = InfoSprites[ SPR_BAQUERO ].Alto;
for ( i=0; i<3; i++ )
if ( x >= (0 + (Xw+1)*(i+9)) && x < (Xw + (Xw+1)*(i+9)) && y >= 0 && y < 18 )
{
Sprite[POS_BAQUERO].Sprite[0][( ( x - (Xw+1)*(i+9) ) + (Xw*y) ) + (Xw*Yw*i)] = color;
return;
}
for ( i=3; i<9; i++ )
if ( x >= (0 + (Xw+1)*(i+9)) && x < (Xw + (Xw+1)*(i+9)) && y >= 0 && y < 18 )
{
Sprite[POS_BAQUERO].Sprite[4][( ( x - (Xw+1)*(i+9) ) + (Xw*y) ) + (Xw*Yw*(i-3))] = color;
return;
}
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// Guarda al Fantasma 16x18
Xw = InfoSprites[ SPR_GOSTH ].Ancho;
Yw = InfoSprites[ SPR_GOSTH ].Alto;
for ( i=0; i<3; i++ )
if ( x >= (0 + (Xw+1)*i) && x < (Xw + (Xw+1)*i) && y >= 19 && y < 37 )
{
Sprite[POS_GOSTH].Sprite[0][( ( x - (Xw+1)*i ) + (Xw*(y-19)) ) + (Xw*Yw*i)] = color;
return;
}
for ( i=3; i<9; i++ )
if ( x >= (0 + (Xw+1)*i) && x < (Xw + (Xw+1)*i) && y >= 19 && y < 37 )
{
Sprite[POS_GOSTH].Sprite[4][( ( x - (Xw+1)*i ) + (Xw*(y-19)) ) + (Xw*Yw*(i-3))] = color;
return;
}
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// Guarda al Platano 16x18
Xw = InfoSprites[ SPR_PLATANO ].Ancho;
Yw = InfoSprites[ SPR_PLATANO ].Alto;
for ( i=0; i<3; i++ )
if ( x >= (0 + (Xw+1)*(i+9)) && x < (Xw + (Xw+1)*(i+9)) && y >= 19 && y < 37 )
{
Sprite[POS_PLATANO].Sprite[0][( ( x - (Xw+1)*(i+9) ) + (Xw*(y-19)) ) + (Xw*Yw*i)] = color;
return;
}
for ( i=3; i<9; i++ )
if ( x >= (0 + (Xw+1)*(i+9)) && x < (Xw + (Xw+1)*(i+9)) && y >= 19 && y < 37 )
{
Sprite[POS_PLATANO].Sprite[4][( ( x - (Xw+1)*(i+9) ) + (Xw*(y-19)) ) + (Xw*Yw*(i-3))] = color;
return;
}
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// Guarda la Bomba 16x18
Xw = InfoSprites[ SPR_BOMBA ].Ancho;
Yw = InfoSprites[ SPR_BOMBA ].Alto;
for ( i=0; i<3; i++ )
if ( x >= (0 + (Xw+1)*i) && x < (Xw + (Xw+1)*i) && y >= 38 && y < 56 )
{
Sprite[POS_BOMBA].Sprite[0][( ( x - (Xw+1)*i) + (Xw*(y-38)) ) + (Xw*Yw*i)] = color;
return;
}
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// Guarda el TelePort 16x18
Xw = InfoSprites[ SPR_TELEPORT ].Ancho;
Yw = InfoSprites[ SPR_TELEPORT ].Alto;
for ( i=0; i<3; i++ )
if ( x >= (0 + (Xw+1)*(i+3)) && x < (Xw + (Xw+1)*(i+3)) && y >= 38 && y < 56 )
{
Sprite[POS_TELEPORT].Sprite[0][( ( x - (Xw+1)*(i+3)) + (Xw*(y-38)) ) + (Xw*Yw*i)] = color;
return;
}
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// Guarda los Numeros 16x18
Xw = InfoSprites[ SPR_NUMEROS ].Ancho;
Yw = InfoSprites[ SPR_NUMEROS ].Alto;
for ( i=0; i<10; i++ )
if ( x >= (0 + (Xw+1)*i) && x < (Xw + (Xw+1)*i) && y >= 76+19 && y < 94+19 )
{
Sprite[POS_NUMEROS].Sprite[0][( ( x - (Xw+1)*i) + (Xw*(y-(76+19))) ) + (Xw*Yw*i)] = color;
// set_point( x, y, color );
return;
}
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// Guarda los PowerUps
Xw = InfoSprites[ SPR_POWERUP ].Ancho;
Yw = InfoSprites[ SPR_POWERUP ].Alto;
for ( j=0; j<2; j++ )
for ( i=0; i<9; i++ )
if ( x >= (0 + (Xw+1)*i) && x < (Xw + (Xw+1)*i) && y >= 114+17*j && y < 130+17*j )
{ // -\/---< 16
Sprite[POS_POWERUP].Sprite[0][( ( x - (Xw+1)*i) + (Xw*(y-(114+17*j))) ) + (Xw*Yw*(i+j*9))] = color;
return;
}
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// Guarda los Mapas
Xw = InfoSprites[ SPR_ELEM_MAPA ].Ancho;
Yw = InfoSprites[ SPR_ELEM_MAPA ].Alto;
for ( j=0; j<5; j++ )
for ( i=0; i<9; i++ )
if ( x >= (0 + (Xw+1)*(i+9)) && x < (Xw + (Xw+1)*(i+9)) && y >= 114+17*j && y < 130+17*j )
{
Sprite[POS_ELEM_MAPA].Sprite[0][( ( x - (Xw+1)*(i+9)) + (Xw*(y-(114+17*j))) ) + (Xw*Yw*(i+9*j))] = color;
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// Guarda el fuego ( vertical y horizontal)
if ( i == 5 && j >= 2 )
{
Sprite[POS_FUEGOv].Sprite[4][( ( x - (Xw+1)*(i+9)) + (Xw*(y-(114+17*j))) ) + (Xw*Yw*(j-2))] = color;
Sprite[POS_FUEGOv].Sprite[4][( ( x - (Xw+1)*(i+9)) + (Xw*(y-(114+17*j))) ) + (Xw*Yw*( 5- (j-2) ))] = color;
Sprite[POS_FUEGOh].Sprite[4][( Xw*( x - (Xw+1)*(i+9)) + (/*Xw**/(y-(114+17*j))) ) + (Xw*Yw*(j-2))] = color;
Sprite[POS_FUEGOh].Sprite[4][( Xw*( x - (Xw+1)*(i+9)) + (/*Xw**/(y-(114+17*j))) ) + (Xw*Yw*( 5- (j-2) ))] = color;
}
return;
}
}
/**************************************************************************\
|* *|
|* ProcesaPuntoJugador *|
|* *|
|* Descripci¢n: *|
|* inserta la imagen en su lugar correspondiente *|
|* *|
|* Entradas: x,y coordenadas actuales del punto *|
|* byte color *|
|* Salidas: (ninguna) *|
|* *|
\**************************************************************************/
void ProcesaPuntoJugador( int x, int y, char color )
{
int i, j, Xw, Yw;
Xw = InfoSprites[ SPR_JUGADOR ].Ancho;
Yw = InfoSprites[ SPR_JUGADOR ].Alto;
for ( j = 0; j < 4; j++ )
{
for ( i = 0; i < 3; i++ )
GetBitmap( TmpBuffer, (Sprite[POS_JUGADORa+j].Sprite[3] + Xw*Yw*i ), (Xw+1)*i, (Yw+1)*2*j, Xw, Yw, 320 );
for ( i = 3; i < 6; i++ )
GetBitmap( TmpBuffer, (Sprite[POS_JUGADORa+j].Sprite[1] + Xw*Yw*(i-3)), (Xw+1)*i, (Yw+1)*2*j, Xw, Yw, 320 );
for ( i = 6; i < 9; i++ )
GetBitmap( TmpBuffer, (Sprite[POS_JUGADORa+j].Sprite[0] + Xw*Yw*(i-6)), (Xw+1)*i, (Yw+1)*2*j, Xw, Yw, 320 );
i = 9;
GetBitmap( TmpBuffer, (Sprite[POS_JUGADORa+j].Sprite[2] + Xw*Yw*(i-i)), (Xw+1)*i, (Yw+1)*2*j, Xw, Yw, 320 );
for ( i = 0; i < 2; i++ )
GetBitmap( TmpBuffer, (Sprite[POS_JUGADORa+j].Sprite[2] + Xw*Yw*(i+1)), (Xw+1)*i, (Yw+1)*(j*2+1), Xw, Yw, 320 );
for ( i = 2; i < 10; i++ )
GetBitmap( TmpBuffer, (Sprite[POS_JUGADORa+j].Sprite[4] + Xw*Yw*(i-2)), (Xw+1)*i, (Yw+1)*(j*2+1), Xw, Yw, 320 );
}
return;
}
void GetBitmap( char far *BitMapSRC, char far *TRG, int X, int Y, int Xw1, int Yw1, int Xw2 )
{
int x, y;
for ( x = 0; x < Xw1; x++ )
for ( y = 0; y < Yw1; y++ )
*( TRG + x + y*Xw1 ) = *( BitMapSRC + X+x + (Y+y)*Xw2 );
}
/**************************************************************************\
|* *|
|* InicializaElementosBasicos *|
|* *|
|* Descripci¢n: *|
|* Pide memoria para los 9 elementos b sicos... *|
|* *|
|* Entradas: (ninguna) *|
|* *|
|* Salidas: OK Todo ha ido bien *|
|* ERROR Algo va mal *|
|* *|
\**************************************************************************/
int InicializaElementosBasicos( void )
{
// Pedimos memoria base para 16 objetos
if ( InsertaObjetosBase( 16 ) != OK ) return ERROR;
// Pide espacio para el BitMap del objeto, incluida animaci¢n:
if (
// Jugador A
MemoriaBitmap( POS_JUGADORa, SPR_JUGADOR ) != OK ||
// Jugador B
MemoriaBitmap( POS_JUGADORb, SPR_JUGADOR ) != OK ||
// Jugador C
MemoriaBitmap( POS_JUGADORc, SPR_JUGADOR ) != OK ||
// Jugador D
MemoriaBitmap( POS_JUGADORd, SPR_JUGADOR ) != OK ||
// Numeros
MemoriaBitmap( POS_NUMEROS, SPR_NUMEROS ) != OK ||
// Elementos del Mapa
MemoriaBitmap( POS_ELEM_MAPA, SPR_ELEM_MAPA ) != OK ||
// Power Ups ( peque¤os )
MemoriaBitmap( POS_POWERUP, SPR_POWERUP ) != OK ||
// Bomba
MemoriaBitmap( POS_BOMBA, SPR_BOMBA ) != OK ||
// TelePort
MemoriaBitmap( POS_TELEPORT, SPR_TELEPORT ) != OK ||
// Globo
MemoriaBitmap( POS_GLOBO, SPR_GLOBO ) != OK ||
// Fantasma
MemoriaBitmap( POS_GOSTH, SPR_GOSTH ) != OK ||
// Estrella
MemoriaBitmap( POS_ESTRELLA, SPR_ESTRELLA ) != OK ||
// Baquero
MemoriaBitmap( POS_BAQUERO, SPR_BAQUERO ) != OK ||
// Platano
MemoriaBitmap( POS_PLATANO, SPR_PLATANO ) != OK ||
// Fuego Vertical
MemoriaBitmap( POS_FUEGOv, SPR_FUEGO ) != OK ||
// Fuego Horizontal
MemoriaBitmap( POS_FUEGOh, SPR_FUEGO ) != OK
) return ERROR;
return OK;
}
/**************************************************************************\
|* *|
|* InsertaObjetosBase *|
|* *|
|* Descripci¢n: *|
|* Pide memoria para las estructuras de soporte de SPRITE *|
|* *|
|* Entradas: Estructuras de SPRITE a insertar *|
|* *|
|* Salidas: OK Todo ha ido bien *|
|* ERROR Algo va mal *|
|* *|
\**************************************************************************/
int InsertaObjetosBase( int Objetos )
{
// Si no hay ningun elemento, solo pido los reclamados
if ( Sprite == NULL )
{
if ( (Sprite = (SPRITE *)calloc( Objetos, sizeof(SPRITE) )) == NULL )
return ERROR;
NObjetos = Objetos;
} else {
NObjetos += Objetos;
if ( (Sprite = (SPRITE *)realloc( Sprite, sizeof(SPRITE)*NObjetos ) ) == NULL )
return NULL;
}
return OK;
}
/**************************************************************************\
|* *|
|* MemoriaBitmap *|
|* *|
|* Descripci¢n: *|
|* Libera la memoria asignada para los objetos *|
|* *|
|* Entradas: ( ninguna ) *|
|* Salidas: ( ninguna ) *|
|* *|
\**************************************************************************/
int MemoriaBitmap( int Pos, int TipoSprite )
{
int i;
// Rango no valido
if ( Pos >= NObjetos )
return ERROR;
printf("\n%2d %2d >>", Pos, TipoSprite);
// El sprite que ocupa esa posici¢n esta ocupado
if ( Sprite[Pos].Sprite[0] == NULL )
{
// Por cada direccion, miro cuantos sprites le corresponden.
for ( i = 0; i < InfoSprites[TipoSprite].NDirecciones - 1 && i < 4; i++)
if ( InfoSprites[TipoSprite].Movimientos[i] != 0 )
{
printf( "%ld --" , (long)(sizeof(char)*InfoSprites[TipoSprite].Movimientos[i]*InfoSprites[TipoSprite].Ancho*InfoSprites[TipoSprite].Alto));
if ( ( Sprite[Pos].Sprite[i] = (char far *)farmalloc( sizeof(char)*InfoSprites[TipoSprite].Movimientos[i]*InfoSprites[TipoSprite].Ancho*InfoSprites[TipoSprite].Alto ) ) == NULL )
return ERROR;
}
// La muerte siempre esta en el punto 5
if ( InfoSprites[TipoSprite].Movimientos[4] != 0 )
{
printf( " * %ld *" , (long)(sizeof(char)*InfoSprites[TipoSprite].Movimientos[4]*InfoSprites[TipoSprite].Ancho*InfoSprites[TipoSprite].Alto));
if ( ( Sprite[Pos].Sprite[4] = (char far*)farmalloc( sizeof(char)*InfoSprites[TipoSprite].Movimientos[4]*InfoSprites[TipoSprite].Ancho*InfoSprites[TipoSprite].Alto ) ) == NULL )
return ERROR;
}
} else return ERROR;
return OK;
}
/**************************************************************************\
|* *|
|* LiberaMemoriaObjetos *|
|* *|
|* Descripci¢n: *|
|* Libera la memoria asignada para los objetos *|
|* *|
|* Entradas: ( ninguna ) *|
|* Salidas: ( ninguna ) *|
|* *|
\**************************************************************************/
void LiberaMemoriaObjetos(void)
{
int Objeto, DirObjeto;
// Este proceso empieza desde los mas enraizados punteros hacia afuera
// Recorre cada objeto de la estructura para eliminar su doble puntero
for ( Objeto=0; Objeto < NObjetos; Objeto++ )
{
// Recorro cada direcci¢n del objeto
for ( DirObjeto=0; DirObjeto < InfoSprites[Sprite[Objeto].Tipo].NDirecciones; DirObjeto++ )
farfree( Sprite[Objeto].Sprite[DirObjeto] );
}
// Ya podemos eliminar la estructura.
free ( Sprite );
}
/**************************************************************************\
|* *|
|* CargaPaleta *|
|* *|
|* Descripci¢n: *|
|* Carga la paleta con los colores por defecto *|
|* *|
|* *|
|* Entradas: achivo PCX de donde cargar la paleta *|
|* *|
|* Salidas: OK Todo ha ido bien *|
|* ERROR Algo va mal *|
|* *|
\**************************************************************************/
int CargaPaleta(char *file )
{
int index;
FILE *fp;
if ( (fp=fopen( file, "rb" ) ) == NULL )
return ERROR;
if ( fseek( fp, -768L, SEEK_END ) == 0 )
{
for (index=0; index<256; index++)
{
// get the red component
// get the green component
// get the blue component
// set components
set_dac_register ( index, (getc(fp) >> 2), (getc(fp) >> 2), (getc(fp) >> 2) );
} // end for index
}
fclose( fp );
return OK;
}
/**************************************************************************\
|* *|
|* InicializaJuego *|
|* *|
|* Descripci¢n: *|
|* Inicializa el tablero de juego segun se especifique en *|
|* puntero de tablero. *|
|* *|
|* Entradas: (ninguna) *|
|* *|
|* Salidas: OK Todo ha ido bien *|
|* ERROR Algo va mal *|
|* *|
\**************************************************************************/
void InicializaJuego(void)
{
int j, i;
int Xw, Yw;
int Elecc = 0;
static char vex = 0;
set_active_page(2);
// Copiamos el tablero ( solo los cuadros indestructibles )
for ( j = 0; j<13; j++)
for ( i = 0; i<21; i++)
prt_tbl2[j][i] = prt_tbl[j][i];
// 1§ Relleno el suelo
Xw = InfoSprites[SPR_ELEM_MAPA].Ancho;
Yw = InfoSprites[SPR_ELEM_MAPA].Alto;
for( j = 0; j < 350; j+=16 )
for ( i = 0; i < 230; i+=16 )
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), j, i, Xw, Yw );
// 2§ Pongo el marco al tablero
MuestraImagen( "images\\dyna_fnd.pcx", 2, 255 );
// 3§ Coloco los cuadros indestructibles
for ( i = 0; i < 21; i++ )
for ( j = 0; j < 13; j++ )
{
if ( prt_tbl[j][i] == 1 )
{
tdraw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+Elecc) ), 12+i*16, 20+j*16, Xw, Yw );
Elecc = random_int(2);
} else
prt_tbl[j][i] = 0;
}
// 4§ Coloco los cuadros destructibles
// Uno los dos intentos, para reforzar el n§ de arboles que aparecen
// >>>>>>>> 1§ intento del algoritmo que soporta 4
if ( vex != 0 )
{
for ( i = 0; i<21*13; i++)
{
Elecc = random_int(2);
j = random_int(21*13);
if ( prt_tbl[j/21][j%21] == 0 )
{
tdraw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+2+Elecc) ), 12+(j%21)*16, 20+(j/21)*16, Xw, Yw );
prt_tbl[j/21][j%21] = 2;
}
}
// >>>>>>>> 2§ intento del algoritmo que soporta 4
for ( i = 0; i < 21; i++ )
for ( j = 0; j < 13; j++ )
{
Elecc = random_int(2);
if ( prt_tbl[j][i] == 0 && random_int(5)%2 )
{
tdraw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+2+Elecc) ), 12+i*16, 20+j*16, Xw, Yw );
prt_tbl[j][i] = 2;
}
}
vex++; if ( vex == 5 ) vex = 0;
} else vex++;
// Dejo respirar a los jugadores
prt_tbl[ 0][ 0] = 0; prt_tbl[ 0][ 1] = 0; prt_tbl[ 1][ 0] = 0;
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), 12+16* 0, 20+16* 0, Xw, Yw );
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), 12+16* 0, 20+16* 1, Xw, Yw );
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), 12+16* 1, 20+16* 0, Xw, Yw );
prt_tbl[ 0][12] = 0; prt_tbl[ 1][12] = 0; prt_tbl[ 0][11] = 0;
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), 12+16* 0, 20+16* 12, Xw, Yw );
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), 12+16* 1, 20+16* 12, Xw, Yw );
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), 12+16* 0, 20+16* 11, Xw, Yw );
prt_tbl[0][20] = 0; prt_tbl[0][19] = 0; prt_tbl[1][20] = 0;
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), 12+16* 20, 20+16* 0, Xw, Yw );
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), 12+16* 19, 20+16* 0, Xw, Yw );
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), 12+16* 20, 20+16* 1, Xw, Yw );
prt_tbl[12][20] = 0; prt_tbl[11][20] = 0; prt_tbl[12][19] = 0;
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), 12+16* 20, 20+16* 12, Xw, Yw );
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), 12+16* 20, 20+16* 11, Xw, Yw );
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + Xw * Yw * (Pref.Entorno+4) ), 12+16* 19, 20+16* 12, Xw, Yw );
// 1 cuadro indestructible
// 2 cuadro destructible
// A jugador A 1
// B jugador B 2
// C jugador C 3
// D jugador D 4
/*
for ( j = 0; j<13; j++)
for ( i = 0; i<21; i++)
prt_tbl[j][i] = prt_tbl2[j][i];
*/
};
/**************************************************************************\
|* *|
|* MuestraImagen *|
|* *|
|* Descripci¢n: *|
|* Descomprime y copia a la pagina indicada un PCX *|
|* *|
|* Entradas: nombre de la imagen *|
|* pagina *|
|* color_invisible ( -1 si ninguno ) *|
|* *|
|* *|
|* Salidas: OK Todo ha ido bien *|
|* ERROR Algo va mal *|
|* *|
\**************************************************************************/
int MuestraImagen( char *file, int page, int col_Inv )
{
int curr_page;
FILE *fp;
int alto, ancho, contador;
unsigned char byte;
if ( (fp = fopen( file,"rb")) != NULL )
{
curr_page = get_active_page();
set_active_page(page);
// Saltamos la cabecera
fseek( fp, 128, SEEK_SET );
for(alto=0; alto<240; alto++)
{
for(ancho=0; ancho<360; )
{
byte=getc(fp);
if(byte<=0xC0)
{
if ( col_Inv < 0 || byte != col_Inv ) set_point (ancho, alto, byte);
ancho++;
}
else
{
contador=byte&0x3F; byte=getc(fp);
for(; contador>0; contador--)
{
if ( col_Inv < 0 || byte != col_Inv ) set_point (ancho, alto, byte);
ancho++;
}
}
}
}
fclose(fp);
} else return ERROR;
set_active_page(curr_page);
return OK;
}
/**************************************************************************\
|* *|
|* MuestraMensajeCargando *|
|* *|
|* Descripci¢n: *|
|* Muestra el mensaje de cargando y lo que esta, cargando *|
|* *|
|* Entradas: (ninguna) *|
|* *|
|* Salidas: OK Todo ha ido bien *|
|* ERROR Algo va mal *|
|* *|
\**************************************************************************/
int MuestraMensajeCargando(void)
{
if ( MuestraImagen( "images\\dyna_car.pcx", 1, -1 ) == ERROR ) Error(0x12);
copy_page(1, 2);
copy_bitmap ( 2, 81, 85, 108, 112, 1, 81, 175 );
if ( CargaPaleta( "images\\dyna_car.pcx" ) !=OK ) Error(0x11);
copy_page(1, 0);
// if ( InicializaSonidos() != OK ) Error(0x20);
copy_bitmap ( 2, 81, 175, 108, 202, 0, 81, 85 );
if ( CargaObjetosBasicos() != OK ) Error(0x12);
copy_bitmap ( 2, 81, 175, 108, 202, 0, 81, 128 );
// Inicializa mapa
copy_bitmap ( 2, 81, 175, 108, 202, 0, 81, 175 );
return OK;
};
/**************************************************************************\
|* *|
|* Error *|
|* *|
|* Descripci¢n: *|
|* Aborta anormalmente el programa, mostrando un mensaje de *|
|* de error. *|
|* *|
|* Entradas: Codigo del mensaje de error a mostrar *|
|* Salidas: (ninguna) *|
|* *|
\**************************************************************************/
void Error(int code)
{
set_video_mode (3);
LiberaMemoriaObjetos();
// UNSET_VECTORES();
setvect(KEYBOARDINTR, BIOSKeyboardHandler);
exit(code);
};
//( int Flags, int CS, int IP, int AX, int BX, int CX, int DX, int SI, int DI, int DS, int ES, int BP )
void interrupt KeyboardHandler(__CPPARGS)
{
static char ekey = 0;
unsigned char key;
key = inportb(KEYBOARDPORT);
// { PROCESS THE KEYSTROKE HERE }
if ( key != 224 ) // No teclas extendidas
mapa_teclado[ (key & 0x7F) ] = !(key & 0x80);
// TECLAr = key;
// 7 bit == 1 tecla OFF E F
// 7 bit == 0 tecla ON 0111 1111
if ( CallBIOSHandler )
{
// { Call the BIOS keyboard handler if the calling program wants us to }
// asm pushf end;
BIOSKeyboardHandler;
// { Otherwise just acknowledge the interrupt }
} else outportb( 0x20, 0x20 );
}