void fantasma::dibujar_fantasma() const{ if (pillTimer < 0){ setCColor(color[col]); } else{ setCColor(color[6]); } gotoxy(_x, _y); printf("%c", 6); }
void duree(){ setCColor(color[1]); gotoxy(5,4); printf(" SCORE : "); gotoxy(5,6); printf(" "); setCColor(color[1]); gotoxy(5,6); printf("%ld",points); setCColor(color[1]); gotoxy(5,25); printf(" VIE :"); for(int i = 0 ; i <= vie ; i++){ gotoxy(5,i+27); printf(" "); } }
void marcador(){ gotoxy(5, 4); printf("PUNTOS"); gotoxy(5, 6); printf(" "); setCColor(color[6]); gotoxy(5, 6); printf("%ld", puntos); if (pillTimer > 0){ gotoxy(5, 10); printf("PODER"); gotoxy(5, 11); if (pillTimer > 9){ printf("%d", pillTimer); } else{ printf("%d ", pillTimer); } } else if (pillTimer == 0){ pillPosition = newPillPosition(); pillTimer = -1; } else{ gotoxy(5, 10); printf(" "); gotoxy(5, 11); printf(" "); } setCColor(color[1]); gotoxy(5, 25); printf("VIDAS"); for (int i = 0; i <= vidas; i++){ gotoxy(5, i + 27); printf(" "); } for (int i = 0; i < vidas; i++){ gotoxy(5, i + 27); printf("%c", 2); } setCColor(color[2]); gotoxy(70, 27); printf("%c", 169); }
void pint_map()//Fonction qui peint le bord de l'écran de jeux { for(int i = 0 ; i < 78 ; i++){ for(int j = 0 ; j < 30 ; j++){ gotoxy(i,j); if(map[j][i] == 'X') {setCColor(color[0]);printf("%c",205);} if(map[j][i] == '_') {setCColor(color[7]); printf("%c",4);} else if(map[j][i] == 'Y') {setCColor(color[0]);printf("%c",186);} else if(map[j][i] == 'A') {setCColor(color[0]);printf("%c",201);} else if(map[j][i] == 'B') {setCColor(color[0]);printf("%c",187);} else if(map[j][i] == 'C') {setCColor(color[0]);printf("%c",188);} else if(map[j][i] == 'D') {setCColor(color[0]);printf("%c",200);} } } }
void pintar_mapa()// Funcion que pinta el borde de la pantalla de juego { for (int i = 0; i < 78; i++){ for (int j = 0; j < 30; j++){ gotoxy(i, j); if (mapa[j][i] == 'X') { setCColor(color[0]); printf("%c", 205); } if (mapa[j][i] == '_') { setCColor(color[1]); printf("%c", 250); } else if (mapa[j][i] == 'Y') { setCColor(color[0]); printf("%c", 186); } else if (mapa[j][i] == 'A') { setCColor(color[0]); printf("%c", 201); } else if (mapa[j][i] == 'B') { setCColor(color[0]); printf("%c", 187); } else if (mapa[j][i] == 'C') { setCColor(color[0]); printf("%c", 188); } else if (mapa[j][i] == 'D') { setCColor(color[0]); printf("%c", 200); } } } }
void fontome::move_fontome(){ supp_fontome(); choc_pacman(); int bolx=_x,boly=_y; if(map[_y][_x] == '|'){ fdir = rand()%4; } if(map[_y][_x] == '*'){ fdir = 0; } if(fdir == 2){ if(map[_y][_x+1] != 'X' && map[_y][_x+1] != 'A' && map[_y][_x+1] != 'Y' && map[_y][_x+1] != 'B' && map[_y][_x+1] != 'C' && map[_y][_x+1] != 'D') _x++; else fdir = rand()%4; } if(fdir == 3){ if(map[_y][_x-1] != 'X' && map[_y][_x-1] != 'A' && map[_y][_x-1] != 'Y' && map[_y][_x-1] != 'B' && map[_y][_x-1] != 'C' && map[_y][_x-1] != 'D') _x--; else fdir = rand()%4; } if(fdir == 0){ if(map[_y-1][_x] != 'X' && map[_y-1][_x] != 'A' && map[_y-1][_x] != 'Y' && map[_y-1][_x] != 'B' && map[_y-1][_x] != 'C' && map[_y-1][_x] != 'D') _y--; else fdir = rand()%4; } if(fdir == 1){ if(map[_y+1][_x] != 'X' && map[_y+1][_x] != 'A' && map[_y+1][_x] != 'Y' && map[_y+1][_x] != 'B' && map[_y+1][_x] != 'C' && map[_y+1][_x] != 'D') _y++; else fdir = rand()%4; } if(map[boly][bolx] == '_') {setCColor(color[7]); gotoxy(bolx,boly);printf("%c",3);} // rutina atajo if(_x <= 17) _x = 61; else if(_x >= 62) _x = 18; dessin_fontome(); }
void fontome::dessin_fontome() const{ setCColor(color[col]); gotoxy(_x,_y); printf("%c",1); }
void fantasma::mover_fantasma(){ borrar_fantasma(); choque_pacman(); float nearerDistance = calculateDistance(Point2D(_x*1.0, _y*1.0), Point2D(x*1.0, y*1.0)); float newDistance = nearerDistance; float fuzzyRate = fuzzyReaction(nearerDistance); //printf("%f", fuzzyRate); int bolx = _x, boly = _y; if (mapa[_y][_x] == '|'){ fdir = rand() % 4; } if (mapa[_y][_x] == '*'){ fdir = 0; } // fuzzy Bonus if ((fuzzyRate > .50 && fuzzyRate <= 1.0) || (fuzzyRate > .25 && rand() % 10 == 3)){ for (int i = 0; i < 4; i++){ if (i == 2){ newDistance = calculateDistance(Point2D((_x+1)*1.0, _y*1.0), Point2D(x*1.0, y*1.0)); if(mapa[_y][_x + 1] != 'X' && mapa[_y][_x + 1] != 'A' && mapa[_y][_x + 1] != 'Y' && mapa[_y][_x + 1] != 'B' && mapa[_y][_x + 1] != 'C' && mapa[_y][_x + 1] != 'D'){ if (pillTimer < 0 && newDistance < nearerDistance){ fdir = i; } else if (pillTimer >= 0 && newDistance > nearerDistance){ fdir = i; } } } if (i == 3){ newDistance = calculateDistance(Point2D((_x - 1)*1.0, _y*1.0), Point2D(x*1.0, y*1.0)); if (mapa[_y][_x - 1] != 'X' && mapa[_y][_x - 1] != 'A' && mapa[_y][_x - 1] != 'Y' && mapa[_y][_x - 1] != 'B' && mapa[_y][_x - 1] != 'C' && mapa[_y][_x - 1] != 'D'){ if (pillTimer < 0 && newDistance < nearerDistance){ fdir = i; } else if (pillTimer >= 0 && newDistance > nearerDistance){ fdir = i; } } } if (i == 0){ newDistance = calculateDistance(Point2D(_x*1.0, (_y-1)*1.0), Point2D(x*1.0, y*1.0)); if (mapa[_y - 1][_x] != 'X' && mapa[_y - 1][_x] != 'A' && mapa[_y - 1][_x] != 'Y' && mapa[_y - 1][_x] != 'B' && mapa[_y - 1][_x] != 'C' && mapa[_y - 1][_x] != 'D'){ if (pillTimer < 0 && newDistance < nearerDistance){ fdir = i; } else if (pillTimer >= 0 && newDistance > nearerDistance){ fdir = i; } } } if (i == 1){ newDistance = calculateDistance(Point2D(_x*1.0, (_y + 1)*1.0), Point2D(x*1.0, y*1.0)); if (mapa[_y + 1][_x] != 'X' && mapa[_y + 1][_x] != 'A' && mapa[_y + 1][_x] != 'Y' && mapa[_y + 1][_x] != 'B' && mapa[_y + 1][_x] != 'C' && mapa[_y + 1][_x] != 'D'){ if (pillTimer < 0 && newDistance < nearerDistance){ fdir = i; } else if (pillTimer >= 0 && newDistance > nearerDistance){ fdir = i; } } } } } if (fdir == 2){ if (mapa[_y][_x + 1] != 'X' && mapa[_y][_x + 1] != 'A' && mapa[_y][_x + 1] != 'Y' && mapa[_y][_x + 1] != 'B' && mapa[_y][_x + 1] != 'C' && mapa[_y][_x + 1] != 'D') _x++; else fdir = rand() % 4; } if (fdir == 3){ newDistance = calculateDistance(Point2D((_x - 1)*1.0, _y*1.0), Point2D(x*1.0, y*1.0)); if (mapa[_y][_x - 1] != 'X' && mapa[_y][_x - 1] != 'A' && mapa[_y][_x - 1] != 'Y' && mapa[_y][_x - 1] != 'B' && mapa[_y][_x - 1] != 'C' && mapa[_y][_x - 1] != 'D') _x--; else fdir = rand() % 4; } if (fdir == 0){ if (mapa[_y - 1][_x] != 'X' && mapa[_y - 1][_x] != 'A' && mapa[_y - 1][_x] != 'Y' && mapa[_y - 1][_x] != 'B' && mapa[_y - 1][_x] != 'C' && mapa[_y - 1][_x] != 'D') _y--; else fdir = rand() % 4; } if (fdir == 1){ if (mapa[_y + 1][_x] != 'X' && mapa[_y + 1][_x] != 'A' && mapa[_y + 1][_x] != 'Y' && mapa[_y + 1][_x] != 'B' && mapa[_y + 1][_x] != 'C' && mapa[_y + 1][_x] != 'D') _y++; else fdir = rand() % 4; } if (fuzzyRate < .50 || (rand() % 10 == 3 && fuzzyRate <= .75)){ if (fuzzyRate >.50 || (fuzzyRate > .25 && rand() % 10 == 3)){ for (int i = 0; i < 4; i++){ if (i == 2){ newDistance = calculateDistance(Point2D((_x + 1)*1.0, _y*1.0), Point2D(x*1.0, y*1.0)); if (mapa[_y][_x + 1] != 'X' && mapa[_y][_x + 1] != 'A' && mapa[_y][_x + 1] != 'Y' && mapa[_y][_x + 1] != 'B' && mapa[_y][_x + 1] != 'C' && mapa[_y][_x + 1] != 'D'){ if (pillTimer < 0 && newDistance < nearerDistance){ fdir = i; } else if (pillTimer > 0 && newDistance > nearerDistance){ fdir = i; } } else{ fdir = rand() % 4; } } if (i == 3){ newDistance = calculateDistance(Point2D((_x - 1)*1.0, _y*1.0), Point2D(x*1.0, y*1.0)); if (mapa[_y][_x - 1] != 'X' && mapa[_y][_x - 1] != 'A' && mapa[_y][_x - 1] != 'Y' && mapa[_y][_x - 1] != 'B' && mapa[_y][_x - 1] != 'C' && mapa[_y][_x - 1] != 'D'){ if (pillTimer < 0 && newDistance < nearerDistance){ fdir = i; } else if (pillTimer >= 0 && newDistance > nearerDistance){ fdir = i; } } else{ fdir = rand() % 4; } } if (i == 0){ newDistance = calculateDistance(Point2D(_x*1.0, (_y - 1)*1.0), Point2D(x*1.0, y*1.0)); if (mapa[_y - 1][_x] != 'X' && mapa[_y - 1][_x] != 'A' && mapa[_y - 1][_x] != 'Y' && mapa[_y - 1][_x] != 'B' && mapa[_y - 1][_x] != 'C' && mapa[_y - 1][_x] != 'D'){ if (pillTimer < 0 && newDistance < nearerDistance){ fdir = i; } else if (pillTimer >= 0 && newDistance > nearerDistance){ fdir = i; } } else{ fdir = rand() % 4; } } if (i == 1){ newDistance = calculateDistance(Point2D(_x*1.0, (_y + 1)*1.0), Point2D(x*1.0, y*1.0)); if (mapa[_y + 1][_x] != 'X' && mapa[_y + 1][_x] != 'A' && mapa[_y + 1][_x] != 'Y' && mapa[_y + 1][_x] != 'B' && mapa[_y + 1][_x] != 'C' && mapa[_y + 1][_x] != 'D') { if (pillTimer < 0 && newDistance < nearerDistance){ fdir = i; } else if (pillTimer >= 0 && newDistance > nearerDistance){ fdir = i; } } } } if (fdir == 2){ if (mapa[_y][_x + 1] != 'X' && mapa[_y][_x + 1] != 'A' && mapa[_y][_x + 1] != 'Y' && mapa[_y][_x + 1] != 'B' && mapa[_y][_x + 1] != 'C' && mapa[_y][_x + 1] != 'D') _x++; else fdir = rand() % 4; } if (fdir == 3){ if (mapa[_y][_x - 1] != 'X' && mapa[_y][_x - 1] != 'A' && mapa[_y][_x - 1] != 'Y' && mapa[_y][_x - 1] != 'B' && mapa[_y][_x - 1] != 'C' && mapa[_y][_x - 1] != 'D') _x--; else fdir = rand() % 4; } if (fdir == 0){ if (mapa[_y - 1][_x] != 'X' && mapa[_y - 1][_x] != 'A' && mapa[_y - 1][_x] != 'Y' && mapa[_y - 1][_x] != 'B' && mapa[_y - 1][_x] != 'C' && mapa[_y - 1][_x] != 'D') _y--; else fdir = rand() % 4; } if (fdir == 1){ if (mapa[_y + 1][_x] != 'X' && mapa[_y + 1][_x] != 'A' && mapa[_y + 1][_x] != 'Y' && mapa[_y + 1][_x] != 'B' && mapa[_y + 1][_x] != 'C' && mapa[_y + 1][_x] != 'D') _y++; else fdir = rand() % 4; } } } if (mapa[boly][bolx] == '_') { setCColor(color[1]); gotoxy(bolx, boly); printf("%c", 250); } // rutina atajo if (_x <= 17) _x = 61; else if (_x >= 62) _x = 18; dibujar_fantasma(); }
void pill(Point2D point){ setCColor(color[6]); gotoxy(point.x, point.y); printf("%c", 3); }
void pacman(int x, int y){ setCColor(color[1]); gotoxy(x, y); printf("%c", 2); }