First commit 16/12/1996

This commit is contained in:
José David Guillén 2021-09-08 21:02:03 +02:00
commit 1de08b2d10
24 changed files with 2822 additions and 0 deletions

BIN
D.EXE Normal file

Binary file not shown.

BIN
DYNA2.EXE Normal file

Binary file not shown.

BIN
DYNA2.PRJ Normal file

Binary file not shown.

BIN
DYNA2.TFA Normal file

Binary file not shown.

991
DYNA_JGD.CPP Normal file
View File

@ -0,0 +1,991 @@
#include <dos.h>
#include <time.h>
#include <conio.h>
#include <stdio.h>
#include <alloc.h>
#include "Dyna_tbl.h"
#include "..\libs\int_key\int_key.h"
#include "..\modex\modex.h"
#include "..\modex\c_utils.h"
#define BORRAR 0
#define REescribe 1
#define CTE_SALTO 80
extern char prt_tbl[13+1][21+1];
extern char prt_tbl2[13+1][21+1];
extern "C" void SET_VECTORES(volatile char *);
extern "C" void UNSET_VECTORES(void);
void limpia_teclado(void);
int RellanaConcursantes(void);
void ProcesaMovimientos(int Page);
void EscribeObjetos( int Accion, int Page );
void LiberaConcursantes(void);
// Establece preferencias por defecto
PREFERENCIAS Pref = { POS_BOSQUE, 4,
{
{ t_d, t_g, t_r, t_f, t_tab },
{ t_4n, t_6n, t_8n, t_2n, t_0n },
{ t_d, t_g, t_r, t_f , t_tab },
{ t_izquierda, t_derecha, t_arriba, t_abajo , t_0n }
/*
{ t_d, t_g, t_r, t_f },
{ t_d, t_g, t_r, t_f },
{ t_d, t_g, t_r, t_f },
{ t_d, t_g, t_r, t_f },
*/
}
};
volatile char mapa_teclado[512];
int RellanaConcursantes(void);
struct byte
{
int PuedeMatar : 1 ; // Informa sobre si puede matar por contacto
int PuedeMorir : 1 ; // Informa sobre si puede morir por contacto
int PuedeVolar : 1 ; // Informa sobre si puede atravezar los cuadros
int Dispara : 1 ; // Informa si el concursante puede disparar
int CaputDelTo : 1 ; // Informa si el concursante puede disparar
int Vidas : 4 ; // Vidas del concursante <= 4
};
// Esta estructura contendra todo lo que hay que procesar:
// (todo lo que se mueva) jugadores, enemigos, bombas, teleports
//
// NOTA: Las primeras estructuras deben corresponder a los HUMANOS
// tantas como participantes hubiesen...
typedef struct concursantes
{
char Tipo_de_concursante; // Quien Juega
char InfoConcursante;
int PosX, PosY; // Posicion del concursante
int old_PosX[2], old_PosY[2]; // Posiciones del concursante en cada pagina
char Direccion; // Direccion que toma el concursante
char Velocidad; // Como de rapido se mueve
char delay_time; // Tiempo de retraso por el que va
int secuencia_animada; // Secuencia de animaci¢n por la que va
char Disparos; // # de disparos que puede poner al mismo tiempo
long DisparosP; // # de disparos ya puestos
char Longitud; // Longitud del disparo en cuadros;
struct byte Varios;
struct concursantes *poseed; // Due¤o f¡sico de este objeto...
struct concursantes *sig; // Puntero al siguientes concursante
} CONCURSANTES;
CONCURSANTES *Concursantes;
CONCURSANTES *NuevoConcursante(struct concursantes *Concur);
//struct concursante *NuevoConcursante(struct concursantes *Concur);
void GeneraFuego( CONCURSANTES *aux );
void GeneraXYaleatorio( int *X, int *Y );
void ColocaBomba( CONCURSANTES *concursante );
CONCURSANTES *EliminaConcursante(struct concursantes *Concur);
void CompruebaCoordenadas(char incX, char incY, CONCURSANTES *objeto, char *Objeto_Caput );
void MovimientoAutomatico( CONCURSANTES *aux, char *incY, char *incX, int Page );
void ColocaFuego( int PosX, int PosY, CONCURSANTES *aux );
int jklop = 0;
extern CallBIOSHandler;
clock_t TiempoDeJuego, InicioDeJuego;
void ComienzaJuego(void)
{
int Current_Page = 0, cifraTMP;
long DTiempo;
limpia_teclado();
if ( RellanaConcursantes() == ERROR ) Error(0x30);
set_display_page( 1 );
CallBIOSHandler = 0;
InicioDeJuego = clock();
while( mapa_teclado[t_esc] == 0 )
{
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
// mostramos el reloj...
TiempoDeJuego = clock();
DTiempo = ( TiempoDeJuego - InicioDeJuego ) / CLK_TCK;
// minutos
cifraTMP = ( DTiempo / 60 );
tdraw_bitmap ((char far *)( (Sprite[POS_NUMEROS].Sprite[0])+(long)16*18*( cifraTMP / 10 ) )
, 28 + 16*0, 3, 16, 11);
cifraTMP = ( cifraTMP - ( cifraTMP / 10 ) * 10 );
tdraw_bitmap ((char far *)( (Sprite[POS_NUMEROS].Sprite[0])+(long)16*18*cifraTMP )
, 28 + 16*1, 3, 16, 11);
// minutos
cifraTMP = ( DTiempo % 60 );
tdraw_bitmap ((char far *)( (Sprite[POS_NUMEROS].Sprite[0])+(long)16*18*( cifraTMP / 10 ) )
, 28 + 4 + 16*2, 3, 16, 11);
cifraTMP = ( cifraTMP - ( cifraTMP / 10 ) * 10 );
tdraw_bitmap ((char far *)( (Sprite[POS_NUMEROS].Sprite[0])+(long)16*18*( cifraTMP ) )
, 28 + 4 + 16*3, 3, 16, 11);
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
if ( mapa_teclado[t_2] )
{
mapa_teclado[t_2] = 0;
set_display_page (2);
sleep(5);
}
if ( mapa_teclado[t_9] )
{
Pref.Entorno+=9; mapa_teclado[t_9] = 0;
if ( Pref.Entorno >= POS_BOSQUE + 3*9 )
Pref.Entorno = POS_BOSQUE;
}
if ( mapa_teclado[t_0] )
{
InicializaJuego(); mapa_teclado[t_0] = 0;
copy_page( 2, 1 );
copy_page( 2, 0 );
}
set_active_page (Current_Page);
EscribeObjetos( BORRAR, Current_Page );
// copy_page( 2, Current_Page );
ProcesaMovimientos( Current_Page );
EscribeObjetos( REescribe, Current_Page );
set_display_page (Current_Page);
Current_Page = Current_Page ^ 0x01;
};
LiberaConcursantes();
}
/**************************************************************************\
|* *|
|* EscribeObjetos *|
|* *|
|* Descripci¢n: *|
|* Se encarga de escribir todos los objetos a la patalla: *|
|* a> se eliminan todos los objetos animados de la pantalla *|
|* b> se dibujan en las nuevas posiciones *|
|* *|
|* Entradas: BORRA ------> a *|
|* REescribe --> b *|
|* Salidas: (ninguna) *|
|* *|
\**************************************************************************/
void EscribeObjetos( int Accion, int Page )
{
CONCURSANTES *aux;
int Ancho, Alto;
// Empiezo por el principio
aux = Concursantes;
// Y mientras quede algo que procesar
while( aux != NULL )
{
// Obtengo las dimensiones
Ancho = InfoSprites[ aux -> InfoConcursante ].Ancho;
Alto = InfoSprites[ aux -> InfoConcursante ].Alto;
if ( Accion == BORRAR )
copy_bitmap (2, aux -> old_PosX[Page] + 12+InfoSprites[aux -> InfoConcursante].CorrX, aux -> old_PosY[Page] + 20+InfoSprites[aux -> InfoConcursante].CorrY, aux -> old_PosX[Page]+12+Ancho+InfoSprites[aux -> InfoConcursante].CorrX, aux -> old_PosY[Page]+20+Alto+InfoSprites[aux -> InfoConcursante].CorrY,
Page, aux -> old_PosX[Page] + 12+InfoSprites[aux -> InfoConcursante].CorrX, aux -> old_PosY[Page] + 20+InfoSprites[aux -> InfoConcursante].CorrY);
// copy_bitmap (2, aux -> old_PosX[Page] + 12, aux -> old_PosY[Page] + 20, aux -> old_PosX[Page]+12+Ancho, aux -> old_PosY[Page]+20+Alto,
// Page, aux -> old_PosX[Page] + 12, aux -> old_PosY[Page] + 20);
else
{
// Amplio la secuencia animada
// 0 Izq, 1 Der, 2 Arr, 3 Abj, Muerte
tdraw_bitmap ((char far *)( (Sprite[aux -> Tipo_de_concursante].Sprite[ aux -> InfoConcursante == SPR_BAQUERO ? 0 : aux->Direccion ])+(long)Ancho*Alto* (long)( aux->secuencia_animada ) ), aux -> PosX+12+InfoSprites[aux -> InfoConcursante].CorrX, aux -> PosY+20+InfoSprites[aux -> InfoConcursante].CorrY, Ancho, Alto);
// tdraw_bitmap ((char far *)( (Sprite[aux -> Tipo_de_concursante].Sprite[aux->Direccion])+(long)Ancho*Alto* (long)( aux->secuencia_animada ) ), aux -> PosX+12, aux -> PosY+20, Ancho, Alto);
}
aux = aux -> sig;
};
}
/**************************************************************************\
|* *|
|* ProcesaMovimientos *|
|* *|
|* Descripci¢n: *|
|* Genera los movimientos del HUMANO y maquina, despues *|
|* llama a la funci¢n que los corrige... *|
|* *|
|* Entradas: Pagina de los movimientos *|
|* Salidas: (ninguna) *|
|* *|
\**************************************************************************/
void ProcesaMovimientos(int Page)
{
CONCURSANTES *aux;
char old_dir, enc;
char incX, incY, objeto_caput;
// Empiezo por el principio
aux = Concursantes;
// Y mientras quede algo que procesar
while( aux != NULL )
{
incX = incY = enc = objeto_caput = 0;
old_dir = aux -> Direccion;
// SOLO SE PROCESA SI ESTA VIVO
if ( aux -> Direccion != 4 )
{
switch( aux -> Tipo_de_concursante )
{
// Los jugadores procesan sus movimientos segun el usuario
// izq, der, arr, abj
case POS_JUGADORa:
case POS_JUGADORb:
// Izquierda
if ( mapa_teclado[Pref.Teclas[(aux -> Tipo_de_concursante)-POS_JUGADORa][0]] )
{
incX = - (aux -> Velocidad);
aux -> Direccion = 0;
enc = 1;
} else
// Derecha
if ( mapa_teclado[Pref.Teclas[(aux -> Tipo_de_concursante)-POS_JUGADORa][1]] )
{
incX = (aux -> Velocidad);
aux -> Direccion = 1;
enc = 1;
} else
// Arriba
if ( mapa_teclado[Pref.Teclas[(aux -> Tipo_de_concursante)-POS_JUGADORa][2]] )
{
incY = - (aux -> Velocidad);
aux -> Direccion = 2;
enc = 1;
} else
// Abajo
if ( mapa_teclado[Pref.Teclas[(aux -> Tipo_de_concursante)-POS_JUGADORa][3]] )
{
incY = (aux -> Velocidad);
aux -> Direccion = 3;
enc = 1;
} //else
// Bomba
if ( mapa_teclado[Pref.Teclas[(aux -> Tipo_de_concursante)-POS_JUGADORa][4]] )
{
// Si puede disparar y el n§ de disparos puestos es menor al que tiene
if ( aux -> Varios.Dispara && aux -> DisparosP < aux -> Disparos )
{
mapa_teclado[Pref.Teclas[(aux -> Tipo_de_concursante)-POS_JUGADORa][4]] = 0;
ColocaBomba( aux );
}
}
break;
case POS_JUGADORd:
case POS_JUGADORc:
MovimientoAutomatico( aux, &incY, &incX, Page );
enc = 1;
break;
// La bomba no se mueve ( A menos que se encuentre en una zona deslizante
case POS_BOMBA:
// Eliminamos la bomba
if ( (clock() - (aux -> DisparosP))/CLK_TCK >= aux -> Varios.Vidas )
objeto_caput = 1;
enc = 1;
break;
case POS_BAQUERO:
MovimientoAutomatico( aux, &incY, &incX, Page );
enc = 1;
break;
// El resto sigue un algoritmo de movimiento ( actualmente ninguno );
default:
MovimientoAutomatico( aux, &incY, &incX, Page );
enc = 1;
break;
}
// Procesa las coordenadas si no esta caput ( Direccion 4 )
CompruebaCoordenadas( incX, incY, aux, &objeto_caput );
// Cambia de secuencia animada si corresponde
if ( enc )
{
// Empieza el nuevo movimiento por por 0 si es distinto
if ( aux -> Direccion != old_dir )
{
aux -> secuencia_animada = 0;
aux -> delay_time = 0;
} else
if ( (aux -> delay_time = aux -> delay_time + aux -> Velocidad) >= InfoSprites[ aux -> InfoConcursante ].PixelCambio )
{
aux -> delay_time = 0;
if ( (int)( aux -> secuencia_animada ) >= InfoSprites[ aux -> InfoConcursante ].Movimientos[ aux -> InfoConcursante == SPR_BAQUERO ? 0 : aux->Direccion] - 1 )
aux -> secuencia_animada = 0;
else
aux -> secuencia_animada = aux -> secuencia_animada + 1;
}
}
}else{
if ( aux -> secuencia_animada >= (InfoSprites[ aux -> InfoConcursante ].Movimientos[4] - 1) )
aux -> Varios.CaputDelTo = 1;
else
if ( (TiempoDeJuego/*clock()*/ - aux -> DisparosP)>>1 >= 1 )
{
aux -> DisparosP = TiempoDeJuego;//clock();
aux -> secuencia_animada = aux -> secuencia_animada + 1;
}
}
// Copia los movimientos a la pagina adecuada
aux -> old_PosX[Page] = aux -> PosX;
aux -> old_PosY[Page] = aux -> PosY;
if ( objeto_caput )
{
if ( aux -> Tipo_de_concursante == POS_BOMBA )
{
aux -> Varios.Vidas = 0;
aux -> Varios.CaputDelTo = 1;
GeneraFuego( aux );
} else {
aux -> Varios.Vidas = aux -> Varios.Vidas - 1;
aux -> Direccion = 4; // Activamos la muerte
aux -> secuencia_animada = 0;
aux -> DisparosP = TiempoDeJuego;
}
}
if ( aux -> Varios.CaputDelTo )
{
// Borramos al objeto de la pantalla
incX = InfoSprites[ aux -> InfoConcursante ].Ancho;
incY = InfoSprites[ aux -> InfoConcursante ].Alto;
if ( aux -> InfoConcursante == SPR_FUEGO )
{
set_active_page (2);
aux -> DisparosP = (Pref.Entorno+4);
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + /*incX * incY **/((aux -> DisparosP)<<8) ), aux -> PosX + 12 , aux -> PosY + 20, incX, incY );
set_active_page (Page);
draw_bitmap ((char far*)( Sprite[POS_ELEM_MAPA].Sprite[0] + /*incX * incY **/((aux -> DisparosP)<<8) ), aux -> PosX + 12 , aux -> PosY + 20, incX, incY );
}
copy_bitmap (2, aux -> old_PosX[!Page] + 12+InfoSprites[aux -> InfoConcursante].CorrX, aux -> old_PosY[!Page] + 20+InfoSprites[aux -> InfoConcursante].CorrY, aux -> old_PosX[!Page]+12+incY+InfoSprites[aux -> InfoConcursante].CorrX, aux -> old_PosY[!Page]+20+incY+InfoSprites[aux -> InfoConcursante].CorrY,
!Page, aux -> old_PosX[!Page] + 12+InfoSprites[aux -> InfoConcursante].CorrX, aux -> old_PosY[!Page] + 20+InfoSprites[aux -> InfoConcursante].CorrY);
prt_tbl[(aux -> PosY)/16][(aux -> PosX)/16] = 0;
if ( ( aux -> poseed ) != NULL )
( ( aux -> poseed ) -> DisparosP ) --;
aux = EliminaConcursante( aux );
}
else
aux = aux -> sig;
};
}
void GeneraFuego( CONCURSANTES *concursante )
{
int x, y, inc;
CONCURSANTES *aux;
x = concursante -> PosX / 16;
y = concursante -> PosY / 16;
// Scaneamos posibiliades hacia la izquierda
for ( inc = 1; ( x - inc ) >= 0 && inc <= concursante -> Longitud; inc++ )
if ( prt_tbl[y][x-inc] != 1 && prt_tbl[y][x-inc] != 2 )
{
if ( (aux = NuevoConcursante(concursante)) == NULL ) Error(-1);
aux -> Tipo_de_concursante = POS_FUEGOh;
ColocaFuego( (x-inc)*16, y*16, aux );
prt_tbl[y][x-inc] = 4;
} else {
// Si es una bomba ­­­ BOOM !!! ( la otra )
if ( prt_tbl2[y][x-inc] == 0 )
{
if ( (aux = NuevoConcursante(concursante)) == NULL ) Error(-1);
aux -> Tipo_de_concursante = POS_FUEGOh;
ColocaFuego( (x-inc)*16, y*16, aux );
prt_tbl[y][x-inc] = 4;
}
break;
}
// Scaneamos posibiliades hacia la Derecha
for ( inc = 1; ( x + inc ) < 21 && inc <= concursante -> Longitud; inc++ )
if ( prt_tbl[y][x+inc] != 1 && prt_tbl[y][x+inc] != 2 )
{
if ( (aux = NuevoConcursante(concursante)) == NULL ) Error(-1);
aux -> Tipo_de_concursante = POS_FUEGOh;
ColocaFuego( (x+inc)*16, y*16, aux );
prt_tbl[y][x+inc] = 4;
} else {
// Si es una bomba ­­­ BOOM !!! ( la otra )
if ( prt_tbl2[y][x+inc] == 0 )
{
if ( (aux = NuevoConcursante(concursante)) == NULL ) Error(-1);
aux -> Tipo_de_concursante = POS_FUEGOh;
ColocaFuego( (x+inc)*16, y*16, aux );
prt_tbl[y][x+inc] = 4;
}
break;
}
// Scaneamos posibiliades hacia la arriba
for ( inc = 1; ( y - inc ) >= 0 && inc <= concursante -> Longitud; inc++ )
if ( prt_tbl[y-inc][x] != 1 && prt_tbl[y-inc][x] != 2 )
{
if ( (aux = NuevoConcursante(concursante)) == NULL ) Error(-1);
aux -> Tipo_de_concursante = POS_FUEGOv;
ColocaFuego( x*16, (y-inc)*16, aux );
prt_tbl[y-inc][x] = 4;
} else {
// Si es una bomba ­­­ BOOM !!! ( la otra )
if ( prt_tbl2[y-inc][x] == 0 )
{
if ( (aux = NuevoConcursante(concursante)) == NULL ) Error(-1);
aux -> Tipo_de_concursante = POS_FUEGOv;
ColocaFuego( x*16, (y-inc)*16, aux );
prt_tbl[y-inc][x] = 4;
}
break;
}
// Scaneamos posibiliades hacia la abajo
for ( inc = 1; ( y + inc ) < 13 && inc <= concursante -> Longitud; inc++ )
if ( prt_tbl[y+inc][x] != 1 && prt_tbl[y+inc][x] != 2 )
{
if ( (aux = NuevoConcursante(concursante)) == NULL ) Error(-1);
aux -> Tipo_de_concursante = POS_FUEGOv;
ColocaFuego( x*16, (y+inc)*16, aux );
prt_tbl[y+inc][x] = 4;
} else {
// Si es una bomba ­­­ BOOM !!! ( la otra )
if ( prt_tbl2[y+inc][x] == 0 )
{
if ( (aux = NuevoConcursante(concursante)) == NULL ) Error(-1);
aux -> Tipo_de_concursante = POS_FUEGOv;
ColocaFuego( x*16, (y+inc)*16, aux );
prt_tbl[y+inc][x] = 4;
}
break;
}
}
void ColocaFuego( int PosX, int PosY, CONCURSANTES *aux )
{
aux -> InfoConcursante = SPR_FUEGO;
aux -> PosX = PosX; aux -> PosY = PosY;
aux -> old_PosX[0] = aux -> old_PosX[1] = PosX;
aux -> old_PosY[0] = aux -> old_PosY[1] = PosY;
aux -> Direccion = 4;
aux -> Velocidad = 1;
aux -> delay_time = 40; aux -> secuencia_animada = 0;
aux -> poseed = NULL;
aux -> DisparosP = TiempoDeJuego;
aux -> Varios.CaputDelTo = 0;
}
void MovimientoAutomatico( CONCURSANTES *aux, char *incY, char *incX, int Page )
{
// Cambiamos de direccion
if ( aux -> old_PosX[Page] == aux -> PosX && aux -> old_PosY[Page] == aux -> PosY )
{
aux -> Direccion = (char)random_int( 4 );
}
switch( aux -> Direccion )
{
// izq, der, arr, abj
case 0:
*incX = -(aux -> Velocidad);
break;
case 1:
*incX = (aux -> Velocidad);
break;
case 2:
*incY = -(aux -> Velocidad);
break;
case 3:
*incY = (aux -> Velocidad);
break;
}
}
/**************************************************************************\
|* *|
|* CompruebaCoordenadas *|
|* *|
|* Descripci¢n: *|
|* Comprueba que las coordenadas son correctas, en caso *|
|* contrario las corrige. Tambien procesa el caso de *|
|* encontrarse en una zona especial: teleport, flecha... *|
|* *|
|* Entradas: Punteros a las Coordenadas X , Y *|
|* Salidas: (ninguna) *|
|* *|
\**************************************************************************/
void CompruebaCoordenadas( char incX, char incY, CONCURSANTES *objeto, char *Objeto_Caput )
{
int xV, yV, xS, yS, Tmp;
// Este es el puntero donde estan los cuadros:
// prt_tbl[13][21];
//
// 1 ---> Cuadro indestructible / BOMBA
// 2 ---> Cuadro destructible ( Se puede sobrevolar )
// 3 ---> Objeto que puede matar al contacto
// ( Solo los jugadores pueden morir al contacto )
// Compruebo que no este fuera de los bordes
while ( (objeto->PosX) < 0 ) (objeto->PosX)++;
while ( (objeto->PosX) > 16*20 ) (objeto->PosX)--;
while ( (objeto->PosY) < 0 ) (objeto->PosY)++;
while ( (objeto->PosY) > 16*12 ) (objeto->PosY)--;
// xV = (*x + incX)/16; yV = (*y + incY)/16;
// Es un movimiento en el eje X
if ( incX != 0 )
{
xV = ((objeto->PosX) + (incX < 0 ? 2 : 11 ) )/16;
yV = ((objeto->PosY)+2)/16;
Tmp = ((objeto->PosY)+11)/16;
// Si no es un jugador ni una bomba ( Controlamos su c¢digo 3 )
xS = xV; yS = yV;
if ( prt_tbl[yS][xS] == 4 )
*Objeto_Caput = 1;
if ( objeto -> Varios.PuedeMatar )
{
prt_tbl[yV][xV] = 0;
}
// Si estoy pisando un cuadro ocupado seguimos una estructura distinta
if ( prt_tbl[yV][xV] == 1 ) //!= 0 )
if ( incX < 0 ) xV --; else xV ++;
else
xV = ((objeto->PosX) + (incX < 0 ? 2 : 11 ) + incX )/16;
// Cuidadin que puede morir
// if ( ( objeto -> InfoConcursante) == SPR_JUGADOR && ( objeto -> Varios.PuedeMorir ) && ( prt_tbl[yV][xV] == 3 || prt_tbl[Tmp][xV] == 3 ) )
/*
if ( prt_tbl[yS][xS] == 4 )
*Objeto_Caput = 1;
else
*/
if ( ( objeto -> InfoConcursante) == SPR_JUGADOR && ( objeto -> Varios.PuedeMorir ) && prt_tbl[yS][xS] == 3 )
*Objeto_Caput = 1;
else
if ( prt_tbl[yV][xV] == 0 && prt_tbl[Tmp][xV] == 0 || ( objeto -> Varios.PuedeVolar && prt_tbl[yV][xV] == 2 && prt_tbl[Tmp][xV] == 2 ) )
{
(objeto->PosX) = (objeto->PosX) + incX;
// Si no es un jugador ni una bomba ( Controlamos su c¢digo 3 )
if ( objeto -> Varios.PuedeMatar )
prt_tbl[yV][xV] = 3;
} else {
// Si no es un jugador ni una bomba ( Controlamos su c¢digo 3 )
if ( objeto -> Varios.PuedeMatar )
prt_tbl[yS][xS] = 3;
}
} else
// Es un movimiento en el eje Y
if ( incY != 0 )
{
yV = ((objeto->PosY) + (incY < 0 ? 2 : 11 ) )/16;
xV = ((objeto->PosX)+2)/16;
Tmp = ((objeto->PosX)+11)/16;
// Si no es un jugador ni una bomba ( Controlamos su c¢digo 3 )
xS = xV; yS = yV;
if ( prt_tbl[yS][xS] == 4 )
*Objeto_Caput = 1;
if ( objeto -> Varios.PuedeMatar )
{
prt_tbl[yV][xV] = 0;
}
// Si estoy pisando un cuadro ocupado seguimos una estructura distinta
if ( prt_tbl[yV][xV] == 1 )//!= 0 )
if ( incY < 0 ) yV --; else yV ++;
else
yV = ((objeto->PosY) + (incY < 0 ? 2 : 11 ) + incY )/16;
// Cuidadin que puede morir
// if ( ( objeto -> InfoConcursante) == SPR_JUGADOR && ( objeto -> Varios.PuedeMorir ) && ( prt_tbl[yV][xV] == 3 || prt_tbl[yV][Tmp] == 3 ) )
/*
if ( prt_tbl[yS][xS] == 4 )
*Objeto_Caput = 1;
else
*/
if ( ( objeto -> InfoConcursante) == SPR_JUGADOR && ( objeto -> Varios.PuedeMorir ) && prt_tbl[yS][xS] == 3 )
*Objeto_Caput = 1;
else
if ( prt_tbl[yV][xV] == 0 && prt_tbl[yV][Tmp] == 0 || ( objeto -> Varios.PuedeVolar && prt_tbl[yV][xV] == 2 && prt_tbl[yV][Tmp] == 2 ) )
{
(objeto->PosY) = (objeto->PosY) + incY;
// Si no es un jugador ni una bomba ( Controlamos su c¢digo 3 )
if ( objeto -> Varios.PuedeMatar )
prt_tbl[yV][xV] = 3;
} else {
// Si no es un jugador ni una bomba ( Controlamos su c¢digo 3 )
if ( objeto -> Varios.PuedeMatar )
prt_tbl[yS][xS] = 3;
}
} else {
// No se mueve, pero puede estar tocandole algo que le mate
xS = ((objeto->PosX)+2)/16;
yS = ((objeto->PosY)+2)/16;
if ( prt_tbl[yS][xS] == 4 )
*Objeto_Caput = 1;
else
if ( ( objeto -> InfoConcursante) == SPR_JUGADOR && ( objeto -> Varios.PuedeMorir ) && prt_tbl[yS][xS] == 3 )
*Objeto_Caput = 1;
}
// Por que lado del que pisa esta ocupado ³
// | ³
// ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄÄÄÄÄÄÄ¿
// ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ <Ä ³ _ ³
// ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÄÄÄij |Ù ³
// ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ³ ³
// ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÀÄÄÄÄÄÄÄÙ
// ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ
// ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿
// ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ
// ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿
// ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ
// ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿
// ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ
//
};
/**************************************************************************\
|* *|
|* limpia_teclado *|
|* *|
|* Descripci¢n: *|
|* Limpia el buffer propio de teclado *|
|* *|
|* Entradas: (ninguna) *|
|* Salidas: (ninguna) *|
|* *|
\**************************************************************************/
void limpia_teclado(void)
{
int n;
for(n=0; n<256; n++)
mapa_teclado[n]=0;
}
void ColocaBomba( CONCURSANTES *concursante )
{
CONCURSANTES *aux;
int xV, yV;
xV = (concursante -> PosX + 8)/16;
yV = (concursante -> PosY + 8)/16;
if ( (aux = NuevoConcursante(concursante)) == NULL ) Error(-1);
aux -> Varios.PuedeMatar = 1; aux -> Varios.PuedeMorir = 1;
aux -> Varios.PuedeVolar = 1; aux -> Varios.Dispara = 1;
aux -> Varios.Vidas = 5; // Vida de la bomba == 5sg.
aux -> Tipo_de_concursante = POS_BOMBA;
aux -> InfoConcursante = SPR_BOMBA;
aux -> PosX = xV*16; aux -> PosY = yV*16;
prt_tbl[yV][xV] = 1; // Tipo 1 == indestructible
aux -> old_PosX[0] = aux -> old_PosX[1] = xV;
aux -> old_PosY[0] = aux -> old_PosY[1] = yV;
aux -> Direccion = 0;
aux -> Velocidad = 1;
aux -> delay_time = 40; aux -> secuencia_animada = 0;
aux -> poseed = concursante;
aux -> DisparosP = clock();
aux -> Longitud = concursante -> Longitud;
concursante -> DisparosP = concursante -> DisparosP + 1;
aux -> Varios.CaputDelTo = 0;
}
/**************************************************************************\
|* *|
|* RellenaConcursantes *|
|* *|
|* Descripci¢n: *|
|* Se encarga de colocar y definir a los concursantes *|
|* *|
|* Entradas: (ninguna) *|
|* Salidas: OK todo va bien *|
|* ERROR algo va mal *|
|* *|
\**************************************************************************/
int RellanaConcursantes(void)
{
CONCURSANTES *aux;
// Jugador 1
if ( (Concursantes = aux = NuevoConcursante(Concursantes)) == NULL ) return ERROR;
aux -> Varios.PuedeMatar = 0; aux -> Varios.PuedeMorir = 1;
aux -> Varios.PuedeVolar = 0; aux -> Varios.Dispara = 1;
aux -> Varios.Vidas = 1;
aux -> Tipo_de_concursante = POS_JUGADORa;
aux -> InfoConcursante = SPR_JUGADOR ;
aux -> PosX = 0; aux -> PosY = 0;
aux -> old_PosX[0] = aux -> old_PosX[1] = 0;
aux -> old_PosY[0] = aux -> old_PosY[1] = 0;
aux -> Direccion = 2; aux -> Velocidad = 1;
aux -> delay_time = 40; aux -> secuencia_animada = 0;
aux -> Disparos = 5; aux -> Longitud = 3;
aux -> DisparosP = 0;
aux -> poseed = NULL;
aux -> Varios.CaputDelTo = 0;
// Jugador 2
if ( (aux = NuevoConcursante(Concursantes)) == NULL ) return ERROR;
aux -> Varios.PuedeMatar = 0; aux -> Varios.PuedeMorir = 1;
aux -> Varios.PuedeVolar = 0; aux -> Varios.Dispara = 1;
aux -> Varios.Vidas = 1;
aux -> Tipo_de_concursante = POS_JUGADORb;
aux -> InfoConcursante = SPR_JUGADOR ;
aux -> PosX = 320; aux -> PosY = 192;
aux -> old_PosX[0] = aux -> old_PosX[1] = 320;
aux -> old_PosY[0] = aux -> old_PosY[1] = 192;
aux -> Direccion = 2; aux -> Velocidad = 1;
aux -> delay_time = 40; aux -> secuencia_animada = 0;
aux -> Disparos = 3; aux -> Longitud = 3;
aux -> DisparosP = 0;
aux -> poseed = NULL;
aux -> Varios.CaputDelTo = 0;
// Jugador 3
if ( Pref.Jugadores >= 3 )
{
if ( (aux = NuevoConcursante(Concursantes)) == NULL ) return ERROR;
aux -> Varios.PuedeMatar = 0; aux -> Varios.PuedeMorir = 1;
aux -> Varios.PuedeVolar = 0; aux -> Varios.Dispara = 1;
aux -> Varios.Vidas = 1;
aux -> Tipo_de_concursante = POS_JUGADORc;
aux -> InfoConcursante = SPR_JUGADOR ;
aux -> PosX = 320; aux -> PosY = 0;
aux -> old_PosX[0] = aux -> old_PosX[1] = 320;
aux -> old_PosY[0] = aux -> old_PosY[1] = 0;
aux -> Direccion = 2; aux -> Velocidad = 1;
aux -> delay_time = 40; aux -> secuencia_animada = 0;
aux -> Disparos = 1; aux -> Longitud = 1;
aux -> poseed = NULL;
aux -> Varios.CaputDelTo = 0;
}
// Jugador 4
if ( Pref.Jugadores >= 4 )
{
if ( (aux = NuevoConcursante(Concursantes)) == NULL ) return ERROR;
aux -> Varios.PuedeMatar = 0; aux -> Varios.PuedeMorir = 1;
aux -> Varios.PuedeVolar = 0; aux -> Varios.Dispara = 1;
aux -> Varios.Vidas = 1;
aux -> Tipo_de_concursante = POS_JUGADORd;
aux -> InfoConcursante = SPR_JUGADOR ;
aux -> PosX = 0; aux -> PosY = 192;
aux -> old_PosX[0] = aux -> old_PosX[1] = 0;
aux -> old_PosY[0] = aux -> old_PosY[1] = 192;
aux -> Direccion = 2; aux -> Velocidad = 1;
aux -> delay_time = 40; aux -> secuencia_animada = 0;
aux -> Disparos = 1; aux -> Longitud = 1;
aux -> DisparosP = 0;
aux -> poseed = NULL;
aux -> Varios.CaputDelTo = 0;
}
// Vaquero
if ( (aux = NuevoConcursante(Concursantes)) == NULL ) return ERROR;
aux -> Varios.PuedeMatar = 1; aux -> Varios.PuedeMorir = 1;
aux -> Varios.PuedeVolar = 0; aux -> Varios.Dispara = 0;
aux -> Varios.Vidas = 1;
aux -> Tipo_de_concursante = POS_BAQUERO;
aux -> InfoConcursante = SPR_BAQUERO;
GeneraXYaleatorio( &(aux -> PosX), &(aux -> PosY) );
aux -> old_PosX[0] = aux -> old_PosX[1] = 0;
aux -> old_PosY[0] = aux -> old_PosY[1] = 192;
aux -> Direccion = 2; aux -> Velocidad = 1;
aux -> delay_time = 40; aux -> secuencia_animada = 0;
aux -> Disparos = 1; aux -> Longitud = 1;
aux -> DisparosP = 0;
aux -> poseed = NULL;
aux -> Varios.CaputDelTo = 0;
return OK;
}
void GeneraXYaleatorio( int *X, int *Y )
{
do {
*X = random_int( 17 ) + 2;
*Y = random_int( 9 ) + 2;
}while( prt_tbl[*Y][*X] == 1 );
prt_tbl[*Y][*X] = 0;
*X = *X * 16; *Y = *Y * 16;
}
/**************************************************************************\
|* *|
|* LiberaConcursantes *|
|* *|
|* Descripci¢n: *|
|* Elimina a todos los concursantes liberando la memoria *|
|* *|
|* Entradas: (ninguna) *|
|* Salidas: (ninguna) *|
|* *|
\**************************************************************************/
void LiberaConcursantes(void)
{
CONCURSANTES *aux;
aux = Concursantes;
if ( Concursantes -> sig != NULL )
{
Concursantes = Concursantes -> sig;
LiberaConcursantes();
}
free( aux );
}
/**************************************************************************\
|* *|
|* EliminaConcursante *|
|* *|
|* Descripci¢n: *|
|* Elimina al concursante que se le pasa como par metro *|
|* *|
|* Entradas: El puntero al elemento a eliminar *|
|* Salidas: Elemento siguiente en la lista *|
|* *|
\**************************************************************************/
CONCURSANTES *EliminaConcursante(CONCURSANTES *Concur)
{
CONCURSANTES *ant;
CONCURSANTES *aux;
ant = aux = Concursantes;
// Quizas haya que eliminar al primer elemento
if ( aux == Concur )
{
Concursantes = aux -> sig;
free ( Concur );
return Concursantes;
} else {
while ( aux != Concur && aux != NULL)
{
ant = aux;
aux = aux -> sig;
};
if ( aux == NULL )
return NULL;
ant -> sig = Concur -> sig;
free( Concur );
return (ant -> sig);
}
}
/**************************************************************************\
|* *|
|* NuevoConcursante *|
|* *|
|* Descripci¢n: *|
|* A¤ade un nuevo concursante al final *|
|* *|
|* Entradas: El puntero base donde insertar (Busca solo el final) *|
|* *|
|* Salidas: direccion del concursante a¤adido *|
|* NULL algo va mal *|
|* *|
\**************************************************************************/
CONCURSANTES *NuevoConcursante(CONCURSANTES *Concur)
{
CONCURSANTES *aux, *Concursante;
if ( (aux = (CONCURSANTES *)malloc( sizeof(CONCURSANTES) ) ) == NULL )
return NULL;
Concursante = Concur;
aux -> sig = NULL;
// Todavia no hay concursantes
if ( Concursante == NULL )
{
Concursante = aux;
} else {
while( Concursante -> sig != NULL )
Concursante = Concursante -> sig;
Concursante -> sig = aux;
}
return aux;
}

962
DYNA_TBL.CPP Normal file
View File

@ -0,0 +1,962 @@
/**************************************************************************\
|* *|
|* 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 );
}

BIN
DYNA_TBL.EXE Normal file

Binary file not shown.

107
DYNA_TBL.H Normal file
View File

@ -0,0 +1,107 @@
/**************************************************************************\
|* *|
|* DYNA_TBL *|
|* *|
|* Descripci¢n: (fichero de apoyo) *|
|* 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... *|
|* *|
\**************************************************************************/
#define ERROR 0
#define OK 1
// Defino las posiciones dentro de Sprite que ocupan los distintos elementos
// y el tipo de Sprite del que se trata
#define POS_NUMEROS 0
#define POS_ELEM_MAPA 1
#define POS_POWERUP 2
#define POS_BOMBA 3
#define POS_TELEPORT 4
#define POS_GLOBO 5
#define POS_GOSTH 6
#define POS_ESTRELLA 7
#define POS_BAQUERO 8
#define POS_PLATANO 9
#define POS_JUGADORa 10
#define POS_JUGADORb 11
#define POS_JUGADORc 12
#define POS_JUGADORd 13
#define POS_FUEGOv 14
#define POS_FUEGOh 15
#define POS_BOSQUE 18
#define SPR_NUMEROS 3
#define SPR_ELEM_MAPA 2
#define SPR_POWERUP 0
#define SPR_BOMBA 4
#define SPR_TELEPORT 4
#define SPR_GLOBO 5
#define SPR_GOSTH 5
#define SPR_ESTRELLA 6
#define SPR_BAQUERO 5
#define SPR_PLATANO 5
#define SPR_JUGADOR 7
#define SPR_FUEGO 8
void Error(int code);
void ComienzaJuego(void);
void InicializaJuego(void);
int CargaPaleta(char *file);
void LiberaMemoriaObjetos(void);
int CargaObjetosBasicos( void );
int MuestraMensajeCargando(void);
int InsertaObjetosBase( int Objetos );
int InicializaElementosBasicos( void );
int MemoriaBitmap( int Pos, int TipoSprite );
void ProcesaPuntoBasico( int x, int y, char color );
void ProcesaPuntoJugador( int x, int y, char color );
int MuestraImagen( char *file, int page, int col_Inv );
// Estructura donde se guardaran las preferencias del usuario
typedef struct
{
char Entorno; // Bosque / Hielo / ....
char Jugadores; // M x. 4
char Teclas[5][6]; // Teclas de los Jugadores
} PREFERENCIAS;
// Informe sobre los bitmap's
typedef struct
{
char NDirecciones; // # de direcciones
// Inicio del Despl a...
char Inicios[5]; // Izq, Der, Arr, Abj, Muerte
char Movimientos[5]; // Movimientos por cada direcci¢n
unsigned char Ancho, Alto; // Dimensiones del objeto
char CorrX, CorrY;
char PixelCambio;
} DatosTipo;
// Estructura para guardar los Bitmap
typedef struct EnemigO
{
char Tipo; // Cada tipo de enemigo tiene un codigo
// de ajuste...
char far *Sprite[5]; // 5 puteros por direccion + muerte
} SPRITE;
extern SPRITE *Sprite;
extern PREFERENCIAS Pref;
extern const DatosTipo InfoSprites[];
extern char prt_tbl[13+1][21+1];
extern "C" void SET_VECTORES(volatile char *);
extern "C" void UNSET_VECTORES(void);
extern volatile char mapa_teclado[512];

757
DYNA_TBL.JD Normal file
View File

@ -0,0 +1,757 @@
/**************************************************************************\
|* *|
|* 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 / *|
|* *|
\**************************************************************************/
#include <alloc.h>
#include <stdio.h>
#include "..\modex\modex.h"
#include "..\modex\c_utils.h"
#include <conio.h>
#include <stdlib.h>
#define ERROR 0
#define OK 1
// Defino las posiciones dentro de Sprite que ocupan los distintos elementos
// y el tipo de Sprite del que se trata
#define POS_NUMEROS 0
#define POS_ELEM_MAPA 1
#define POS_POWERUP 2
#define POS_BOMBA 3
#define POS_TELEPORT 4
#define POS_GLOBO 5
#define POS_GOSTH 6
#define POS_ESTRELLA 7
#define POS_BAQUERO 8
#define POS_PLATANO 9
#define POS_BOSQUE 18
#define SPR_NUMEROS 3
#define SPR_ELEM_MAPA 2
#define SPR_POWERUP 0
#define SPR_BOMBA 4
#define SPR_TELEPORT 4
#define SPR_GLOBO 5
#define SPR_GOSTH 5
#define SPR_ESTRELLA 6
#define SPR_BAQUERO 5
#define SPR_PLATANO 5
int CargaPaleta(char *file);
void ProcesaPuntoBasico( int x, int y, char color );
int MuestraImagen( char *file, int page, int col_Inv );
int CargaObjetosBasicos( void );
int InsertaObjetosBase( int Objetos );
int InicializaElementosBasicos( void );
int MemoriaBitmap( int Pos, int TipoSprite );
void LiberaMemoriaObjetos(void);
void InicializaJuego(void);
typedef struct
{
char Entorno;
} PREFERENCIAS;
typedef struct
{
char NDirecciones; // # de direcciones
// Inicio del Despl a...
char Inicios[5]; // Izq, Der, Arr, Abj, Muerte
char Movimientos[5]; // Movimientos por cada direcci¢n
unsigned char Ancho, Alto; // Dimensiones del objeto
} DatosTipo;
typedef struct EnemigO
{
char Tipo; // Cada tipo de enemigo tiene un codigo
// de ajuste...
char *Sprite[5]; // 5 puteros por direccion + muerte
} SPRITE;
SPRITE *Sprite;
int NObjetos=0; // # de objetos ya contenidos en Sprite
// Establece preferencias
PREFERENCIAS Pref = { POS_BOSQUE };
// 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,
// 01 > Cuadros est ticos 16x16 ( Unidades )
0x02,
{ 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x01, 0x00, 0x00, 0x00, 0x00 },
0x10, 0x10,
// 02 > Cuadros est ticos 16x16 ( Mapas )
0x02,
{ 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x2D, 0x00, 0x00, 0x00, 0x00 },
0x10, 0x10,
// 03 > Cuadros est ticos 16x18 ( Numeros )
0x02,
{ 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x0A, 0x00, 0x00, 0x00, 0x00 },
0x10, 0x12,
// 04 > Anim. como Bomba, TelePort... 16x18
0x02,
{ 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x03, 0x03, 0x03, 0x03, 0x03 },
0x10, 0x12,
// 05 > Monstruos como Globo y Fantasma 16x18
0x02,
{ 0x00, 0x00, 0x00, 0x00, 0x03 },
{ 0x03, 0x03, 0x03, 0x03, 0x06 },
0x10, 0x12,
// 06 > Monstruos 4dir. Estrella... 16x18
0x05,
{ 0x00, 0x03, 0x06, 0x09, 0x0C },
{ 0x03, 0x03, 0x03, 0x03, 0x06 },
0x10, 0x12,
};
char prt_tbl[13][21] =
{
{ 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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0 },
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0 },
{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0 },
{ 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0 },
{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0 },
{ 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
void Error(int code)
{
set_video_mode (3);
LiberaMemoriaObjetos();
exit(code);
};
int MuestraMenu(void)
{
return ERROR;
};
void ComienzaJuego(void)
{};
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;
};
int main( void )
{
printf( "\n> Inicializando ModoX" );
printf( "\n> Jos David Guillen" );
init_random ();
if (set_vga_modex( Mode_360x240, 360, 240, 3) == 0) Error(0x00);
if ( MuestraMensajeCargando() != OK ) Error(0x10);
/*
while ( MuestraMenu() == OK )
{
*/
InicializaJuego();
set_display_page( 2 );
if ( CargaPaleta("images\\dyna_tbl.pcx") !=OK ) Error(0x11);
while( getch()!=27 )
{
InicializaJuego();
};
/*
copy_page( 2, 1 );
copy_page( 2, 0 );
ComienzaJuego();
};
*/
set_video_mode (3);
LiberaMemoriaObjetos();
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;
// Pido memoria para los elementos b sicos
if ( InicializaElementosBasicos() != OK ) return ERROR;
// 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++;
}
}
}
}
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;
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;
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// 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;
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;
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// 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;
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;
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// 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;
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;
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// 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;
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// 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;
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// 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 && y < 94 )
Sprite[POS_NUMEROS].Sprite[0][( ( x - (Xw+1)*i) + (Xw*(y-76)) ) + (Xw*Yw*i)] = color;
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// 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 )
Sprite[POS_POWERUP].Sprite[0][( ( x - (Xw+1)*i) + (Xw*(y-(114+16*j))) ) + (Xw*Yw*(i+j*9))] = color;
// þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ
// 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;
}
/**************************************************************************\
|* *|
|* 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
if ( InsertaObjetosBase( 10) != OK ) return ERROR;
// Pide espacio para el BitMap del objeto, incluida animaci¢n:
if (
// 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
) 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;
// 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 )
if ( ( Sprite[Pos].Sprite[i] = (char *)malloc( 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 )
if ( ( Sprite[Pos].Sprite[4] = (char *)malloc( 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++ )
free( 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;
set_active_page(2);
// 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);
}
}
char prt_tbl2[13][21];
for ( j = 0; j<13; j++)
for ( i = 0; i<21; i++)
prt_tbl2[j][i] = prt_tbl[j][i];
// 4§ Coloco los cuadros destructibles
// Uno los dos intentos, para reforzar el n§ de arboles que aparecen
// >>>>>>>> 1§ intento del algoritmo que soporta 4
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;
}
}
// 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[20][ 0] = 0; prt_tbl[19][ 0] = 0; prt_tbl[20][ 1] = 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[20][12] = 0; prt_tbl[20][11] = 0; prt_tbl[19][12] = 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;
}

BIN
IMAGES/DYNA_CAR.PCX Normal file

Binary file not shown.

BIN
IMAGES/DYNA_FND.PCX Normal file

Binary file not shown.

BIN
IMAGES/DYNA_JGD.PCX Normal file

Binary file not shown.

BIN
IMAGES/DYNA_TBL.PCX Normal file

Binary file not shown.

BIN
IMAGES/PREW/01.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
IMAGES/PREW/02.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
IMAGES/PREW/DYNA_CAR.PCX Normal file

Binary file not shown.

BIN
IMAGES/PREW/DYNA_FND.PCX Normal file

Binary file not shown.

BIN
IMAGES/PREW/DYNA_JGD.PCX Normal file

Binary file not shown.

BIN
IMAGES/PREW/DYNA_TBL.PCX Normal file

Binary file not shown.

BIN
IMAGES/PREW/LET.PAL Normal file

Binary file not shown.

BIN
IMAGES/PREW/MDYNA.PAL Normal file

Binary file not shown.

BIN
IMAGES/PREW/NEW-1.PCX Normal file

Binary file not shown.

BIN
IMAGES/PREW/YO.PAL Normal file

Binary file not shown.

5
README.md Normal file
View File

@ -0,0 +1,5 @@
#DYNA
*16/12/1996*
ToDo: wwtcf?
![screenshot](/DYNA.png "Screenshot")