Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*------------------------------------------------------------------------*/
- /*-----------------------------------PACOMAN------------------------------*/
- /*------------------------------------------------------------------------*/
- #include <string.h>
- #include <conio.h>
- #include <stdio.h>
- #include <dos.h>
- #include <stdlib.h>
- /* CONSTANTES SIMBOLICAS*/
- /* VERSION */
- #define PACOVER "v0.5a"
- #define COMPATIVERSION 'a' //a:casa //b:notebook hp //->necesario puesto que el ASCII de las notebooks hp aparentemente difiere de el de la maquina de mi casa en algunos caracteres
- /* SONIDO */
- //#define CONWAKA 1 //hace *wakawakawaka* cuando se mueve?
- //#define CONTWEET 1 //hace *tweet* cuando come un fantasma?
- //#define CONMUSICAMUERTE //hace priiiiibuuukacua
- /* SIMBOLOS DEL MAPA */
- #define PVAI 185 //¹:185 pared vertical abierta a la izquierda
- #define PVER 186 //º:186 pared vertical
- #define ECSD 187 //»:187 esquina cerrada superior derecha
- #define ECID 188 //¼:188 esquina cerrada inferior derecha
- #define ECSI 201 //É:201 esquina cerrada superior izquierda
- #define ECII 200 //È:200 esquina cerrada inferior izquierda
- #define TINV 202 //Ê:202 T abierta invertida
- #define TCOM 203 //Ë:203 T abierta
- #define PVAD 204 //Ì:204 pared vertical abierta a la derecha
- #define PHZN 205 //Í:205 pared horizontal
- #define CRUZ 206 //Î:206 + (cruz abierta)
- #define SPFN 126 //~:126 spawn fantasma <-requiere un espacio vacio arriba //cuenta como pared //SOLO PUEDE HABER UNO POR MAPA
- #define PACO 2 //:2 paco /spawn paco //SOLO PUEDE HABER UNO EN EL MAPA
- #if COMPATIVERSION=='a' //si estamos en modo compatibilidad con la pc de mi casa
- #define PAST 250 //ú:250 pastilla
- #define SPAS 155 //›:155 super pastilla
- #define FANT 169 //©:169 fantasma
- #elif COMPATIVERSION=='b' //si estamos en modo compatibilidad con las notebooks hp
- #define PAST 249 //ù:249 pastilla
- #define SPAS 236 //ì:236 super pastilla
- #define FANT 234 //ê:234 fantasma
- #endif
- /* TIPOS DE DATOS */
- struct ente{
- char q; //su simbolo
- int x; //su posicion en x
- int y; //su posicion en y
- int dir; //la direccion en la que se mueve //0 no se mueve
- int vel; //la velocidad a la que se mueve //0 no se mueve
- int def_vel; //la velocidad estandar del ente
- int dopa_vel; //la velocidad del ente cuando el paco esta dopado
- int def_color; //su color normal
- int color; //el color que posee actualmente
- int dopa_color; //su color cuando el paco esta dopado
- };
- /* CONSTANTES GLOBALES */
- const int POS_INI_X=1; //comienzo del mapa en x
- const int POS_INI_Y=3; //comienzo del mapa en y
- const int PAREDES[12]={PVAI, PVER, ECSD, ECID, ECSI, ECII, TINV, TCOM, PVAD, PHZN, CRUZ, SPFN}; //todos los caracteres que no son caminables
- enum DIRECCIONES{QUIETO=0,ARR,IZQ,ABA,DER}; //las 4 posibles direcciones de movimiento
- const int MAX_DIR=DER;
- enum VELOCIDADES{ NORMAL=1,RAPIDO}; //las posibles velocidades (es valida la direccion QUIETO como velocidad 0)
- const int MAX_VEL=RAPIDO;
- const char MOV_AR='w';
- const char MOV_IZ='a';
- const char MOV_AB='s';
- const char MOV_DE='d';
- const char SALIR='k';
- const char PAUSA='p';
- enum ERRORES{PSNF=0,FSNF,PANF,SPANF,MFDG,FMNE}; //los distintos codigos de error
- const int ANCHOMAPA=22; //1 espacio extra para el caracter de fin de cadena
- const int ALTOMAPA=21; //OjO, el mapa no debe tener mas de 20 de altura o no entra en la pantalla todo
- const int MAXFANTASMAS=4; //la maxima cantidad de fantasmas simultaneos //nota, no puede ser mayor a (MAX_FANT_COLOR-MIN_FANT_COLOR)
- const int MAX_VEL_FANT=NORMAL; //la maxima velocidad posible para los fantasmas
- const int MIN_FANT_COLOR=GREEN; //el color mas bajo asignable a un fantasma
- const int MAX_FANT_COLOR=DARKGRAY; //el color mas alto asignable a un fantasma
- const int FANT_DOPA_COLOR=LIGHTBLUE+BLINK; //el color de los fantasmas cuando el paco esta dopado
- const int PACO_DEF_COLOR=YELLOW; //el color normal del paco
- const int PACO_DOPA_COLOR=YELLOW; //el color dopado del paco
- const int PACO_DEF_DIR=ARR; //direccion en la que comienza moviendoce el paco
- const int PACO_DEF_VEL=NORMAL; //velocidad estandar del paco //nota: dado mi estilo vago de programacion, el paco no deberia tener una velocidad mayor a 1, de lo contrarios pueden darse errores con las verificaciones de coliciones con los fantasmas, los fantasmas por otro lado pueden ser tan rapidos como se quiera.
- const int COLOR_TEXTO=WHITE;
- const int COLOR_MAPA=RED;
- const int COLOR_PASTILLAS=YELLOW;
- const int COLOR_PUNTAJE_OBT=CYAN;
- const int PUNTAJE_PASTILLA=1;
- const int PUNTAJE_SUP_PAST=10;
- const int PUNTAJE_FANTASMA=100;
- const int LAPSO_ENTRE_FANTASMAS=13; //el tiempo en segundos entre que sale un fatasma y el siguiente
- const int DURACION_DOPA=30; //duracion de la superpastilla en segundos
- const int DEF_VIDAS=1; //vidas con las que comienza la partida el jugador
- const int HSFPS=75; //la cantidad de centesimas de segundo a esperar antes del siguiente cuadro
- const char CHARNULO=' ';
- #ifdef CONWAKA //faa, fanatico de la performance :P
- const int FREC_DOPADO=100; //default:100
- const int MIN_FREC_WAKA=300; //default:300
- const int MAX_FREC_WAKA=600; //default:600
- const int MIN_INTER_WAKA=600; //default:600
- const int MAX_INTER_WAKA=1200; //default:1200
- int g_sonando=0; //es constante, pero ni ganas de hacer otro ifdef-endif
- int g_suena_mueve=0; //para que solo suene si se esta moviendo el paco
- #endif
- /* VARIABLES GLOBALES */
- int g_puntaje=0; //puntaje del jugador
- int g_vidas=DEF_VIDAS; //vidas del jugador
- int g_killing_spree=0; //bonus por cantidad de fantasmas comidos en una misma sesion de dopaje //aumenta el puntaje que entrega comerse a un fantasma
- int g_pastillas=0; //la cantidad de pastillas que faltan comer
- int g_super_pastillas=0;
- int g_cant_fant=0; //la cantidad de fantasmas que hay dando vuelta
- int g_fin_del_juego=0; //cuando sea !=0 terminar el juego
- int g_dopado=0; //para saber si hay activa una superpastilla
- struct time g_t_com_dopa; //comienzo del dopaje
- struct time g_t_com_juego; //comienzo del juego
- int g_color_fantasma_muerto=-1; //soy un limado (no, no voy a explicar para que es esto, es bastante autoexplicativo, mira en el main sino) //nota: esto sirve solo porque no puede haber 2 fantasmas con el mismo color
- char pastillas[ALTOMAPA][ANCHOMAPA];
- char MAPA001[ALTOMAPA][ANCHOMAPA]={ //el mapa cargado, si bien no es constante me resulta comodo ponerlo en mayuscula
- /**/" ",/**/ "ÉÍÍÍÍÍ» ÉÍÍÍÍÍ»", //NOTA, el agregado de una linea vacia al comienzo es por el bug raro que aparecio al separar las pastillas en otra capa, el porque del bug me sigue eludiendo
- "º21111ÈÍÍÍÍÍÍͼ11112º",
- "º1ÉÍ»11111111111ÉÍ»1º",
- "º1º ÈÍÍÍÍ»1ÉÍÍÍͼ º1º",
- "º1ÈËÍËÍÍͼ1ÈÍÍÍËÍ˼1º",
- "º11Èͼ111121111Èͼ11º",
- "È»11111ÉÍÍ~ÍÍ»11111ɼ",
- " ÈÍÍÍ»1ÈÍÍÍÍͼ1ÉÍÍͼ ",
- " Éͼ111111111ÈÍ» ",
- " Éͼ111ÉÍ»1ÉÍ»111ÈÍ» ",
- "ɼ111ÉÍÎ͹1ÌÍÎÍ»111È»",
- "º11Éͼ º º1º º ÈÍ»11º",
- "º1ɼ º º1º º È»1º",
- "º1ÌÍÍÍÍÊ͹1ÌÍÊÍÍÍ͹1º",
- "º1º º1º º1º",
- "º1º º1º º1º",
- "º1ÈÍ» Éͼ1ÈÍ» Éͼ1º",
- "º111ÈÍͼ1111ÈÍͼ111º",
- "ÈÍ»211111ÉÍ»111112Éͼ",
- " ÈÍÍÍÍÍͼ ÈÍÍÍÍÍͼ ",};
- /*PROTOTIPO DE FUNCIONES */
- void muestra_titulo(); //limpia la pantalla y muestra el titulo del juego
- void muestra_mapa(); //imprime el mapa en pantalla
- void muestra_pastillas(); //actualiza las pastillas
- void muestra_puntaje_y_vidas(); //muestra las vidas y el puntaje del jugador denajo del mapa
- void muestra_instrucciones(); //muestra las teclas de manejo al fondo de la pantalla
- void muestra_ente(struct ente); //dibuja al ente que se le pasa en su posicion correspondiente y con su correspondiente color
- struct ente buscar_ente(char); //busca un cierto caracter en el mapa y lo devuelve como ente
- int buscar_spawn_paco(struct ente&); //busca el caracter de spawn del paco
- int buscar_spawn_fantasma(struct ente&); //busca el caracter de spawn de fantasmas
- void buscar_pastillas(); //busca las pastillas, las convierte al caracter segun la version y las carga en el arreglo (limpiando el mapa), guardando la cantidad ademas, obvio
- void crear_paco(struct ente &paco, struct ente spawn); //crea al ente paco en la posicion dada por su ente spawn
- void crear_fant(struct ente &fant, int&, struct ente spawn); //crea un ente fantasma arriba de la puerta o punto de spawn de fantasma
- void recibir_input(struct ente&); //recibe input desde el teclado y lo interpreta
- void modif_dir_ente(int nuevadir,struct ente&); //modifica la direccion del ente dado
- void mover_ente(struct ente&,struct ente otto); //mueve a un ente en la direccion dada y con su velocidad propia (si es posible) /nota: el chocarse contra una pared termina el movimiento hasta el siguiente cuadro //verifica la coliciones con el ente "otto" //nota: uso "otto" porque "aux" ya era otra cosa en la funcion, y "dummy" tom‚ por costumbre que sea un ente vacio, asi que este ente auxiliar generico se lama "otto"
- int valid_mov(struct ente, struct ente otto); //verifica que sea valido mover al ente/ devuelve la cantidad de espacios que se movera en la direccion dada //verfica las coliciones con el ente "otto"
- void comer_pastilla(int x, int y); //elimina la pastilla del mapa en la posicion dada, suma el puntaje y llama a la funcion que comienza el dopaje en caso de que haya sido una super pastilla
- void err(int); //maneja los errores del programa
- /* MAIN */
- int main()
- {
- gettime(&g_t_com_juego);
- /* CONSTANTES LOCALES DE MAIN*/
- /* VARIABLES LOCALES DE MAIN*/
- int i=0,j=0; //indices genericos
- #ifdef CONWAKA //se, ya lime con esto, asi que la hago completa
- int sonando; //para alternar el sonido producido..
- #endif
- struct ente punto_spawn_paco;
- struct ente punto_spawn_fantasma;
- struct ente paco;
- struct ente fantasmas[MAXFANTASMAS];
- struct ente dummy; dummy.q=CHARNULO; dummy.x=0; dummy.y=0; //ver para que lo uso en la funcion de movimiento, validacion de movimiento y entonces coliciones
- int ult_color_fant=MIN_FANT_COLOR; //el color asignado al ultimo fantasma que fue creado
- int imprimir_puntaje=0;
- struct time t_com_bucle; //variable para buclear mientras que el usuario realice un input
- struct time t_ultimo_fant; //cuando se cre¢ el ultimo fantasma
- struct time t_aux;
- //int t_hudif=0;
- int t_sedif=0;
- /* INICIO DEL PROGRAMA */
- srand(time(0)); //inicializa el generador de numeros aleatorios
- muestra_titulo(); //muestra *PACOMAN vX.X*
- if(buscar_spawn_paco(punto_spawn_paco)) {err(PSNF); return PSNF; }
- if(buscar_spawn_fantasma(punto_spawn_fantasma)) {err(FSNF); return FSNF; }
- buscar_pastillas(); if(!g_pastillas) {err(PANF); return PANF; }
- if(MAXFANTASMAS > MAX_FANT_COLOR-MIN_FANT_COLOR) {err(MFDG); return MFDG; }
- crear_paco(paco, punto_spawn_paco);
- crear_fant(fantasmas[g_cant_fant],ult_color_fant,punto_spawn_fantasma);
- gettime(&t_ultimo_fant); /* creamos un fantasma si ya es hora */
- do
- {
- gettime(&t_aux);
- t_sedif=t_aux.ti_sec-g_t_com_dopa.ti_sec;
- (t_sedif<0)?t_sedif=-t_sedif:1;
- if(t_sedif>=DURACION_DOPA)
- {
- g_dopado=0;
- g_killing_spree=0;
- }
- if(g_cant_fant<MAXFANTASMAS && !g_dopado) //solo se crean fantasmas si no se llego al maximo y si el paco no esta dopado, para evitar que "campee"
- {
- gettime(&t_aux);
- t_sedif=t_aux.ti_sec-t_ultimo_fant.ti_sec;
- (t_sedif<0)?t_sedif=-t_sedif:1;
- if(t_sedif>=LAPSO_ENTRE_FANTASMAS)
- {
- crear_fant(fantasmas[g_cant_fant],ult_color_fant,punto_spawn_fantasma);
- gettime(&t_ultimo_fant);
- }
- }
- muestra_titulo();
- muestra_mapa();
- muestra_pastillas();
- muestra_ente(paco);
- for (i=0;i<g_cant_fant;i++)
- muestra_ente(fantasmas[i]);
- muestra_puntaje_y_vidas();
- muestra_instrucciones();
- if(imprimir_puntaje)
- {
- textcolor(COLOR_PUNTAJE_OBT);
- gotoxy(POS_INI_X+paco.y,POS_INI_Y+paco.x);
- cprintf("%d!!",PUNTAJE_FANTASMA*g_killing_spree);
- #ifdef CONTWEET
- printf("\a\a\a");
- #endif
- textcolor(WHITE);
- imprimir_puntaje=0;
- }
- gettime(&t_com_bucle);
- // gotoxy(1,13); printf("\n%d %d",paco.x,paco.y); //que muestre la posicion para debuggear mas facil
- do //bucle para input/espera a siguiente cuadro para no actualizar muchas veces por segundo que queda feo
- {
- #ifdef CONWAKA
- if (g_suena_mueve)
- {
- if(!g_dopado)
- if(g_sonando>MIN_INTER_WAKA){sound(MIN_FREC_WAKA); g_sonando++; if(g_sonando>MAX_INTER_WAKA)g_sonando=0;}//wakawakawakawaka..
- else{sound(MAX_FREC_WAKA); g_sonando++;}
- else sound(FREC_DOPADO);
- }
- #endif
- recibir_input(paco);
- gettime(&t_aux);
- /*t_hudif=t_aux.ti_hund-t_com_bucle.ti_hund;
- (t_hudif<0)?t_hudif=-t_hudif:1;*/
- t_sedif=t_aux.ti_sec-t_com_bucle.ti_sec;
- (t_sedif<0)?t_sedif=-t_sedif:1;
- }while(/*t_hudif<HSFPS&&*/t_sedif<1);
- mover_ente(paco, dummy); //mando a dummy porque no tengo nada que pasarle, las coliciones del paco con los fantasmas se verfican al mover los fantasmas nomas
- for (i=0;i<g_cant_fant;i++)
- {
- mover_ente(fantasmas[i], paco);
- if(g_color_fantasma_muerto!=-1) //elimina al fantasma muerto, muestra y suma puntaje y usa el intervalo de tiempo para crear otro fantasma
- {
- i=-1;
- do
- {
- i++;
- }while(fantasmas[i].color!=g_color_fantasma_muerto /*&& i<g_cant_fant*/); //por alguna razon si le agrego la condicion que dej‚ comentada no anda
- if(fantasmas[i].color!=g_color_fantasma_muerto) {err(FMNE); return FMNE;} //porlas
- for(j=i;j<g_cant_fant-1;j++) //mueve todos los fantasmas que estan despues del muerto para eliminarlo
- {
- fantasmas[j]=fantasmas[j+1];
- }
- g_cant_fant--;
- fantasmas[g_cant_fant].color=WHITE; //simplemente un color ilegal para fantasmas, para que no quede tanta basura (paranoia?)
- g_killing_spree++;
- g_puntaje+=PUNTAJE_FANTASMA*g_killing_spree;
- g_color_fantasma_muerto=-1;
- gettime(&t_ultimo_fant);
- imprimir_puntaje=1;
- }
- }
- }while(!g_fin_del_juego);
- #ifdef CONWAKA
- nosound(); //detiene el wakawaka
- #endif
- #ifdef CONMUSICAMUERTE
- if(g_fin_del_juego==2)
- {
- for(i=500;i>100;i--)
- {
- sound(i);
- delay(5);
- }
- nosound();
- sound(700);
- delay(300);
- nosound();
- sound(700);
- delay(300);
- nosound();
- }
- #endif
- muestra_titulo();
- muestra_mapa();
- muestra_pastillas();
- // muestra_ente(paco);
- for (i=0;i<g_cant_fant;i++)
- muestra_ente(fantasmas[i]);
- muestra_puntaje_y_vidas();
- switch (g_fin_del_juego)
- {
- case 1: printf("\nGANASTE!!"); break;
- case 2: printf("\nperdiste.. y bueh.."); break;
- case 3: printf("\naah, cobarde, no lograste terminar la partida"); break;
- }
- while(!kbhit());
- return 0;
- /* FIN DEL PROGRAMA */
- }
- /* DEFINICION DE FUNCIONES */
- void mover_ente(struct ente &pj, struct ente otto) //MUEVE AL ENTE EN LA DIRECCION DADA SEGUN SU VELOCIDAD Y SEGUN SEA POSIBLE. CONTROLA EL MOVIMIENTO DE LOS FANTASMAS, EL WAKAWAKA, Y NO ME ACUERDO SI ALGO MAS /nota: esta funcion tb quedo demasiado grande creo
- {
- int cant=0, dir=0, ban=0;
- char aux=CHARNULO;
- if(pj.dir>QUIETO && pj.vel>QUIETO)
- {
- cant=valid_mov(pj, otto);
- if (cant>0)
- {
- switch (pj.dir)
- {
- case ARR: pj.x-=cant; break;
- case ABA: pj.x+=cant; break;
- case IZQ: pj.y-=cant; break;
- case DER: pj.y+=cant; break;
- }
- }
- }
- if(pj.q==(char)FANT) /* controla el movimiento de los fanasmas.. tengo que pensar algo menos frutal.. quizas que sigan al paco.. nose..*/
- {
- switch (pj.dir)
- {
- case ARR: aux=MAPA001[pj.x-1][pj.y]; break;
- case ABA: aux=MAPA001[pj.x+1][pj.y]; break;
- case IZQ: aux=MAPA001[pj.x][pj.y-1]; break;
- case DER: aux=MAPA001[pj.x][pj.y+1]; break;
- }
- if(cant<pj.vel || aux!=CHARNULO)
- {
- dir=pj.dir;
- do
- {
- pj.dir=rand()%MAX_DIR +1;
- switch (pj.dir)
- {
- case ARR: aux=MAPA001[pj.x-1][pj.y]; break;
- case ABA: aux=MAPA001[pj.x+1][pj.y]; break;
- case IZQ: aux=MAPA001[pj.x][pj.y-1]; break;
- case DER: aux=MAPA001[pj.x][pj.y+1]; break;
- }
- }while(pj.dir==dir && aux!=CHARNULO);
- }
- }
- #ifdef CONWAKA
- if(pj.q==(char)PACO)
- if(cant>0)
- g_suena_mueve=1;
- else
- {
- nosound(); //solo debe sonar si se esta moviendo el paco
- g_suena_mueve=0;
- }
- #endif
- return;
- }
- int valid_mov(struct ente pj, struct ente otto) //DEVUELVE CUANTOS CUADROS SE PUEDE MOVER EN LA DIRECCION DADA SIN CHOCARSE /CALCULA LAS COLICIONES DE SER NECESARIO/nota: es un monstro esta funcion ahora
- {
- char aux;
- int i=0, cant=0, ban=0;
- int x=pj.x, y=pj.y;
- if(pj.q==(char)FANT && otto.q==(char)PACO)
- if(x==otto.x && y==otto.y)
- if(!g_dopado)
- {
- g_vidas--;
- /* TERMINAR RONDA*/
- if(g_vidas==0) g_fin_del_juego=2; //cuando lo termine posta (cuando implemente varias rondas) esto ya no iria aca
- return 0; //si colisionaron ahi sin moverse devuelve cero
- }
- else
- {
- g_color_fantasma_muerto=pj.color;
- }
- do
- {
- i++;
- switch (pj.dir)
- {
- case ARR: x=pj.x-i; break;
- case ABA: x=pj.x+i; break;
- case IZQ: y=pj.y-i; break;
- case DER: y=pj.y+i; break;
- }
- aux=MAPA001[x][y];
- if(aux!=CHARNULO) //un ente solo puede caminar a traves de espacio vacio (o pastillas, pero est n en otra matriz)
- ban=1;
- else
- {
- cant=i;
- if((pj.q==(char)PACO) && (pastillas[x][y]!=CHARNULO))
- comer_pastilla(x,y);
- if(pj.q==(char)FANT && otto.q==(char)PACO)
- if(x==otto.x && y==otto.y)
- if(!g_dopado)
- {
- g_vidas--;
- /* To Do: TERMINAR RONDA*/
- if(g_vidas==0) g_fin_del_juego=2; //cuando lo termine posta (cuando implemente varias rondas) esto ya no iria aca
- return 0; //para que salga sin hacer nada mas
- }
- else
- {
- g_color_fantasma_muerto=pj.color;
- }
- }
- }while(i<pj.vel && ban==0);
- return (cant);
- }
- void comer_pastilla(int x, int y) //se come una pastilla y hace lo que tenga que hacer
- {
- switch (pastillas[x][y])
- {
- case (char)PAST: g_puntaje+=PUNTAJE_PASTILLA; g_pastillas--; break;
- case (char)SPAS: g_puntaje+=PUNTAJE_SUP_PAST; g_super_pastillas--; gettime(&g_t_com_dopa); g_dopado=1; /* DOPAJE!! */ break;
- }
- pastillas[x][y]=CHARNULO;
- if (g_pastillas==0 && g_super_pastillas==0) g_fin_del_juego=1;
- return;
- }
- void recibir_input(struct ente &paco) //verfica si se ha pulsado una tecla y realiza la accion que corresponda
- {
- int tecla;
- if(kbhit())
- {
- tecla=getch();
- if (tecla==MOV_AR||tecla==MOV_IZ||tecla==MOV_AB||tecla==MOV_DE)
- modif_dir_ente(tecla, paco);
- else
- if (tecla==PAUSA)
- /*p*/;
- else
- if (tecla==SALIR)
- g_fin_del_juego=3;
- }
- return;
- }
- void modif_dir_ente(int nuevadir, struct ente &pj) //cambia la direccion del ente por la dada
- {
- char aux=CHARNULO;
- int dirant=pj.dir;
- switch (nuevadir)
- {
- case MOV_AR: pj.dir=ARR; break;
- case MOV_AB: pj.dir=ABA; break;
- case MOV_IZ: pj.dir=IZQ; break;
- case MOV_DE: pj.dir=DER; break;
- }
- switch (pj.dir)
- {
- case ARR: aux=MAPA001[pj.x-1][pj.y]; break;
- case ABA: aux=MAPA001[pj.x+1][pj.y]; break;
- case IZQ: aux=MAPA001[pj.x][pj.y-1]; break;
- case DER: aux=MAPA001[pj.x][pj.y+1]; break;
- }
- if (aux!=CHARNULO) pj.dir=dirant;
- return;
- }
- struct ente buscar_ente(char coso) /* DEVUELVE UN ENTE CON EL CARACTER BUSCADO EN SU POSICION (soy malo con las descripciones..)*/
- {
- struct ente esto;
- int i=0, j=0;
- for(i=0;i<ALTOMAPA;i++)
- for(j=0;j<ANCHOMAPA;j++)
- if(MAPA001[i][j]==coso)
- {
- esto.q=coso;
- esto.x=i;
- esto.y=j;
- esto.dir=QUIETO;
- esto.vel=esto.def_vel=QUIETO;
- esto.dopa_color=esto.color=esto.def_color=WHITE;
- return esto;
- }
- esto.q='0';
- return esto;
- }
- int buscar_spawn_paco(struct ente &paco) /* BUSCA EL PUNTO DE SPAWN DEL PACO */
- {
- paco=buscar_ente((char)PACO);
- if (paco.q=='0') return 1;
- else
- {
- MAPA001[paco.x][paco.y]=CHARNULO; // quita el simbolo de spawn del mapa
- return 0;
- }
- }
- int buscar_spawn_fantasma(struct ente &fant) /* BUSCA EL PUNTO DE SPAWN DE LOS FANTASMAS */
- {
- fant=buscar_ente((char)SPFN);
- if (fant.q=='0') return 1;
- else return 0;
- }
- void buscar_pastillas() /* BUSCA TODAS LAS PASTILLAS EN EL MAPA Y LAS CARGA */
- {
- int i=0,j=0;
- char aux=CHARNULO;
- for(i=0;i<=ALTOMAPA;i++)
- for(j=0;j<ANCHOMAPA;j++)
- {
- switch(MAPA001[i][j])
- {
- case '1': pastillas[i][j]=(char)PAST;
- g_pastillas++;
- MAPA001[i][j]=CHARNULO;
- break;
- case '2': pastillas[i][j]=(char)SPAS;
- g_super_pastillas++;
- MAPA001[i][j]=CHARNULO;
- break;
- default: pastillas[i][j]=CHARNULO;
- break;
- }
- }
- return;
- }
- void crear_fant(struct ente &fantasma, int& color, struct ente spawn) /*CREA E INICIALIZA A UN FANTASMA*/
- {
- char aux=MAPA001[spawn.x-1][spawn.y];
- if (g_cant_fant<MAXFANTASMAS)
- if(aux==CHARNULO)
- {
- fantasma.q=(char)FANT;
- fantasma.x=spawn.x-1; //osea que lo crea una posicion arriba de el punto de spawn
- fantasma.y=spawn.y;
- fantasma.dir=rand()%4 +1; //sin el +1 podria dar 0, que es quieto
- fantasma.vel=fantasma.def_vel=rand()%MAX_VEL_FANT +1; //sin el +1 podria dar 0, que es el quieto
- color++;
- fantasma.color=fantasma.def_color=color;
- fantasma.dopa_color=FANT_DOPA_COLOR;
- g_cant_fant++;
- }
- //else /*no se pudo crear el fantasma debido a que el espacio sobre el punto de spawn estaba ocupado */
- //else /*no se pudo crear el fantasma debido a que ya se ha llegado al maximo de fantasmas*/
- return;
- }
- void crear_paco(struct ente &paco, struct ente spawn) /*CREA E INICIALIZA AL PACO*/
- {
- paco.q=(char)PACO;
- paco.x=spawn.x;
- paco.y=spawn.y;
- paco.dir=PACO_DEF_DIR;
- paco.vel=paco.def_vel=PACO_DEF_VEL;
- paco.color=paco.def_color=PACO_DEF_COLOR;
- paco.dopa_color=PACO_DOPA_COLOR;
- return;
- }
- void err(int horror) /* MANEJA LOS ERROES DEL PROGRAMA */
- {
- clrscr();
- switch(horror)
- {
- case PSNF: printf("\n\nERROR %d: no se encontro el punto de spawn del paco en el mapa",PSNF); break;
- case FSNF: printf("\n\nERROR %d: no se encontro el punto de spawn del fantasma en el mapa",FSNF); break;
- case PANF: printf("\n\nERROR %d: no se encontro ninguna pastilla en el mapa",PANF); break;
- case SPANF: printf("\n\nERROR %d: no se encontro ninguna superpastilla en el mapa",SPANF); break;
- case MFDG: printf("\n\nERROR %d: el maximo de fantasmas existentes es mayor a la cantidad de colores posibles",MFDG); break;
- case FMNE: printf("\n\nERROR %d: sucedio fruta al tratar de matar un fantasma",FMNE); break;
- }
- getche();
- return;
- }
- void muestra_titulo() /* LIMPIA LA PANTALLA Y MUESTRA EL TITULO */
- {
- textbackground(BLACK);
- textcolor(WHITE);
- clrscr();
- textbackground(BLUE);
- textcolor(YELLOW);
- //gotoxy(20,1); cprintf("*******************************");
- gotoxy(22,2); cprintf("****** ******");
- //gotoxy(20,3); cprintf("*******************************");
- textcolor(YELLOW + BLINK);
- gotoxy(29,2); cprintf("PACOMAN %s",PACOVER);
- gotoxy(POS_INI_X,POS_INI_Y);//deja el cursor en un lugar comodo para continuar con el juego
- textbackground(BLACK); //deja el fondo estandar
- textcolor(WHITE); //deja la fuente estandar
- return;
- }
- void muestra_mapa() /* MUESTRA EL MAPA EN PANTALLA */
- {
- textcolor(COLOR_MAPA);
- gotoxy(POS_INI_X,POS_INI_Y);
- int i=0, j=0;
- for(i=0;i<ALTOMAPA;i++)
- {
- for(j=0;j<ANCHOMAPA;j++)
- {
- cprintf("%c",MAPA001[i][j]);
- }
- printf("\n");
- }
- textcolor(WHITE);
- return;
- }
- void muestra_pastillas() /* MUESTRA LAS PASTILLAS EN PANTALLA */
- {
- textcolor(COLOR_PASTILLAS);
- int i=0, j=0;
- for(i=0;i<ALTOMAPA;i++)
- {
- for(j=0;j<ANCHOMAPA;j++)
- {
- if(pastillas[i][j]!=CHARNULO) //PORUQE ENTRA SI ES FALSO?!?!?
- {
- gotoxy(POS_INI_X+j,POS_INI_Y+i);
- cprintf("%c",pastillas[i][j]);
- }
- }
- }
- textcolor(WHITE);
- return;
- }
- void muestra_puntaje_y_vidas()
- {
- textcolor(COLOR_TEXTO);
- gotoxy(POS_INI_X,POS_INI_Y+ALTOMAPA); //justo debajo del mapa
- printf("PUNTAJE: %d\t\tVIDAS: %d", g_puntaje, g_vidas);
- textcolor(WHITE);
- return;
- }
- void muestra_instrucciones()
- {
- textcolor(COLOR_TEXTO);
- gotoxy(POS_INI_X,POS_INI_Y+ALTOMAPA+1); //debajo del puntaje
- cprintf("Movimiento: Arriba:\'%c\' Izquierda:'\%c' Abajo:\'%c\' Derecha\'%c\' Salir:\'%c\'", MOV_AR, MOV_IZ, MOV_AB, MOV_DE, SALIR/*, PAUSA*/);
- textcolor(WHITE);
- return;
- }
- void muestra_ente(struct ente pj) /* MUESTRA AL ENTE DADO EN SU POSICION Y CON SU COLOR */
- {
- if(g_dopado)
- textcolor(pj.dopa_color);
- else
- textcolor(pj.color); //el color adecuado para el ente
- gotoxy(POS_INI_X+pj.y,POS_INI_Y+pj.x); //en las posicion adecuada dentro del mapa //nota:las x y las y cambiadas porque ni ganas de modificar todo el resto del codigo
- cprintf("%c",pj.q);
- textcolor(WHITE); // para continuar tranquilo con el resto del programa
- return;
- }
- /* Teh End */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement