Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*------------------------------------------------------------------------*/
- /*-----------------------------------PACOMAN------------------------------*/
- /*------------------------------------------------------------------------*/
- /*The following is a translation of a "Pacman clone" I made aout a year ago to see exatly what I remembered about C before I went on to teaching other people, the overall desing of the app can be snipped out of context as "hwy, what about if I made a pacman clone? I would need, hmhm.. a aloop in wich I draw stuff to the screen, then read input and move things around properly, I should be able to get something working by this afternoon", I actually said that a day at around 10am, of course, all that was there at that afternoon was an skeleton of the map, on the next day I had the pills placed around and a smily face that moved around responding to input, eating pills and respecting no boundaries. After 3 more days of constant key-stroking (and not much thinking) I had the current version of Pacoman -wich I never ever think of upgrading, well, maybe I'll rewrite it on C# with a better design someday, and perhaps it'll have nice graphics and will run at more than 1 FPS-. Btw, sorry if my translation sucks, it will hopefully not be worse than the code itself, tho.*/
- #include <string.h>
- #include <conio.h>
- #include <stdio.h>
- #include <dos.h>
- #include <stdlib.h>
- /* SIMBOLIC CONSTANTS */
- /* VERSION */
- #define PACOVER "v0.5a"
- #define COMPATIVERSION 'a' //a:casa //b:notebook hp //->needed this to proper display some ascii chars in some computers, mode a is the way to go on most comps
- /* SOUND */
- //#define CONWAKA 1 //pacoman will make *wakawakawaka* when moving if uncommented -sounds really bad-
- //#define CONTWEET 1 //make a *tweet* when a ghost is eaten?
- //#define CONMUSICAMUERTE //really, doesn't sound right either
- /* MAP SIMBOLS */ //This ones are needed because, well, they really aren't needed, but they made my life easy at the moment.
- #define PVAI 185 //¹:185 vertical wall open to the left
- #define PVER 186 //º:186 vertical wall
- #define ECSD 187 //»:187 upper right closed corner
- #define ECID 188 //¼:188 lower right closed corner
- #define ECSI 201 //É:201 upper left closed corner
- #define ECII 200 //È:200 lower left closed corner
- #define TINV 202 //Ê:202 inverted open T
- #define TCOM 203 //Ë:203 open T
- #define PVAD 204 //Ì:204 vertical wall open to the right
- #define PHZN 205 //Í:205 horizontal wall
- #define CRUZ 206 //Î:206 + (open cross)
- #define SPFN 126 //~:126 spawn ghost <-requires an empty space above //counts as a wall //there can only be one per map
- #define PACO 2 //:2 paco /spawn paco //there can only be one per map
- #if COMPATIVERSION=='a' //if we are on the compatibility mode for my home pc we'll define this simbols like this
- #define PAST 250 //ú:250 pill
- #define SPAS 155 //›:155 super pill
- #define FANT 169 //©:169 ghost
- #elif COMPATIVERSION=='b' //if we are on 'that place' notebook's mode instead
- #define PAST 249 //ù:249 pill
- #define SPAS 236 //ì:236 super pill
- #define FANT 234 //ê:234 ghost
- #endif
- /* DATA STRUCTURES */
- struct ente{
- char q; //it's symbol
- int x; //x coordinate
- int y; //y coordinate
- int dir; //direction of movement //0 does not move
- int vel; //current moving speed //0 does not move
- int def_vel; //default moving speed
- int dopa_vel; //speed when doped //I'll often use the words "doped", or "highed" for when the pacoman is under the effects of the super pill, beware
- int def_color; //normal color
- int color; //current color
- int dopa_color; //doped color
- };
- /* OTHER GLOBAL CONSTs */
- const int POS_INI_X=1; //start of the map on the screen
- const int POS_INI_Y=3;
- const int PAREDES[12]={PVAI, PVER, ECSD, ECID, ECSI, ECII, TINV, TCOM, PVAD, PHZN, CRUZ, SPFN}; //all the symbols that cannot be walked thru
- enum DIRECCIONES{QUIETO=0,ARR,IZQ,ABA,DER}; //the 4 possible directions of movement
- const int MAX_DIR=DER;
- enum VELOCIDADES{ NORMAL=1,RAPIDO}; //the different speeds, 'STILL' direction can be used as speed or making the entity stop
- const int MAX_VEL=RAPIDO;
- const char MOV_AR='w'; //command key for moving UP
- const char MOV_IZ='a'; //left
- const char MOV_AB='s'; //down
- const char MOV_DE='d'; //right
- const char SALIR='k'; //exit
- const char PAUSA='p'; //pause
- enum ERRORES{PSNF=0,FSNF,PANF,SPANF,MFDG,FMNE}; //error codes
- const int ANCHOMAPA=22; //map's width, with 1 extra space for placing the '\0' and printing it like a string for easy of use
- const int ALTOMAPA=21; //map's height, cannot be larger than 20 or it won't fit on the screen
- const int MAXFANTASMAS=4; //max amount of simultaneous ghosts //note, should not be higher than (MAX_FANT_COLOR-MIN_FANT_COLOR)
- const int MAX_VEL_FANT=NORMAL; //ghost's max possible speed
- const int MIN_FANT_COLOR=GREEN; //lowest color asignable to a ghost
- const int MAX_FANT_COLOR=DARKGRAY; //highest color asignable to a ghost
- const int FANT_DOPA_COLOR=LIGHTBLUE+BLINK; //ghosts color when paco is doped
- const int PACO_DEF_COLOR=YELLOW; //paco's normal color
- const int PACO_DOPA_COLOR=YELLOW; //paco's highed color
- const int PACO_DEF_DIR=ARR; //direction of movement at the start of the game
- const int PACO_DEF_VEL=NORMAL; //paco's default speed //note: given the lazyness of the code, the paco should not be assigned a higher speed than 1, or there will be collission problems, the ghosts on the other hand can move as fast as one want them to
- 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; //score given by eating a pill, super pill, and ghost
- const int PUNTAJE_SUP_PAST=10;
- const int PUNTAJE_FANTASMA=100;
- const int LAPSO_ENTRE_FANTASMAS=13; //time in seconds between a ghost spawn and the next
- const int DURACION_DOPA=30; //duration of the superpill's effect
- const int DEF_VIDAS=1; //player starting lifes
- const int HSFPS=75; //amount of cents of seconds to wait until next frame, given a bug in my time calculation system, this is never used and instead the game runs at a solid 1 FPS
- const char CHARNULO=' ';
- #ifdef CONWAKA //constants used only for creating the *wakawaka* effect
- 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;
- int g_suena_mueve=0; //so the sound only is heard when the paco is moving
- #endif
- /* GLOBAL VARs */
- int g_puntaje=0; //player's score
- int g_vidas=DEF_VIDAS; //player's lifes
- int g_killing_spree=0; //stacked bonus per ghost eaten in a continuous doping session
- int g_pastillas=0; //amount of pills left to eat
- int g_super_pastillas=0;
- int g_cant_fant=0; //amount of ghosts swirming around
- int g_fin_del_juego=0; //when it's !=0 the game is over
- int g_dopado=0; //to check and see if there's an active superpill
- struct time g_t_com_dopa; //start of dopage time
- struct time g_t_com_juego; //start of game time
- int g_color_fantasma_muerto=-1; //to see wich was the last ghost to have died, I think, I didn't comments this right the first time around //this only works because there can't be 2 ghosts of the same color
- char pastillas[ALTOMAPA][ANCHOMAPA];
- char MAPA001[ALTOMAPA][ANCHOMAPA]={ //the map loaded, I could've deined it as a const and then have diferent arrays ofr holding different stuff, but IDK WTF I was thinking ATM
- /**/" ",/**/ "ÉÍÍÍÍÍ» ÉÍÍÍÍÍ»", //NOTE, the extra line is added because a bizare bug would happen otherwise
- "º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Éͼ",
- " ÈÍÍÍÍÍͼ ÈÍÍÍÍÍͼ ",};
- /* FUNCTIONS PROTOTIPES */
- void muestra_titulo(); //clears the screen and shows the game title
- void muestra_mapa(); //prints the map on the screen
- void muestra_pastillas(); //updates the pills
- void muestra_puntaje_y_vidas(); //shows life and score of the player
- void muestra_instrucciones(); //shows command keys at the bottom of the screen
- void muestra_ente(struct ente); //draws a given entity at it's given place and color
- struct ente buscar_ente(char); //searches the map for a certain symbol and returns it as an entity
- int buscar_spawn_paco(struct ente&); //searches the character for spawning the paco
- int buscar_spawn_fantasma(struct ente&); //searches the character for spawning the ghosts
- void buscar_pastillas(); //searches the map for all the pills, counts and stores them in an array with the proper symbol depending on the compatibility version selected
- void crear_paco(struct ente &paco, struct ente spawn); //creates the paco entity at the position given by it's spawn place
- void crear_fant(struct ente &fant, int&, struct ente spawn); //creates a ghost right above the ghost's spawn point
- void recibir_input(struct ente&); //gets and interpretes keyboard input
- void modif_dir_ente(int nuevadir,struct ente&); //changes the direction of a given entity
- void mover_ente(struct ente&,struct ente otto); //moves an entity on it's given direction and speed (if possible) /note: hitting a wall terminates movement until the next frame //checks for collissions with the entity "otto" //note: I call it "otto" since I've already used "aux" for something else in other function, and I "dummy" as a generic empty entity, so I'm using this sort of naming convention of calling "otto" my generic auxiliar entity.
- int valid_mov(struct ente, struct ente otto); //verifies that it's valid to move the entity /returns the amount of spaces the entity can move in the given direction at the current speed //checks for collisions with entity "otto"
- void comer_pastilla(int x, int y); //eats a pill, doing everything that it may require //note: spanish comment was longer, but cut me some slack will ya?
- void err(int); //handles errors
- /* MAIN */
- int main()
- {
- gettime(&g_t_com_juego);
- /* MAIN LOCAL CONSTs*/
- /* MAIN LOCAL VARs*/
- int i=0,j=0; //generic indexes
- #ifdef CONWAKA //if we are using the *waka* sound system..
- int sonando;
- #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; //check movement function for specifics on usage, mainly validation of movement and collissions
- int ult_color_fant=MIN_FANT_COLOR; //color assigned to last created ghost
- int imprimir_puntaje=0;
- struct time t_com_bucle; //variable for looping waiting for user input
- struct time t_ultimo_fant; //when the last ghost was created
- struct time t_aux;
- //int t_hudif=0;
- int t_sedif=0;
- /* PROGRAM START */
- srand(time(0)); //initializes random number generator
- muestra_titulo(); //displays *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); /* creates a ghost if it's time */
- 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) //ghosts are only created if max ghost amount hasn't been reached, and if the paco is not doped. Non-scared ghosts while paco is doped are not supported.
- {
- 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); //shows paco's position on map for easier debugging
- do //input-wating loop
- {
- #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; //broken code that attempted to make the game run faster than 1 FPS
- (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); //I pass dummy because I have nothing to pass, the collissions between the paco and the ghosts are calculated when the ghosts attempt to move. //HOLY SHIT IT JUST HIT ME: it appears I had never heard of optional parameters. Or! I maybe had tried them, but the goat-blowing compiler I was using didn't suport optionals -as it didn't support many other things :/ -
- for (i=0;i<g_cant_fant;i++)
- {
- mover_ente(fantasmas[i], paco);
- if(g_color_fantasma_muerto!=-1) //deletes dead ghost, adds score and uses time to spawn a new ghost
- {
- i=-1;
- do
- {
- i++;
- }while(fantasmas[i].color!=g_color_fantasma_muerto /*&& i<g_cant_fant*/); //broken code for forgotten reason
- if(fantasmas[i].color!=g_color_fantasma_muerto) {err(FMNE); return FMNE;} //just in case?
- for(j=i;j<g_cant_fant-1;j++) //moves all the ghosts that come after the dead one
- {
- fantasmas[j]=fantasmas[j+1];
- }
- g_cant_fant--;
- fantasmas[g_cant_fant].color=WHITE; //an ilegal ghost code, just in case some trash was let behind (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(); //stops the 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); //no longer called here
- 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;
- /* END OF PROGRAM */
- }
- /* FUNCTIONS */
- /* MOVE ENTITY */ //moves the given entity on the proper direction and with the proper speed as much as possible. Also controls the movement of ghosts, the *wakawaka* and posibly something else. //note: this function definately got too large
- void mover_ente(struct ente &pj, struct ente otto)
- {
- 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) /* controls the movement of ghosts, or makes them move stupidly, better said*/
- {
- 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(); //should only sound if the paco is on the move
- g_suena_mueve=0;
- }
- #endif
- return;
- }
- /* VALIDATE MOVEMENT */ //returns how many squares can the entity move, clculates collissions if neccessary. /note: now this function is a bit of a monster too
- int valid_mov(struct ente pj, struct ente otto)
- {
- 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; //if I ever upgrade this thing (implementing several rounds and lifes) this shouldn't go here anymore
- return 0; //if the collission happens without any movement done, return zero
- }
- 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) //an entity can only walk trhu empty space (or pills, but those are in another matrix)
- 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: END ROUND*/
- if(g_vidas==0) g_fin_del_juego=2; //if I ever upgrade this thing (implementing several rounds and lifes) this shouldn't go here anymore
- return 0; //just get out without doing any further
- }
- else
- {
- g_color_fantasma_muerto=pj.color;
- }
- }
- }while(i<pj.vel && ban==0);
- return (cant);
- }
- /* EAT PILL */ //eats a pill and does whatever should be done
- void comer_pastilla(int x, int y)
- {
- 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;
- }
- /* TAKE INPUT */ //checks to see if a key has been pressed and does what it should in response
- void recibir_input(struct ente &paco)
- {
- 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)
- /*to do..*/;
- else
- if (tecla==SALIR)
- g_fin_del_juego=3;
- }
- return;
- }
- /* CHANGE DIRECTION */ //changes the entity's direction by the given one
- void modif_dir_ente(int nuevadir, struct ente &pj)
- {
- 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;
- } //I didn't notice this uneccessary double-switch until now, but I won't change it, as I promised
- /* SEEK ENTITY */ //returns an entity with the symbol searched on its position (this sounded equally bad in spanish, probably wrote it at 4am or something)
- struct ente buscar_ente(char coso)
- {
- 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;
- }
- /* SEARCH SPAWN PACO */ //searches for the spawn point of the pacoman
- int buscar_spawn_paco(struct ente &paco)
- {
- paco=buscar_ente((char)PACO);
- if (paco.q=='0') return 1;
- else
- {
- MAPA001[paco.x][paco.y]=CHARNULO; // removes the symbol from the map
- return 0;
- }
- }
- /* SEARCH SPAWN GHOST */ //searches for the spawn point of the ghosts
- int buscar_spawn_fantasma(struct ente &fant)
- {
- fant=buscar_ente((char)SPFN);
- if (fant.q=='0') return 1;
- else return 0;
- }
- /* SEEK PILLS */ //searches for all the pills and loads them up
- void buscar_pastillas()
- {
- 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;
- }
- /* CREATE GHOST */ //creates and initializes a ghost entity
- void crear_fant(struct ente &fantasma, int& color, struct ente spawn)
- {
- 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; //creates it in the position above the spawn point
- fantasma.y=spawn.y;
- fantasma.dir=rand()%4 +1; //without the +1 it could be 0, meaning it'll just stand still
- fantasma.vel=fantasma.def_vel=rand()%MAX_VEL_FANT +1; //again, the +1
- color++;
- fantasma.color=fantasma.def_color=color;
- fantasma.dopa_color=FANT_DOPA_COLOR;
- g_cant_fant++;
- }
- //else /* ghost could not be created due to lack of space above */
- //else /*ghost could not be created since the max ghosts amount has be reached */
- return;
- }
- /* CREATE PACO */ //creates and initializes the paco
- void crear_paco(struct ente &paco, struct ente spawn)
- {
- 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;
- }
- /* ERR */ //handles program erors
- void err(int horror)
- {
- clrscr();
- switch(horror)
- {
- case PSNF: printf("\n\nERROR %d: no se encontro el punto de spawn del paco en el mapa",PSNF); break; //paco spawn point missing on map
- case FSNF: printf("\n\nERROR %d: no se encontro el punto de spawn del fantasma en el mapa",FSNF); break; //ghost spawn point missing on map
- case PANF: printf("\n\nERROR %d: no se encontro ninguna pastilla en el mapa",PANF); break; //no pill found on map
- case SPANF: printf("\n\nERROR %d: no se encontro ninguna superpastilla en el mapa",SPANF); break; //no superpill found on map //not really an error?
- case MFDG: printf("\n\nERROR %d: el maximo de fantasmas existentes es mayor a la cantidad de colores posibles",MFDG); break; //max possible amount of ghosts higher than color range
- case FMNE: printf("\n\nERROR %d: sucedio fruta al tratar de matar un fantasma",FMNE); break; //something bad happened when attempting to create a ghost
- }
- getche();
- return;
- }
- /*Note on graphic functions: yeah, this is almost as unefficient as possible, run it fullscreen in an not neccessariously old comp and you will wan't to kill yourself rather than play*/
- /* SHOW TITLE */ //clears screen and shows game title
- void muestra_titulo()
- {
- textbackground(BLACK);
- textcolor(WHITE);
- clrscr();
- textbackground(BLUE);
- textcolor(YELLOW);
- //gotoxy(20,1); cprintf("*******************************"); //commented to make title thinner
- gotoxy(22,2); cprintf("****** ******");
- //gotoxy(20,3); cprintf("*******************************"); //commented to make title thinner
- textcolor(YELLOW + BLINK);
- gotoxy(29,2); cprintf("PACOMAN %s",PACOVER);
- gotoxy(POS_INI_X,POS_INI_Y);//leaves the cursor on a convenient place to keep on with the program
- textbackground(BLACK); //resets background color
- textcolor(WHITE); //resets font color
- return;
- }
- /* SHOW MAP */ //displays the map on the screen
- void muestra_mapa()
- {
- 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;
- }
- /* SHOW PILLS */
- void muestra_pastillas()
- {
- 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) //at some point the program seemed to enter this 'if' even when the condition was alse, IDK if I ever fixed that -run it and tell me?-
- {
- gotoxy(POS_INI_X+j,POS_INI_Y+i);
- cprintf("%c",pastillas[i][j]);
- }
- }
- }
- textcolor(WHITE);
- return;
- }
- /* SHOW SCORE AND LIFES */
- void muestra_puntaje_y_vidas()
- {
- textcolor(COLOR_TEXTO);
- gotoxy(POS_INI_X,POS_INI_Y+ALTOMAPA); //right below the map
- printf("PUNTAJE: %d\t\tVIDAS: %d", g_puntaje, g_vidas);
- textcolor(WHITE);
- return;
- }
- /* SHOW INSTRUCTIONS */ //better name would be "show keys" or "show commands" :/
- void muestra_instrucciones()
- {
- textcolor(COLOR_TEXTO);
- gotoxy(POS_INI_X,POS_INI_Y+ALTOMAPA+1); //right below the score
- cprintf("Movimiento: Arriba:\'%c\' Izquierda:'\%c' Abajo:\'%c\' Derecha\'%c\' Salir:\'%c\'", MOV_AR, MOV_IZ, MOV_AB, MOV_DE, SALIR/*, PAUSA*/); //pause doesn't do anything yet, so why display the key?
- textcolor(WHITE);
- return;
- }
- /* SHOW ENTITY */ //shows a given entity on it's position and with it's color
- void muestra_ente(struct ente pj)
- {
- if(g_dopado)
- textcolor(pj.dopa_color);
- else
- textcolor(pj.color); //set the right color
- gotoxy(POS_INI_X+pj.y,POS_INI_Y+pj.x); //show in the right position
- cprintf("%c",pj.q);
- textcolor(WHITE); // set back to default so nothing funky happens later
- return;
- }
- /* Teh End */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement