Advertisement
Guest User

ZippoLag

a guest
Apr 28th, 2008
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 25.17 KB | None | 0 0
  1. /*------------------------------------------------------------------------*/
  2. /*-----------------------------------PACOMAN------------------------------*/
  3. /*------------------------------------------------------------------------*/
  4.  
  5. #include <string.h>
  6. #include <conio.h>
  7. #include <stdio.h>
  8. #include <dos.h>
  9. #include <stdlib.h>
  10.  
  11. /* CONSTANTES SIMBOLICAS*/
  12.        /* VERSION */
  13. #define PACOVER "v0.5a"
  14. #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
  15.  
  16.    /* SONIDO */
  17.  
  18. //#define CONWAKA 1       //hace *wakawakawaka* cuando se mueve?
  19. //#define CONTWEET 1      //hace *tweet* cuando come un fantasma?
  20. //#define CONMUSICAMUERTE //hace priiiiibuuukacua
  21.  
  22.         /* SIMBOLOS DEL MAPA */
  23. #define PVAI 185   //¹:185   pared vertical abierta a la izquierda
  24. #define PVER 186   //º:186   pared vertical
  25. #define ECSD 187   //»:187   esquina cerrada superior derecha
  26. #define ECID 188   //¼:188   esquina cerrada inferior derecha
  27. #define ECSI 201   //É:201   esquina cerrada superior izquierda
  28. #define ECII 200   //È:200   esquina cerrada inferior izquierda
  29. #define TINV 202   //Ê:202   T abierta invertida
  30. #define TCOM 203   //Ë:203   T abierta
  31. #define PVAD 204   //Ì:204   pared vertical abierta a la derecha
  32. #define PHZN 205   //Í:205   pared horizontal
  33. #define CRUZ 206   //Î:206   + (cruz abierta)
  34. #define SPFN 126   //~:126   spawn fantasma <-requiere un espacio vacio arriba //cuenta como pared //SOLO PUEDE HABER UNO POR MAPA
  35. #define PACO   2   //:2     paco /spawn paco //SOLO PUEDE HABER UNO EN EL MAPA
  36.  
  37. #if COMPATIVERSION=='a' //si estamos en modo compatibilidad con la pc de mi casa
  38. #define PAST 250   //ú:250   pastilla
  39. #define SPAS 155   //›:155   super pastilla
  40. #define FANT 169   //©:169   fantasma
  41. #elif COMPATIVERSION=='b' //si estamos en modo compatibilidad con las notebooks hp
  42. #define PAST 249   //ù:249   pastilla
  43. #define SPAS 236   //ì:236   super pastilla
  44. #define FANT 234   //ê:234   fantasma
  45. #endif
  46.  
  47. /* TIPOS DE DATOS */
  48.  
  49. struct ente{
  50.         char q;          //su simbolo
  51.         int x;           //su posicion en x
  52.         int y;           //su posicion en y
  53.         int dir;         //la direccion en la que se mueve //0 no se mueve
  54.         int vel;         //la velocidad a la que se mueve  //0 no se mueve
  55.         int def_vel;     //la velocidad estandar del ente
  56.         int dopa_vel;    //la velocidad del ente cuando el paco esta dopado
  57.         int def_color;   //su color normal
  58.         int color;       //el color que posee actualmente
  59.         int dopa_color;  //su color cuando el paco esta dopado
  60.        };
  61.  
  62.  
  63. /* CONSTANTES GLOBALES */
  64.  
  65.  const int POS_INI_X=1; //comienzo del mapa en x
  66.  const int POS_INI_Y=3; //comienzo del mapa en y
  67.  
  68.  const int PAREDES[12]={PVAI, PVER, ECSD, ECID, ECSI, ECII, TINV, TCOM, PVAD, PHZN, CRUZ, SPFN}; //todos los caracteres que no son caminables
  69.  
  70.  enum DIRECCIONES{QUIETO=0,ARR,IZQ,ABA,DER}; //las 4 posibles direcciones de movimiento
  71.  const int MAX_DIR=DER;
  72.  enum VELOCIDADES{        NORMAL=1,RAPIDO}; //las posibles velocidades (es valida la direccion QUIETO como velocidad 0)
  73.  const int MAX_VEL=RAPIDO;
  74.  
  75.  const char MOV_AR='w';
  76.  const char MOV_IZ='a';
  77.  const char MOV_AB='s';
  78.  const char MOV_DE='d';
  79.  const char SALIR='k';
  80.  const char PAUSA='p';
  81.  
  82.  enum  ERRORES{PSNF=0,FSNF,PANF,SPANF,MFDG,FMNE}; //los distintos codigos de error
  83.  
  84.  const int ANCHOMAPA=22; //1 espacio extra para el caracter de fin de cadena
  85.  const int ALTOMAPA=21;  //OjO, el mapa no debe tener mas de 20 de altura o no entra en la pantalla todo
  86.  
  87.  const int MAXFANTASMAS=4; //la maxima cantidad de fantasmas simultaneos //nota, no puede ser mayor a (MAX_FANT_COLOR-MIN_FANT_COLOR)
  88.  
  89.  const int MAX_VEL_FANT=NORMAL; //la maxima velocidad posible para los fantasmas
  90.  const int MIN_FANT_COLOR=GREEN; //el color mas bajo asignable a un fantasma
  91.  const int MAX_FANT_COLOR=DARKGRAY; //el color mas alto asignable a un fantasma
  92.  const int FANT_DOPA_COLOR=LIGHTBLUE+BLINK; //el color de los fantasmas cuando el paco esta dopado
  93.  
  94.  const int PACO_DEF_COLOR=YELLOW; //el color normal del paco
  95.  const int PACO_DOPA_COLOR=YELLOW; //el color dopado del paco
  96.  const int PACO_DEF_DIR=ARR; //direccion en la que comienza moviendoce el paco
  97.  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.
  98.  
  99.  const int COLOR_TEXTO=WHITE;
  100.  const int COLOR_MAPA=RED;
  101.  const int COLOR_PASTILLAS=YELLOW;
  102.  const int COLOR_PUNTAJE_OBT=CYAN;
  103.  
  104.  const int PUNTAJE_PASTILLA=1;
  105.  const int PUNTAJE_SUP_PAST=10;
  106.  const int PUNTAJE_FANTASMA=100;
  107.  
  108.  const int LAPSO_ENTRE_FANTASMAS=13; //el tiempo en segundos entre que sale un fatasma y el siguiente
  109.  const int DURACION_DOPA=30; //duracion de la superpastilla en segundos
  110.  const int DEF_VIDAS=1; //vidas con las que comienza la partida el jugador
  111.  const int HSFPS=75; //la cantidad de centesimas de segundo a esperar antes del siguiente cuadro
  112.  
  113.  const char CHARNULO=' ';
  114.  
  115. #ifdef CONWAKA //faa, fanatico de la performance :P
  116.  const int FREC_DOPADO=100;     //default:100
  117.  const int MIN_FREC_WAKA=300;   //default:300
  118.  const int MAX_FREC_WAKA=600;   //default:600
  119.  const int MIN_INTER_WAKA=600;  //default:600
  120.  const int MAX_INTER_WAKA=1200; //default:1200
  121.  int g_sonando=0; //es constante, pero ni ganas de hacer otro ifdef-endif
  122.  int g_suena_mueve=0; //para que solo suene si se esta moviendo el paco
  123. #endif
  124.  
  125. /* VARIABLES GLOBALES */
  126.  int g_puntaje=0;       //puntaje del jugador
  127.  int g_vidas=DEF_VIDAS; //vidas del jugador
  128.  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
  129.  int g_pastillas=0;     //la cantidad de pastillas que faltan comer
  130.  int g_super_pastillas=0;
  131.  int g_cant_fant=0; //la cantidad de fantasmas que hay dando vuelta
  132.  
  133.  int g_fin_del_juego=0; //cuando sea !=0 terminar  el juego
  134.  int g_dopado=0; //para saber si hay activa una superpastilla
  135.  
  136.  struct time g_t_com_dopa; //comienzo del dopaje
  137.  struct time g_t_com_juego; //comienzo del juego
  138.  
  139.  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
  140.  
  141.  char pastillas[ALTOMAPA][ANCHOMAPA];
  142.  char MAPA001[ALTOMAPA][ANCHOMAPA]={ //el mapa cargado, si bien no es constante me resulta comodo ponerlo en mayuscula
  143.            /**/" ",/**/       "ÉÍÍÍÍÍ»       ÉÍÍÍÍÍ»", //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
  144.                       "º21111ÈÍÍÍÍÍÍͼ11112º",
  145.                       "º1ÉÍ»11111111111ÉÍ»1º",
  146.                       "º1º ÈÍÍÍÍ»1ÉÍÍÍͼ º1º",
  147.                       "º1ÈËÍËÍÍͼ1ÈÍÍÍËÍ˼1º",
  148.                       "º11Èͼ111121111Èͼ11º",
  149.                       "È»11111ÉÍÍ~ÍÍ»11111ɼ",
  150.                       " ÈÍÍÍ»1ÈÍÍÍÍͼ1ÉÍÍͼ ",
  151.                       "   Éͼ111111111ÈÍ»   ",
  152.                       " Éͼ111ÉÍ»1ÉÍ»111ÈÍ» ",
  153.                       "ɼ111ÉÍÎ͹1ÌÍÎÍ»111È»",
  154.                       "º11Éͼ º º1º º ÈÍ»11º",
  155.                       "º1ɼ   º º1º º   È»1º",
  156.                       "º1ÌÍÍÍÍÊ͹1ÌÍÊÍÍÍ͹1º",
  157.                       "º1º      º1º      º1º",
  158.                       "º1º      º1º      º1º",
  159.                       "º1ÈÍ»  Éͼ1ÈÍ»  Éͼ1º",
  160.                       "º111ÈÍͼ1111ÈÍͼ111º",
  161.                       "ÈÍ»211111ÉÍ»111112Éͼ",
  162.                       "  ÈÍÍÍÍÍͼ ÈÍÍÍÍÍͼ  ",};
  163.  
  164.  
  165. /*PROTOTIPO DE FUNCIONES */
  166.  
  167. void muestra_titulo(); //limpia la pantalla y muestra el titulo del juego
  168. void muestra_mapa(); //imprime el mapa en pantalla
  169. void muestra_pastillas(); //actualiza las pastillas
  170. void muestra_puntaje_y_vidas(); //muestra las vidas y el puntaje del jugador denajo del mapa
  171. void muestra_instrucciones(); //muestra las teclas de manejo al fondo de la pantalla
  172. void muestra_ente(struct ente); //dibuja al ente que se le pasa en su posicion correspondiente y con su correspondiente color
  173.  
  174. struct ente buscar_ente(char);     //busca un cierto caracter en el mapa y lo devuelve como ente
  175. int buscar_spawn_paco(struct ente&); //busca el caracter de spawn del paco
  176. int buscar_spawn_fantasma(struct ente&); //busca el caracter de spawn de fantasmas
  177. 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
  178.  
  179. void crear_paco(struct ente &paco, struct ente spawn); //crea al ente paco en la posicion dada por su ente spawn
  180. void crear_fant(struct ente &fant, int&, struct ente spawn); //crea un ente fantasma arriba de la puerta o punto de spawn de fantasma
  181.  
  182. void recibir_input(struct ente&); //recibe input desde el teclado y lo interpreta
  183. void modif_dir_ente(int nuevadir,struct ente&); //modifica la direccion del ente dado
  184. 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"
  185. 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"
  186.  
  187. 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
  188.  
  189. void err(int); //maneja los errores del programa
  190.  
  191. /* MAIN */
  192.  
  193. int main()
  194. {
  195.  gettime(&g_t_com_juego);
  196.  /* CONSTANTES LOCALES DE MAIN*/
  197.  
  198.  /* VARIABLES LOCALES DE MAIN*/
  199.  
  200.  int i=0,j=0; //indices genericos
  201.  
  202. #ifdef CONWAKA //se, ya lime con esto, asi que la hago completa
  203.  int sonando; //para alternar el sonido producido..
  204. #endif
  205.  
  206.  struct ente punto_spawn_paco;
  207.  struct ente punto_spawn_fantasma;
  208.  struct ente paco;
  209.  struct ente fantasmas[MAXFANTASMAS];
  210.  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
  211.  
  212.  int ult_color_fant=MIN_FANT_COLOR; //el color asignado al ultimo fantasma que fue creado
  213.  int imprimir_puntaje=0;
  214.  
  215.  struct time t_com_bucle; //variable para buclear mientras que el usuario realice un input
  216.  struct time t_ultimo_fant; //cuando se cre¢ el ultimo fantasma
  217.  struct time t_aux;
  218.  //int t_hudif=0;
  219.  int t_sedif=0;
  220.  
  221.  /* INICIO DEL PROGRAMA */
  222.  
  223.  srand(time(0)); //inicializa el generador de numeros aleatorios
  224.  
  225.  muestra_titulo(); //muestra *PACOMAN vX.X*
  226.  if(buscar_spawn_paco(punto_spawn_paco))                 {err(PSNF);  return PSNF; }
  227.  if(buscar_spawn_fantasma(punto_spawn_fantasma))         {err(FSNF);  return FSNF; }
  228.  buscar_pastillas(); if(!g_pastillas)                    {err(PANF);  return PANF; }
  229.  if(MAXFANTASMAS > MAX_FANT_COLOR-MIN_FANT_COLOR)        {err(MFDG);  return MFDG; }
  230.  crear_paco(paco, punto_spawn_paco);
  231.  crear_fant(fantasmas[g_cant_fant],ult_color_fant,punto_spawn_fantasma);
  232.  gettime(&t_ultimo_fant);    /* creamos un fantasma si ya es hora */
  233.  do
  234.   {
  235.    gettime(&t_aux);
  236.    t_sedif=t_aux.ti_sec-g_t_com_dopa.ti_sec;
  237.    (t_sedif<0)?t_sedif=-t_sedif:1;
  238.    if(t_sedif>=DURACION_DOPA)
  239.     {
  240.      g_dopado=0;
  241.      g_killing_spree=0;
  242.     }
  243.    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"
  244.     {
  245.      gettime(&t_aux);
  246.      t_sedif=t_aux.ti_sec-t_ultimo_fant.ti_sec;
  247.      (t_sedif<0)?t_sedif=-t_sedif:1;
  248.      if(t_sedif>=LAPSO_ENTRE_FANTASMAS)
  249.       {
  250.        crear_fant(fantasmas[g_cant_fant],ult_color_fant,punto_spawn_fantasma);
  251.        gettime(&t_ultimo_fant);
  252.       }
  253.     }
  254.    muestra_titulo();
  255.    muestra_mapa();
  256.    muestra_pastillas();
  257.    muestra_ente(paco);
  258.    for (i=0;i<g_cant_fant;i++)
  259.     muestra_ente(fantasmas[i]);
  260.    muestra_puntaje_y_vidas();
  261.    muestra_instrucciones();
  262.    if(imprimir_puntaje)
  263.     {
  264.      textcolor(COLOR_PUNTAJE_OBT);
  265.      gotoxy(POS_INI_X+paco.y,POS_INI_Y+paco.x);
  266.      cprintf("%d!!",PUNTAJE_FANTASMA*g_killing_spree);
  267. #ifdef CONTWEET
  268.      printf("\a\a\a");
  269. #endif
  270.      textcolor(WHITE);
  271.      imprimir_puntaje=0;
  272.     }
  273.    gettime(&t_com_bucle);
  274.    // gotoxy(1,13); printf("\n%d %d",paco.x,paco.y); //que muestre la posicion para debuggear mas facil
  275.    do //bucle para input/espera a siguiente cuadro para no actualizar muchas veces por segundo que queda feo
  276.     {
  277. #ifdef CONWAKA
  278.      if (g_suena_mueve)
  279.       {
  280.        if(!g_dopado)
  281.     if(g_sonando>MIN_INTER_WAKA){sound(MIN_FREC_WAKA); g_sonando++; if(g_sonando>MAX_INTER_WAKA)g_sonando=0;}//wakawakawakawaka..
  282.      else{sound(MAX_FREC_WAKA); g_sonando++;}
  283.     else sound(FREC_DOPADO);
  284.       }
  285. #endif
  286.      recibir_input(paco);
  287.      gettime(&t_aux);
  288.      /*t_hudif=t_aux.ti_hund-t_com_bucle.ti_hund;
  289.      (t_hudif<0)?t_hudif=-t_hudif:1;*/
  290.      t_sedif=t_aux.ti_sec-t_com_bucle.ti_sec;
  291.      (t_sedif<0)?t_sedif=-t_sedif:1;
  292.     }while(/*t_hudif<HSFPS&&*/t_sedif<1);
  293.    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
  294.    for (i=0;i<g_cant_fant;i++)
  295.     {
  296.      mover_ente(fantasmas[i], paco);
  297.      if(g_color_fantasma_muerto!=-1) //elimina al fantasma muerto, muestra y suma puntaje y usa el intervalo de tiempo para crear otro fantasma
  298.       {
  299.        i=-1;
  300.        do
  301.     {
  302.      i++;
  303.     }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
  304.        if(fantasmas[i].color!=g_color_fantasma_muerto) {err(FMNE); return FMNE;} //porlas
  305.        for(j=i;j<g_cant_fant-1;j++) //mueve todos los fantasmas que estan despues del muerto para eliminarlo
  306.     {
  307.      fantasmas[j]=fantasmas[j+1];
  308.     }
  309.        g_cant_fant--;
  310.        fantasmas[g_cant_fant].color=WHITE; //simplemente un color ilegal para fantasmas, para que no quede tanta basura (paranoia?)
  311.        g_killing_spree++;
  312.        g_puntaje+=PUNTAJE_FANTASMA*g_killing_spree;
  313.        g_color_fantasma_muerto=-1;
  314.        gettime(&t_ultimo_fant);
  315.        imprimir_puntaje=1;
  316.       }
  317.     }
  318.   }while(!g_fin_del_juego);
  319.  
  320. #ifdef CONWAKA
  321.  nosound(); //detiene el wakawaka
  322. #endif
  323.  
  324. #ifdef CONMUSICAMUERTE
  325.  if(g_fin_del_juego==2)
  326.   {
  327.    for(i=500;i>100;i--)
  328.     {
  329.      sound(i);
  330.      delay(5);
  331.     }
  332.    nosound();
  333.    sound(700);
  334.    delay(300);
  335.    nosound();
  336.    sound(700);
  337.    delay(300);
  338.    nosound();
  339.   }
  340. #endif
  341.  
  342.  muestra_titulo();
  343.  muestra_mapa();
  344.  muestra_pastillas();
  345. // muestra_ente(paco);
  346.  for (i=0;i<g_cant_fant;i++)
  347.   muestra_ente(fantasmas[i]);
  348.  muestra_puntaje_y_vidas();
  349.  switch (g_fin_del_juego)
  350.   {
  351.    case 1: printf("\nGANASTE!!"); break;
  352.    case 2: printf("\nperdiste.. y bueh.."); break;
  353.    case 3: printf("\naah, cobarde, no lograste terminar la partida"); break;
  354.   }
  355.  
  356.  while(!kbhit());
  357.  return 0;
  358.  
  359.  /* FIN DEL PROGRAMA */
  360.  
  361. }
  362.  
  363. /* DEFINICION DE FUNCIONES  */
  364.  
  365. 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
  366. {
  367.  int cant=0, dir=0, ban=0;
  368.  char aux=CHARNULO;
  369.  if(pj.dir>QUIETO && pj.vel>QUIETO)
  370.   {
  371.    cant=valid_mov(pj, otto);
  372.    if (cant>0)
  373.    {
  374.     switch (pj.dir)
  375.      {
  376.       case ARR: pj.x-=cant; break;
  377.       case ABA: pj.x+=cant; break;
  378.       case IZQ: pj.y-=cant; break;
  379.       case DER: pj.y+=cant; break;
  380.      }
  381.    }
  382.   }
  383.  if(pj.q==(char)FANT)     /* controla el movimiento de los fanasmas.. tengo que pensar algo menos frutal.. quizas que sigan al paco.. nose..*/
  384.   {
  385.    switch (pj.dir)
  386.     {
  387.      case ARR: aux=MAPA001[pj.x-1][pj.y]; break;
  388.      case ABA: aux=MAPA001[pj.x+1][pj.y]; break;
  389.      case IZQ: aux=MAPA001[pj.x][pj.y-1]; break;
  390.      case DER: aux=MAPA001[pj.x][pj.y+1]; break;
  391.     }
  392.    if(cant<pj.vel || aux!=CHARNULO)
  393.     {
  394.      dir=pj.dir;
  395.      do
  396.       {
  397.        pj.dir=rand()%MAX_DIR +1;
  398.        switch (pj.dir)
  399.     {
  400.      case ARR: aux=MAPA001[pj.x-1][pj.y]; break;
  401.      case ABA: aux=MAPA001[pj.x+1][pj.y]; break;
  402.      case IZQ: aux=MAPA001[pj.x][pj.y-1]; break;
  403.      case DER: aux=MAPA001[pj.x][pj.y+1]; break;
  404.     }
  405.       }while(pj.dir==dir && aux!=CHARNULO);
  406.     }
  407.   }
  408. #ifdef CONWAKA
  409.  if(pj.q==(char)PACO)
  410.   if(cant>0)
  411.     g_suena_mueve=1;
  412.   else
  413.    {
  414.     nosound(); //solo debe sonar si se esta moviendo el paco
  415.     g_suena_mueve=0;
  416.    }
  417. #endif
  418.  return;
  419. }
  420.  
  421. 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
  422. {
  423.  char aux;
  424.  int i=0, cant=0, ban=0;
  425.  int x=pj.x, y=pj.y;
  426.  if(pj.q==(char)FANT && otto.q==(char)PACO)
  427.   if(x==otto.x && y==otto.y)
  428.    if(!g_dopado)
  429.     {
  430.      g_vidas--;
  431.      /* TERMINAR RONDA*/
  432.      if(g_vidas==0) g_fin_del_juego=2; //cuando lo termine posta (cuando implemente varias rondas) esto ya no iria aca
  433.      return 0; //si colisionaron ahi sin moverse devuelve cero
  434.     }
  435.    else
  436.     {
  437.      g_color_fantasma_muerto=pj.color;
  438.     }
  439.  do
  440.   {
  441.    i++;
  442.    switch (pj.dir)
  443.     {
  444.      case ARR: x=pj.x-i; break;
  445.      case ABA: x=pj.x+i; break;
  446.      case IZQ: y=pj.y-i; break;
  447.      case DER: y=pj.y+i; break;
  448.     }
  449.    aux=MAPA001[x][y];
  450.    if(aux!=CHARNULO)  //un ente solo puede caminar a traves de espacio vacio (o pastillas, pero est n en otra matriz)
  451.     ban=1;
  452.    else
  453.     {
  454.      cant=i;
  455.      if((pj.q==(char)PACO) && (pastillas[x][y]!=CHARNULO))
  456.       comer_pastilla(x,y);
  457.      if(pj.q==(char)FANT && otto.q==(char)PACO)
  458.       if(x==otto.x && y==otto.y)
  459.        if(!g_dopado)
  460.     {
  461.      g_vidas--;
  462.      /* To Do: TERMINAR RONDA*/
  463.      if(g_vidas==0) g_fin_del_juego=2; //cuando lo termine posta (cuando implemente varias rondas) esto ya no iria aca
  464.      return 0; //para que salga sin hacer nada mas
  465.     }
  466.        else
  467.     {
  468.      g_color_fantasma_muerto=pj.color;
  469.     }
  470.     }
  471.   }while(i<pj.vel && ban==0);
  472.  return (cant);
  473. }
  474.  
  475. void comer_pastilla(int x, int y) //se come una pastilla y hace lo que tenga que hacer
  476. {
  477.  switch (pastillas[x][y])
  478.   {
  479.    case (char)PAST: g_puntaje+=PUNTAJE_PASTILLA; g_pastillas--; break;
  480.    case (char)SPAS: g_puntaje+=PUNTAJE_SUP_PAST; g_super_pastillas--; gettime(&g_t_com_dopa); g_dopado=1; /* DOPAJE!! */ break;
  481.   }
  482.  pastillas[x][y]=CHARNULO;
  483.  if (g_pastillas==0 && g_super_pastillas==0) g_fin_del_juego=1;
  484.  return;
  485. }
  486.  
  487. void recibir_input(struct ente &paco) //verfica si se ha pulsado una tecla y realiza la accion que corresponda
  488. {
  489.  int tecla;
  490.  if(kbhit())
  491.   {
  492.    tecla=getch();
  493.    if (tecla==MOV_AR||tecla==MOV_IZ||tecla==MOV_AB||tecla==MOV_DE)
  494.     modif_dir_ente(tecla, paco);
  495.    else
  496.     if (tecla==PAUSA)
  497.      /*p*/;
  498.     else
  499.      if (tecla==SALIR)
  500.       g_fin_del_juego=3;
  501.   }
  502.  return;
  503. }
  504.  
  505. void modif_dir_ente(int nuevadir, struct ente &pj) //cambia la direccion del ente por la dada
  506. {
  507.  char aux=CHARNULO;
  508.  int dirant=pj.dir;
  509.  switch (nuevadir)
  510.   {
  511.    case MOV_AR: pj.dir=ARR; break;
  512.    case MOV_AB: pj.dir=ABA; break;
  513.    case MOV_IZ: pj.dir=IZQ; break;
  514.    case MOV_DE: pj.dir=DER; break;
  515.   }
  516.  switch (pj.dir)
  517.   {
  518.    case ARR: aux=MAPA001[pj.x-1][pj.y]; break;
  519.    case ABA: aux=MAPA001[pj.x+1][pj.y]; break;
  520.    case IZQ: aux=MAPA001[pj.x][pj.y-1]; break;
  521.    case DER: aux=MAPA001[pj.x][pj.y+1]; break;
  522.   }
  523.  if (aux!=CHARNULO) pj.dir=dirant;
  524.  return;
  525. }
  526.  
  527. struct ente buscar_ente(char coso) /* DEVUELVE UN ENTE CON EL CARACTER BUSCADO EN SU POSICION (soy malo con las descripciones..)*/
  528. {
  529.  struct ente esto;
  530.  int i=0, j=0;
  531.  for(i=0;i<ALTOMAPA;i++)
  532.   for(j=0;j<ANCHOMAPA;j++)
  533.    if(MAPA001[i][j]==coso)
  534.     {
  535.      esto.q=coso;
  536.      esto.x=i;
  537.      esto.y=j;
  538.      esto.dir=QUIETO;
  539.      esto.vel=esto.def_vel=QUIETO;
  540.      esto.dopa_color=esto.color=esto.def_color=WHITE;
  541.      return esto;
  542.     }
  543.  esto.q='0';
  544.  return esto;
  545. }
  546.  
  547. int buscar_spawn_paco(struct ente &paco) /* BUSCA EL PUNTO DE SPAWN DEL PACO */
  548. {
  549.  paco=buscar_ente((char)PACO);
  550.  if (paco.q=='0') return 1;
  551.   else
  552.    {
  553.     MAPA001[paco.x][paco.y]=CHARNULO; // quita el simbolo de spawn del mapa
  554.     return 0;
  555.    }
  556. }
  557.  
  558. int buscar_spawn_fantasma(struct ente &fant) /* BUSCA EL PUNTO DE SPAWN DE LOS FANTASMAS */
  559. {
  560.  fant=buscar_ente((char)SPFN);
  561.  if (fant.q=='0') return 1;
  562.   else return 0;
  563. }
  564.  
  565. void buscar_pastillas() /* BUSCA TODAS LAS PASTILLAS EN EL MAPA Y LAS CARGA */
  566. {
  567.  int i=0,j=0;
  568.  char aux=CHARNULO;
  569.  for(i=0;i<=ALTOMAPA;i++)
  570.   for(j=0;j<ANCHOMAPA;j++)
  571.    {
  572.     switch(MAPA001[i][j])
  573.      {
  574.       case '1': pastillas[i][j]=(char)PAST;
  575.         g_pastillas++;
  576.         MAPA001[i][j]=CHARNULO;
  577.            break;
  578.       case '2': pastillas[i][j]=(char)SPAS;
  579.         g_super_pastillas++;
  580.         MAPA001[i][j]=CHARNULO;
  581.            break;
  582.       default:  pastillas[i][j]=CHARNULO;
  583.            break;
  584.      }
  585.    }
  586.  return;
  587. }
  588.  
  589. void crear_fant(struct ente &fantasma, int& color, struct ente spawn) /*CREA E INICIALIZA A UN FANTASMA*/
  590. {
  591. char aux=MAPA001[spawn.x-1][spawn.y];
  592.  if (g_cant_fant<MAXFANTASMAS)
  593.   if(aux==CHARNULO)
  594.    {
  595.     fantasma.q=(char)FANT;
  596.     fantasma.x=spawn.x-1; //osea que lo crea una posicion arriba de el punto de spawn
  597.     fantasma.y=spawn.y;
  598.     fantasma.dir=rand()%4 +1; //sin el +1 podria dar 0, que es quieto
  599.     fantasma.vel=fantasma.def_vel=rand()%MAX_VEL_FANT +1; //sin el +1 podria dar 0, que es el quieto
  600.     color++;
  601.     fantasma.color=fantasma.def_color=color;
  602.     fantasma.dopa_color=FANT_DOPA_COLOR;
  603.     g_cant_fant++;
  604.    }
  605.   //else /*no se pudo crear el fantasma debido a que el espacio sobre el punto de spawn estaba ocupado */
  606.  //else /*no se pudo crear el fantasma debido a que ya se ha llegado al maximo de fantasmas*/
  607.  return;
  608. }
  609.  
  610. void crear_paco(struct ente &paco, struct ente spawn) /*CREA E INICIALIZA AL PACO*/
  611. {
  612.  paco.q=(char)PACO;
  613.  paco.x=spawn.x;
  614.  paco.y=spawn.y;
  615.  paco.dir=PACO_DEF_DIR;
  616.  paco.vel=paco.def_vel=PACO_DEF_VEL;
  617.  paco.color=paco.def_color=PACO_DEF_COLOR;
  618.  paco.dopa_color=PACO_DOPA_COLOR;
  619.  return;
  620. }
  621.  
  622.  
  623. void err(int horror)              /* MANEJA LOS ERROES DEL PROGRAMA */
  624. {
  625.  clrscr();
  626.  switch(horror)
  627.   {
  628.    case PSNF:  printf("\n\nERROR %d: no se encontro el punto de spawn del paco en el mapa",PSNF); break;
  629.    case FSNF:  printf("\n\nERROR %d: no se encontro el punto de spawn del fantasma en el mapa",FSNF); break;
  630.    case PANF:  printf("\n\nERROR %d: no se encontro ninguna pastilla en el mapa",PANF); break;
  631.    case SPANF: printf("\n\nERROR %d: no se encontro ninguna superpastilla en el mapa",SPANF); break;
  632.    case MFDG:  printf("\n\nERROR %d: el maximo de fantasmas existentes es mayor a la cantidad de colores posibles",MFDG); break;
  633.    case FMNE:  printf("\n\nERROR %d: sucedio fruta al tratar de matar un fantasma",FMNE); break;
  634.   }
  635.  getche();
  636.  return;
  637. }
  638.  
  639. void muestra_titulo()   /* LIMPIA LA PANTALLA Y MUESTRA EL TITULO */
  640. {
  641.  textbackground(BLACK);
  642.  textcolor(WHITE);
  643.  clrscr();
  644.  textbackground(BLUE);
  645.  textcolor(YELLOW);
  646.  //gotoxy(20,1); cprintf("*******************************");
  647.  gotoxy(22,2); cprintf("******                   ******");
  648.  //gotoxy(20,3); cprintf("*******************************");
  649.  textcolor(YELLOW + BLINK);
  650.  gotoxy(29,2); cprintf("PACOMAN %s",PACOVER);
  651.  gotoxy(POS_INI_X,POS_INI_Y);//deja el cursor en un lugar comodo para continuar con el juego
  652.  textbackground(BLACK); //deja el fondo estandar
  653.  textcolor(WHITE);      //deja la fuente estandar
  654.  return;
  655. }
  656.  
  657. void muestra_mapa()     /* MUESTRA EL MAPA EN PANTALLA */
  658. {
  659.  textcolor(COLOR_MAPA);
  660.  gotoxy(POS_INI_X,POS_INI_Y);
  661.  int i=0, j=0;
  662.  for(i=0;i<ALTOMAPA;i++)
  663.   {
  664.    for(j=0;j<ANCHOMAPA;j++)
  665.     {
  666.      cprintf("%c",MAPA001[i][j]);
  667.     }
  668.    printf("\n");
  669.   }
  670.  textcolor(WHITE);
  671.  return;
  672. }
  673.  
  674. void muestra_pastillas()     /* MUESTRA LAS PASTILLAS EN PANTALLA */
  675. {
  676.  textcolor(COLOR_PASTILLAS);
  677.  int i=0, j=0;
  678.  for(i=0;i<ALTOMAPA;i++)
  679.   {
  680.    for(j=0;j<ANCHOMAPA;j++)
  681.     {
  682.      if(pastillas[i][j]!=CHARNULO) //PORUQE ENTRA SI ES FALSO?!?!?
  683.       {
  684.        gotoxy(POS_INI_X+j,POS_INI_Y+i);
  685.        cprintf("%c",pastillas[i][j]);
  686.       }
  687.     }
  688.   }
  689.  textcolor(WHITE);
  690.  return;
  691. }
  692.  
  693. void muestra_puntaje_y_vidas()
  694. {
  695.  textcolor(COLOR_TEXTO);
  696.  gotoxy(POS_INI_X,POS_INI_Y+ALTOMAPA); //justo debajo del mapa
  697.  printf("PUNTAJE: %d\t\tVIDAS: %d", g_puntaje, g_vidas);
  698.  textcolor(WHITE);
  699.  return;
  700. }
  701.  
  702. void muestra_instrucciones()
  703. {
  704.  textcolor(COLOR_TEXTO);
  705.  gotoxy(POS_INI_X,POS_INI_Y+ALTOMAPA+1); //debajo del puntaje
  706.  cprintf("Movimiento: Arriba:\'%c\' Izquierda:'\%c' Abajo:\'%c\' Derecha\'%c\' Salir:\'%c\'", MOV_AR, MOV_IZ, MOV_AB, MOV_DE, SALIR/*, PAUSA*/);
  707.  textcolor(WHITE);
  708.  return;
  709. }
  710.  
  711. void muestra_ente(struct ente pj) /* MUESTRA AL ENTE DADO EN SU POSICION Y CON SU COLOR */
  712. {
  713.  if(g_dopado)
  714.   textcolor(pj.dopa_color);
  715.  else
  716.   textcolor(pj.color);           //el color adecuado para el ente
  717.  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
  718.  cprintf("%c",pj.q);
  719.  textcolor(WHITE); // para continuar tranquilo con el resto del programa
  720.  return;
  721. }
  722.  
  723.  
  724. /* Teh End */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement