Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef PACMA_CPP_INCLUDED
- #define PACMA_CPP_INCLUDED
- #include <allegro.h>
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <math.h>
- #include <stdlib.h>
- #define NAME "tito" // para el login
- #define PASSWORD "123456" // para el login
- #define MAXFILAS 20 // para el eje y
- #define MAXCOLS 31 //para el eje x
- using namespace std;
- BITMAP * buffer;
- BITMAP *roca;
- BITMAP *pacbmp;
- BITMAP *pacman;
- BITMAP *comida;
- BITMAP *muertebmp;
- //musica
- MIDI *musica1;
- SAMPLE *bolita;
- SAMPLE *caminando;
- SAMPLE *muerte;
- int px = 30*14,py=30*17;
- int dir =4;
- int anteriorpx,anteriorpy;
- bool login_correct = false;
- char mapa[MAXFILAS][MAXCOLS]={
- "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
- "X o |o o o XXXXX o o o| o X",
- "X XXX XXXXX XXXXX XXXXX XXX X",
- "XoXXX XXXXX XXXXX XXXXX XXXoX",
- "X o|o o o o|o X",
- "XoXXXoXX XXXXXXXXXXX XXoXXXoX",
- "X |XX |XXX| XX X",
- "XoXXXoXXXXXX XXX XXXXXXoXXXoX",
- "X XXXoXX ooo|ooo|ooo XXoXXX X",
- " o |XX XXXXXXXXXXX XX| o ",
- "X XXXoXX XXXXXXXXXXX XXoXXX X",
- "XoXXXoXX oo |ooo|ooo XXoXXXoX",
- "X XXXoXXXXXX XXX XXXXXXoXXX X",
- "X XX XXX XX X",
- "X XXXoXX XXXXXXXXXXX XXoXXX X",
- "XoXXX| o| o o o o o |o |XXXoX",
- "X XXXoXXXX XXXXXXXX XXX XXX X",
- "XoXXXoXXXX XXX XXXoX",
- "X o |o o XXXXXXXX o o| o X",
- "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
- };
- void dibujar_mapa(){
- int row,col;
- for(row =0; row<MAXFILAS; row++){
- for(col =0; col<MAXCOLS; col++){
- if(mapa[row][col] == 'X'){
- draw_sprite(buffer,roca, col*30 , row*30);
- }
- else if(mapa[row][col] == 'o'){
- draw_sprite(buffer,comida, col*30 , row*30);
- if(py/30 == row && px/30 == col){
- //play_sample(bolita,300, 150, 100,0);
- mapa[row][col] = ' ';
- }
- }
- }
- }
- }
- void pantalla(){
- blit(buffer,screen , 0,0,0,0,880,600);
- }
- void dibujar_personaje(){
- blit(pacbmp,pacman,dir*33,0,0,0,33,33);
- draw_sprite(buffer,pacman,px,py);
- }
- bool game_over(){
- int row,col;
- for(row =0; row<MAXFILAS; row++){
- for(col =0; col<MAXCOLS; col++){
- if(mapa[row][col] == 'o')return true;
- }
- }
- return false;
- }
- class Fantasma{
- private:
- BITMAP *enemigobmp;
- BITMAP *enemigo;
- int fdir = 0;
- int _x, _y;
- public:
- Fantasma(int x , int y);
- void dibujar_fantasma() const;
- void mover_fantasma();
- void choque_pacman();
- };
- Fantasma::Fantasma(int x, int y){
- _x = x;
- _y = y;
- fdir = rand()%4;
- enemigo = create_bitmap(30,30);
- enemigobmp = load_bitmap("enemigo.bmp",NULL);
- }
- void Fantasma::dibujar_fantasma() const{
- blit(enemigobmp,enemigo,0,0,0,0,30,30);
- draw_sprite(buffer,enemigo,_x,_y);
- }
- void Fantasma::choque_pacman(){
- if((py == _y && px == _x) || (_y == anteriorpy && anteriorpy == _x)) {
- play_sample(muerte,100,150,1000,0);
- for(int j =0; j<=5; j++){
- clear(pacman);
- clear(buffer);
- dibujar_mapa();
- blit(muertebmp,pacman,j*33,0,0,0,33,333);
- draw_sprite(buffer,pacman,px,py);
- pantalla();
- rest(80);
- }
- px = 30*14;
- py = 30*17;
- dir = 4;
- }
- }
- void Fantasma::mover_fantasma(){
- dibujar_fantasma();
- choque_pacman();
- if(mapa[_y/30][_x/30] == '|'){
- fdir = rand()%4;
- }
- if(fdir == 0){
- if(mapa[_y/30][(_x-30)/30] != 'X') _x-=30;
- else fdir = rand()%4;
- }
- if(fdir == 1){
- if(mapa[_y/30][(_x+30)/30] != 'X') _x+=30;
- else fdir = rand()%4;
- }
- if(fdir == 2){
- if(mapa[(_y-30)/30][(_x)/30] != 'X') _y-=30;
- else fdir = rand()%4;
- }
- if(fdir == 3){
- if(mapa[(_y+30)/30][(_x)/30] != 'X') _y+=30;
- else fdir = rand()%4;
- }
- //rutina atajo
- if(_x <= -30 ) _x = 870;
- else if(_x >= 870) _x= -30;
- }
- void start_game(){
- allegro_init();using namespace std;
- install_keyboard();
- set_color_depth(32);
- set_gfx_mode(GFX_AUTODETECT_WINDOWED,880,600,0,0);
- if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
- allegro_message("Error: inicializando sistema de sonido\n%s\n", allegro_error);
- }
- //ajustamo el volumen
- set_volume(70, 70);
- musica1 = load_midi("mario.mid");
- bolita = load_wav("coin.wav");
- caminando = load_wav("jump.wav");
- muerte = load_wav("Muerte.wav");
- buffer = create_bitmap(880,600);
- roca = load_bitmap("roca.bmp",NULL);
- pacbmp = load_bitmap("pacman.bmp",NULL);
- pacman = create_bitmap(33,33);
- comida = load_bitmap("Comida.bmp",NULL);
- muertebmp = load_bitmap("muerte.bmp",NULL);
- Fantasma A(30*2,30*3);
- Fantasma B(30*10,30*11);
- Fantasma C(30*15,30*16);
- Fantasma D(30*21,30*22);
- Fantasma E(30*23,30*25);
- Fantasma F(30*25,30*12);
- Fantasma G(30*20,30*8);
- Fantasma H(30*20,30*8);
- play_midi(musica1,1);
- while(!key[KEY_ESC] && game_over() ){
- if(dir != 4) play_sample(caminando,100,150,100,0);
- anteriorpx = px;
- anteriorpy = py;
- if(key[KEY_RIGHT]) dir=1; // rutina para mover a pacman
- else if(key[KEY_LEFT]) dir=0;
- else if(key[KEY_UP]) dir = 2;
- else if(key[KEY_DOWN]) dir = 3;
- if(dir == 0){
- if(mapa[py/30][(px-30)/30] != 'X'){
- px -= 30;
- }
- else dir =4;
- }
- if(dir == 1){
- if(mapa[py/30][(px+30)/30] != 'X'){
- px += 30;
- }
- else dir =4;
- }
- if(dir == 2){
- if(mapa[(py-30)/30][(px)/30] != 'X'){
- py -= 30;
- }
- else dir =4;
- }
- if(dir == 3){
- if(mapa[(py+30)/30][(px)/30] != 'X'){
- py += 30;
- }
- else dir =4;
- }
- //rutina para atajo
- if(px <= -30 ) px = 870;
- else if(px >= 870) px= -30;
- clear(buffer);
- dibujar_mapa();
- dibujar_personaje();
- A.mover_fantasma();
- B.mover_fantasma();
- C.mover_fantasma();
- D.mover_fantasma();
- E.mover_fantasma();
- F.mover_fantasma();
- G.mover_fantasma();
- H.mover_fantasma();
- pantalla();
- rest(70);
- clear(pacman);
- blit(pacbmp,pacman,4*33,0,0,0,33,33);
- draw_sprite(buffer,pacman,px,py);
- pantalla();
- rest(90);
- }
- }
- void login(){
- string nombre = "",password="";
- char aux;
- int intentos = 1;
- while(true){
- intentos++;
- cout << "\t\tNombre: ";
- cin>>nombre;
- cout << "\t\tContrasena: ";
- aux= getch();
- while(aux != 13){
- cout << "*";
- password.push_back(aux);
- aux = getch();
- }
- if(PASSWORD == password && NAME == nombre){
- cout << "\n\nBienvenido " << nombre << " :) " << endl;
- login_correct = true;
- break;
- }
- else{
- if(intentos > 3){
- cout << "\n\n\t\thaz tratado de ingresar 3 veces y \n\t\tno haz podido" << endl;
- break;
- }
- else{
- cout << "\n\n\t\tcontraseña y/o usuario incorrecto \n\t\tintentelo de nuevo " << endl << endl;
- rest(50);
- system("cls");
- }
- }
- }
- }
- #endif // PACMA_CPP_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement