Вы находитесь на странице: 1из 12

Colegio De Educacio n Profesional

Te cnica Del Estado De Veracruz



Unidad de Aprendizaje 2:
Diseo de videojuegos Nmero:
Prctica 8:
Evitar los parpadeos. Juego Miniserpiente 3
Propsito de la prctica:
Crear juego donde se eviten parpadeos mediante aproximaciones.
Mdulo: Programacin De Videojuegos [POVI-02]
Grupo: 604 Informtica
Alumno: Manuel Alexis Hurtado Morales
P.S.P: Ing. Miguel ngel Ramos Grande
Fecha: 19 de mayo de 2014
Matricula: 111650246-7
Comentarios:

Observaciones:


Direccin del blog:
http://programaciondevideojuegosalexis.blogspot.mx/
PRACTICA #8 Evitar los parpadeos.
Juego Miniserpiente 3
1.- Para la elaboracin de esta prctica lo primero que realice es:
Abrir Dev-Cpp
Damos clic en ARCHIVO
Seleccionamos el men NUEVO
Enseguida damos clic en PROYECTO

2. - Se abrira la siguiente ventana y seleccionamos el men siguiente:

#include <allegro.h>
/* Posiciones X e Y iniciales */
#define POS_X_INI 16
#define POS_Y_INI 10
#define INC_X_INI 1
#define INC_Y_INI 0
/* Pausa en milisegundos entre un "fotograma" y otro */
#define PAUSA 350
/* Teclas predefinidas */
#define TEC_ARRIBA KEY_E
#define TEC_ABAJO KEY_X
#define TEC_IZQDA KEY_S
#define TEC_DCHA KEY_D
int posX, posY; /* Posicion actual */
int incX, incY; /* Incremento de la posicion */
/* Terminado: Si ha chocado o comida todas las frutas */
int terminado;
/* La tecla pulsada */
int tecla;
/* Escala: relacion entre tama?o de mapa y de pantalla */
#define ESCALA 10
/* Ancho y alto de los sprites */
#define ANCHOSPRITE 10
#define ALTOSPRITE 10
/* Y el mapa que representa a la pantalla */
/* Como usaremos modo grafico de 320x200 puntos */
/* y una escala de 10, el tablero medira 32x20 */
#define MAXFILAS 20
#define MAXCOLS 33
char mapa[MAXFILAS][MAXCOLS]={

};
int numFrutas = 8;
/* Nuestros sprites */
BITMAP *ladrilloFondo, *comida, *jugador;
BITMAP *pantallaOculta; /* Y la pantalla oculta */
typedef
char tipoSprite[ANCHOSPRITE][ALTOSPRITE];
/* El sprite en si: matriz de 10x10 bytes */
tipoSprite spriteLadrillo =
{{0,2,2,2,2,2,2,2,2,0},
{2,1,1,1,1,1,1,1,1,2},
{2,1,1,1,1,1,1,1,1,2},
{2,1,1,1,1,1,1,1,1,2},
{2,1,1,1,1,1,1,1,1,2},
{2,1,1,1,1,1,1,1,3,2},
{2,1,1,1,1,1,1,3,3,2},
{2,1,1,1,1,1,3,3,2,2},
{2,2,2,2,2,2,2,2,2,0}
};
tipoSprite spriteComida =
{{0,0,0,2,0,0,0,0,0,0},
{0,0,2,2,0,0,2,2,0,0},
{0,4,4,4,2,2,4,4,0,0},
{4,4,4,4,4,2,4,4,4,0},
{4,4,4,4,4,4,4,4,4,0},
{4,4,4,4,4,4,4,4,4,0},
{4,4,4,4,4,4,4,4,4,0},
{4,4,4,4,4,4,4,4,4,0},
{0,4,4,4,4,4,4,4,0,0}
};
tipoSprite spriteJugador =
{{0,0,3,3,3,3,3,0,0,0},
{0,3,1,1,1,1,1,3,0,0},
{3,1,1,1,1,1,1,1,3,0},
{3,1,1,1,1,1,1,1,3,0},
{3,1,1,1,1,1,1,1,3,0},
{3,1,1,1,1,1,1,1,3,0},
{0,3,1,1,1,1,1,3,0,0},
{0,0,3,3,3,3,3,0,0,0}
};
/* -------------- Rutina de crear los sprites ------------- */
void creaSprites()
{
int i, j;
ladrilloFondo = create_bitmap(10, 10);
clear_bitmap(ladrilloFondo);
for(i=0; i<ANCHOSPRITE; i++)
for (j=0; j<ALTOSPRITE; j++)
putpixel(ladrilloFondo, i, j,
palette_color[ spriteLadrillo[j][i] ]);
comida = create_bitmap(10, 10);
clear_bitmap(comida);
for(i=0; i<ANCHOSPRITE; i++)
for (j=0; j<ALTOSPRITE; j++)
putpixel(comida, i, j,
palette_color[ spriteComida[j][i] ]);
jugador = create_bitmap(10, 10);
clear_bitmap(jugador);
for(i=0; i<ANCHOSPRITE; i++)
for (j=0; j<ALTOSPRITE; j++)
putpixel(jugador, i, j,
palette_color[ spriteJugador[j][i] ]);
pantallaOculta = create_bitmap(320, 200);
}
/* -------------- Rutina de dibujar el fondo ------------- */
void dibujaFondo()
{
int i, j;
clear_bitmap(pantallaOculta);
for(i=0; i<MAXCOLS; i++)
for (j=0; j<MAXFILAS; j++) {
if (mapa[j][i] == 'X')
draw_sprite(pantallaOculta, ladrilloFondo, i*ESCALA, j*ESCALA);
if (mapa[j][i] == 'F')
draw_sprite(pantallaOculta, comida, i*ESCALA, j*ESCALA);
}
}
/* ------------------------------------------------ */
/* */
/* -------------- Cuerpo del programa ------------- */
int main()
{
allegro_init(); /* Inicializamos Allegro */
install_keyboard();
install_timer();
/* Intentamos entrar a modo grafico */
if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message(
"Incapaz de entrar a modo grafico\n%s\n",
allegro_error);
return 1;
}
/* ----------------------- Si todo ha ido bien: empezamos */
creaSprites();
dibujaFondo();
/* Valores iniciales */
posX = POS_X_INI;
posY = POS_Y_INI;
incX = INC_X_INI;
incY = INC_Y_INI;
/* Parte repetitiva: */
do {
dibujaFondo();
draw_sprite (pantallaOculta, jugador, posX*ESCALA, posY*ESCALA);
terminado = FALSE;
/* Si pasa por una fruta: se borra y falta una menos */
if (mapa[posY][posX] == 'F') {
mapa[posY][posX] = ' ';
numFrutas --;
if (numFrutas == 0) {
textout(pantallaOculta, font,
"Ganaste!", 100, 90, palette_color[14]);
terminado = TRUE;
}
}
/* Si choco con la pared, se acab el juego */
if (mapa[posY][posX] == 'X') {
textout(pantallaOculta, font,
"Chocaste!", 100, 90, palette_color[13]);
terminado = TRUE;
}
/* En cualquier caso, vuelco la pantalla oculta */
blit(pantallaOculta, screen, 0, 0, 0, 0, 320, 200);
if (terminado) break;
/* Compruebo si se ha pulsado alguna tecla */
if ( keypressed() ) {
tecla = readkey() >> 8;
switch (tecla) {
case TEC_ARRIBA:
incX = 0; incY = -1; break;
case TEC_ABAJO:
incX = 0; incY = 1; break;
case TEC_IZQDA:
incX = -1; incY = 0; break;
case TEC_DCHA:
incX = 1; incY = 0; break;
}
}
posX += incX;
posY += incY;
/* Pequea pausa antes de seguir */
rest ( PAUSA );
}
while (TRUE); /* Repetimos indefinidamente */
/* (la condicion de salida la comprobamos "dentro") */
readkey();
destroy_bitmap(pantallaOculta);
destroy_bitmap(jugador);
destroy_bitmap(comida);
destroy_bitmap(ladrilloFondo);
return 0;
}
/* Termino con la "macro" que me pide Allegro */
END_OF_MAIN();
En esta practica creamos un "buffer" es una memoria intermedia en la que se
guarda la informacin antes de llegar a su destino definitivo.
La forma de conseguir esto con Allegro es algo parecido a:
BITMAP *bmp = create_bitmap(320, 200); // Creamos el bitmap auxiliar en
memoria
clear_bitmap(bmp); // Lo borramos
putpixel(bmp, x, y, color); // Dibujamos en l
blit(bmp, screen, 0, 0, 0, 0, 320, 200); // Finalmente,volcamos a pantalla
Pantalla que se muestra al iniciar el juego

Si chocas con un muro se te mostrara un mensaje:

Si ganas se te felicitara:

Вам также может понравиться

  • Admón
    Admón
    Документ10 страниц
    Admón
    Alexis Hurtado
    Оценок пока нет
  • Práctica 12 POVI
    Práctica 12 POVI
    Документ9 страниц
    Práctica 12 POVI
    Alexis Hurtado
    Оценок пока нет
  • Ramos Practica 11 C
    Ramos Practica 11 C
    Документ7 страниц
    Ramos Practica 11 C
    Alexis Hurtado
    Оценок пока нет
  • Practica 5 Ramos
    Practica 5 Ramos
    Документ8 страниц
    Practica 5 Ramos
    Alexis Hurtado
    Оценок пока нет
  • Practica 11 Ramos
    Practica 11 Ramos
    Документ8 страниц
    Practica 11 Ramos
    Alexis Hurtado
    Оценок пока нет
  • Práctica 10
    Práctica 10
    Документ14 страниц
    Práctica 10
    Alexis Hurtado
    Оценок пока нет
  • Práctica 10 POVI
    Práctica 10 POVI
    Документ5 страниц
    Práctica 10 POVI
    Alexis Hurtado
    Оценок пока нет
  • Práctica - 6 POVI
    Práctica - 6 POVI
    Документ7 страниц
    Práctica - 6 POVI
    Alexis Hurtado
    Оценок пока нет
  • Práctica 7
    Práctica 7
    Документ10 страниц
    Práctica 7
    Alexis Hurtado
    Оценок пока нет
  • Práctica - 8 POVI
    Práctica - 8 POVI
    Документ12 страниц
    Práctica - 8 POVI
    Alexis Hurtado
    Оценок пока нет
  • Ramos Practica 11 C
    Ramos Practica 11 C
    Документ7 страниц
    Ramos Practica 11 C
    Alexis Hurtado
    Оценок пока нет
  • Práctica 12 Simón Dice
    Práctica 12 Simón Dice
    Документ9 страниц
    Práctica 12 Simón Dice
    Alexis Hurtado
    Оценок пока нет
  • Práctica 6
    Práctica 6
    Документ7 страниц
    Práctica 6
    Alexis Hurtado
    Оценок пока нет
  • Práctica 4
    Práctica 4
    Документ9 страниц
    Práctica 4
    Alexis Hurtado
    Оценок пока нет
  • Práctica 7
    Práctica 7
    Документ10 страниц
    Práctica 7
    Alexis Hurtado
    Оценок пока нет
  • Práctica 10 Punteria
    Práctica 10 Punteria
    Документ5 страниц
    Práctica 10 Punteria
    Alexis Hurtado
    Оценок пока нет
  • Practica 13 Ramos
    Practica 13 Ramos
    Документ12 страниц
    Practica 13 Ramos
    Alexis Hurtado
    Оценок пока нет
  • Práctica - 4 POVI
    Práctica - 4 POVI
    Документ9 страниц
    Práctica - 4 POVI
    Alexis Hurtado
    Оценок пока нет
  • Práctica 12 Simón Dice
    Práctica 12 Simón Dice
    Документ8 страниц
    Práctica 12 Simón Dice
    Alexis Hurtado
    Оценок пока нет
  • Practica 5
    Practica 5
    Документ8 страниц
    Practica 5
    Alexis Hurtado
    Оценок пока нет
  • Practica 5
    Practica 5
    Документ8 страниц
    Practica 5
    Alexis Hurtado
    Оценок пока нет
  • Practica 5 Ramos
    Practica 5 Ramos
    Документ8 страниц
    Practica 5 Ramos
    Alexis Hurtado
    Оценок пока нет
  • Practica 12 MRDE
    Practica 12 MRDE
    Документ11 страниц
    Practica 12 MRDE
    Alexis Hurtado
    Оценок пока нет
  • Práctica 10
    Práctica 10
    Документ18 страниц
    Práctica 10
    Alexis Hurtado
    Оценок пока нет
  • Practica 15
    Practica 15
    Документ9 страниц
    Practica 15
    Alexis Hurtado
    Оценок пока нет
  • Practica 11 Ramos
    Practica 11 Ramos
    Документ8 страниц
    Practica 11 Ramos
    Alexis Hurtado
    Оценок пока нет
  • Practica 14 Manejo de Redes
    Practica 14 Manejo de Redes
    Документ8 страниц
    Practica 14 Manejo de Redes
    Alexis Hurtado
    Оценок пока нет
  • Practica 12 MRDE
    Practica 12 MRDE
    Документ11 страниц
    Practica 12 MRDE
    Alexis Hurtado
    Оценок пока нет
  • Proyecto MRDE
    Proyecto MRDE
    Документ31 страница
    Proyecto MRDE
    Alexis Hurtado
    Оценок пока нет
  • Computadoras Superescalares
    Computadoras Superescalares
    Документ36 страниц
    Computadoras Superescalares
    Lawiet Elle
    Оценок пока нет
  • Escalar Imagen en Java
    Escalar Imagen en Java
    Документ5 страниц
    Escalar Imagen en Java
    Pedro Ruiz
    Оценок пока нет
  • Oracle Sqldeveloper
    Oracle Sqldeveloper
    Документ26 страниц
    Oracle Sqldeveloper
    DIEGO AHUMADA DELVILLAR
    Оценок пока нет
  • Lenguaje Maquina
    Lenguaje Maquina
    Документ19 страниц
    Lenguaje Maquina
    Madaí Kanthunzita
    Оценок пока нет
  • Habilidades Comunicativas
    Habilidades Comunicativas
    Документ2 страницы
    Habilidades Comunicativas
    Antony Arias Blanco
    0% (1)
  • 2 3 Procesos Ligeros Hilos o Hebras
    2 3 Procesos Ligeros Hilos o Hebras
    Документ6 страниц
    2 3 Procesos Ligeros Hilos o Hebras
    Irving Aguilar
    Оценок пока нет
  • Actividades de Refuerzo
    Actividades de Refuerzo
    Документ3 страницы
    Actividades de Refuerzo
    Isabel Odriozola
    Оценок пока нет
  • Especificación de Requerimientos de Software
    Especificación de Requerimientos de Software
    Документ15 страниц
    Especificación de Requerimientos de Software
    Santiago Aguilar
    Оценок пока нет
  • Funciones de Fecha y Cadena PDF
    Funciones de Fecha y Cadena PDF
    Документ5 страниц
    Funciones de Fecha y Cadena PDF
    Christopher
    Оценок пока нет
  • Crear Un Disco Duro Virtual en Linux
    Crear Un Disco Duro Virtual en Linux
    Документ5 страниц
    Crear Un Disco Duro Virtual en Linux
    Fran May
    Оценок пока нет
  • Recursividad
    Recursividad
    Документ5 страниц
    Recursividad
    Cristian San Martin
    Оценок пока нет
  • Arquitectura Del Microprocesador z80
    Arquitectura Del Microprocesador z80
    Документ9 страниц
    Arquitectura Del Microprocesador z80
    Nilyan Berti
    Оценок пока нет
  • Abrazo Mortal
    Abrazo Mortal
    Документ8 страниц
    Abrazo Mortal
    edenfray
    Оценок пока нет
  • Diferencia Entre RFI y RFP
    Diferencia Entre RFI y RFP
    Документ6 страниц
    Diferencia Entre RFI y RFP
    Andrés Alava
    50% (2)
  • Procesador z80
    Procesador z80
    Документ15 страниц
    Procesador z80
    Abraham Contreras
    100% (1)
  • Desarrollo de Software Orientado A Aspectos
    Desarrollo de Software Orientado A Aspectos
    Документ4 страницы
    Desarrollo de Software Orientado A Aspectos
    Silys Pineda
    Оценок пока нет
  • Isatis Software de Geoestadistica para Una Mejora Estimacion de Recursos Mineros
    Isatis Software de Geoestadistica para Una Mejora Estimacion de Recursos Mineros
    Документ2 страницы
    Isatis Software de Geoestadistica para Una Mejora Estimacion de Recursos Mineros
    Eduardo Torres Burga
    Оценок пока нет
  • Introduccion A Arduino
    Introduccion A Arduino
    Документ24 страницы
    Introduccion A Arduino
    dadar2586
    Оценок пока нет
  • Owasp Dvwa
    Owasp Dvwa
    Документ31 страница
    Owasp Dvwa
    Carlos Humbeto Portillo Mendez
    Оценок пока нет
  • Conferencia - 11 - Memoria
    Conferencia - 11 - Memoria
    Документ14 страниц
    Conferencia - 11 - Memoria
    Yanquiel Mansfarroll Gonzalez
    Оценок пока нет
  • 04 Isc 478 Trabajo de Grado PDF
    04 Isc 478 Trabajo de Grado PDF
    Документ118 страниц
    04 Isc 478 Trabajo de Grado PDF
    Enyerson Darwin Camero Correa
    Оценок пока нет
  • EL Patrón MVC
    EL Patrón MVC
    Документ16 страниц
    EL Patrón MVC
    Anonymous hWPiz6
    Оценок пока нет
  • Caso Practico Numero 2 Gestion de Proyectos Dos
    Caso Practico Numero 2 Gestion de Proyectos Dos
    Документ2 страницы
    Caso Practico Numero 2 Gestion de Proyectos Dos
    yeiner
    100% (5)
  • Materia Sistema Operativo UNIX-1
    Materia Sistema Operativo UNIX-1
    Документ48 страниц
    Materia Sistema Operativo UNIX-1
    anon_74680334
    Оценок пока нет
  • CCNA2 Cap3 Configuración Del Router v3
    CCNA2 Cap3 Configuración Del Router v3
    Документ17 страниц
    CCNA2 Cap3 Configuración Del Router v3
    Victor Caceres
    Оценок пока нет
  • Examen LP II Ejercicios Java Net Beans
    Examen LP II Ejercicios Java Net Beans
    Документ1 страница
    Examen LP II Ejercicios Java Net Beans
    Jose Miguel
    Оценок пока нет
  • Algoritmia Y Programacion Estructurada :)
    Algoritmia Y Programacion Estructurada :)
    Документ11 страниц
    Algoritmia Y Programacion Estructurada :)
    Lalez Palmer
    Оценок пока нет
  • Practica 11.5.1 Cisco
    Practica 11.5.1 Cisco
    Документ13 страниц
    Practica 11.5.1 Cisco
    Benja Crosh
    Оценок пока нет
  • Indice Tentativo (Autoguardado)
    Indice Tentativo (Autoguardado)
    Документ57 страниц
    Indice Tentativo (Autoguardado)
    Satanacio Alba Rodriguez
    Оценок пока нет
  • Torre de Hanoi Fuerza Brutal Python
    Torre de Hanoi Fuerza Brutal Python
    Документ4 страницы
    Torre de Hanoi Fuerza Brutal Python
    Dogezo
    Оценок пока нет