Está en la página 1de 38

2-3-2014 Prácticas y

actividades
Programación de videojuegos

Sonia Valeriano Villalvazo


Índice
Contenido
INTRODUCCIÓN................................................................................................................................... 2
ACTIVIDADES............................................................................................................................................ 3
ACTIVIDAD 1..................................................................................................................................................4
ACTIVIDAD 2..................................................................................................................................................5
ACTIVIDAD 3..................................................................................................................................................6
ACTIVIDAD 4..................................................................................................................................................7
ACTIVIDAD 5..................................................................................................................................................8
PRACTICAS................................................................................................................................................ 9
PRACTICA 1.................................................................................................................................................... 10
PRACTICA 2.................................................................................................................................................... 11
PRACTICA 3.................................................................................................................................................... 12
PRACTICA 4.................................................................................................................................................... 13
PRACTICA 5.................................................................................................................................................... 14
PRACTICA 6.................................................................................................................................................... 15
PRACTICA 7.................................................................................................................................................... 16
PRACTICA 8.................................................................................................................................................... 17
PRACTICA 9.................................................................................................................................................... 18
PRACTICA 10..................................................................................................................................................19
PRACTICA 11..................................................................................................................................................20
PRACTICA 12..................................................................................................................................................21
PRACTICA 13..................................................................................................................................................22
PRACTICA 14..................................................................................................................................................23
PRACTICA 15..................................................................................................................................................24
PRACTICA 16..................................................................................................................................................25
PRACTICA 17..................................................................................................................................................26
PRACTICA 18..................................................................................................................................................27
PRACTICA 19..................................................................................................................................................28
PRACTICA 20..................................................................................................................................................29
Introducción

En este documento presento las prácticas y las actividades desarrolladas a


lo largo del tema 1.1 de la materia programación de videojuegos.
En las prácticas presento el código y el resultado obtenido de cada una de
ellas.
En las actividades presento la información solicitada por el maestro.
Cada una de estas prácticas y cada una de estas actividades fueron
realizadas con mucho esfuerzo, esperando presentar, no un buen trabajo,
sino uno de los mejores que puedan ser presentamos en este tema y en
cualquier otro, por lo que espero que sea de su agrado.
A continuación se presenta las actividades y prácticas realizadas en la
primera unidad, donde se evaluó el desempeño y cumplimiento de cada
alumno, estas actividades fueron realizadas por mi Sonia Valeriano
Villalvazo, para la entrega del 3 de marzo del 2014
Actividades

Actividades
ACTIVIDAD 1

MAPA CONCEPTUAL

VIDEOJUEGO

¿QUÉ ES? ¿PARA QUE SIRVE?


¿EN QUE SE BASA?

ES UN PARA EL
EN LA INTERACCION PROGRAMA ENTRETENIMIENTO
ENTRE UNA O INFORMATICO
VARIAS PERSONAS Y
UNA CONSOLA.

ORIGEN
¿QUÉ HACE?

ESTOS RECREAN ENTORNOS Y TIENE SU ORIGEN EN LA


SITUACIONES VIRTUALES, DECADA DE 1940, TRAS LA
DONDE LOS USUARIOS USAN SEGUNDA GUERRA MUNDIAL
PERSONAJES Y CONSIGUEN
OBJETIVOS SIGUIENDO REGLAS
ACTIVIDAD 2
DIAGRAMA DE FLUJO

INICIALIZACIÓN

CICLO DEL
VIDEOJUEGO

ENTRADA

PROCESAMIENTO

VISUALIZACION DEL
SALIDA
MUNDO VIRTUAL

VIDA NO
<=1

FINALIZACIÓN
SI

COMIENZA LA
MANIPULACION

SIGUE
NO
CON
VIDA

SI
ACTIVIDAD 3
Características de los videojuegos.
A) Funcionamiento en tiempo real

Son videojuegos de estrategia en los que no hay turnos sino que el tiempo transcurre de forma
continua para los jugadores.

Las partidas se desarrollan en un mapa, que puede ser una ubicación real o no, en el cual ocurre
la acción. En el mapa podemos encontrar unidades, edificaciones, recursos y el moldeado del
terreno.

b) Realización de tareas independientes al usuario, dibujar objetos, actualizar coordenadas,


calcular.

En esta etapa es necesario definir los aspectos fundamentales que conformarán el videojuego,
entre los que se encuentran:
 Género: Dentro de que género o géneros se va a desarrollar el juego. De no corresponder
a un género conocido, se deben especificar las características.
 Game play: Lo que generará diversión a la hora de jugarlo.
 Story board: Algunas ideas sueltas acerca de cómo debe lucir el juego en cuanto a
personajes, ambientación, música, etc.

c) Trabajo bajo ciclos en espera de eventos-respuesta

Pruebas: Los videojuegos deben pasar por una etapa donde se corrigen los errores de
programación, los videojuegos requieren un refinamiento de su característica fundamental, la de
producir diversión de manera interactiva. Esta etapa se lleva a cabo en dos fases:

Pruebas alpha: Se llevan a cabo por un pequeño grupo de personas, que con anterioridad estén
involucradas en el desarrollo, lo que puede incluir artistas, programadores, coordinadores, etc. El
propósito es corregir los defectos más graves y mejorar características de jugabilidad.

Pruebas beta: Estas pruebas se llevan a cabo por un equipo externo de jugadores, bien sea que
sean contratados para la ocasión o que sean un grupo componente del proyecto. De estas pruebas
el videojuego debe salir con la menor cantidad posible de defectos menores y ningún defecto
medio o crítico.

ACTIVIDAD 4
INVESTIGACION: LENGUAJES
C++
#include <iostream.h>
int main()
{
int i;
i = 1099;
cout << ”El valor de i es” <<
i << “\n”;
}
Flexibilidad. Portabilidad. Velocidad. Lenguaje compilado.
A los principiantes se les puede dificultar un poco.
C
/* Ejemplo 1. Programa
DOCENA.C */
#include <stdio.h>
main ()
{int docena;
docena = 12;
printf ("Una docena son %d unidades\n", docena);
}
Suministra una visión de conjunto. Eficacia. Muy potente. Lenguaje de alto nivel.
Lenguaje diseñado para la resolución de problemas. Lenguaje compilado.
No es un lenguaje muy estructurado. Lenguaje complicado para el usuario NOVEL.
JAVA
// Hola.java
public class Hola {
public static void main(String[] args)
{ System.out.println
("Hola, mundo!");
}
}
Lenguaje portable. Alto rendimiento. Simple. Seguro. Robusto. Orientado a objetos. Lenguaje
intermediario.
No soporta decimales verdaderos. Redunda en una falta de rendimiento. Depende del tipo de
aplicación a realizarse.
PYTHON
def factorial(x):if x == 0:return 1else:return x * factorial(x -1)
Sintaxis clara. Funciones y librerías. Orientado a objetos. Interactivo. Interpretado.
Multiplataforma.
Lentitud
BASIC
Private Sub Form_Load() 'Ejecuta un simple box
Primer lenguaje de programación
Problema de versionado
ACTIVIDAD 5
IDENTIFICACION DE HERRAMIENTAS DE SOFTWARE
LENGUAJES DE PROGRAMACION COMPILADOS E INTERPRETADOS
NOMBRE SINTAXIS VENTAJAS DESVENTAJAS
C++ #include <iostream.h> Flexibilidad. A los principiantes se les
int main() Portabilidad. puede dificultar un
{ Velocidad. poco.
int i; Lenguaje compilado.
i = 1099;
cout << ”El valor de i es” <<
i << “\n”;
}

C /* Ejemplo 1. Programa Suministra una visión de No es un lenguaje muy


DOCENA.C */ conjunto. estructurado.
#include <stdio.h> Eficacia. Lenguaje complicado
main () Muy potente. Lenguaje para el usuario NOVEL.
{ de alto nivel.
int docena; Lenguaje diseñado para
docena = 12; la resolución de
printf ("Una docena son %d problemas. Lenguaje
unidades\n", docena); compilado.
}
JAVA // Hola.java Lenguaje portable. No soporta decimales
public class Hola { Alto rendimiento. Simple. verdaderos. Redunda en
public static void Seguro. Robusto. una falta de
main(String[] args) Orientado a objetos. rendimiento. Depende
{ System.out.println Lenguaje intermediario. del tipo de aplicación a
("Hola, mundo!"); realizarse.
}
}
PYTHON def factorial(x):if x == Sintaxis clara. Lentitud
0:return 1else:return x * Funciones y librerías.
factorial(x -1) Orientado a objetos.
Interactivo. Interpretado.
Multiplataforma.

BASIC Private Sub Form_Load() Primer lenguaje de Problema de versionado


'Ejecuta un simple box programación
MinGW No se necesita ninguna es que los ejecutables
instalación que genera son de
tamaño más grande que
los generados por otros
compiladores
Practicas

Prácticas
Practica 1
Código Pantallazo
#include <allegro.h>

void init();
void deinit();

int main() {
init();

while (!key[KEY_ESC]) {

line(screen,50,100,400,150,palette_color[23]);
}

deinit();
return 0;
}
END_OF_MAIN()

void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res =
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640,
480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}

install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}

void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
Practica 2
Código Pantallazo
#include <allegro.h>

void init();
void deinit();

int main() {
init();

while (!key[KEY_ESC]) {

rect(screen,100,150,300,300,palette_color[1]);
}

deinit();
return 0;
}
END_OF_MAIN()

void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res =
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640,
480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}

install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}

void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
Practica 3
Código Pantallazo
#include <allegro.h>

void init();
void deinit();

int main() {
init();

while (!key[KEY_ESC]) {

rectfill(screen,100,100,300,300,palette_color[14]);
}

deinit();
return 0;
}
END_OF_MAIN()

void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res =
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640,
480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}

install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}

void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
Practica 4
Código Pantallazo
#include <allegro.h>

void init();
void deinit();

int main() {
init();

while (!key[KEY_ESC]) {

circle(screen,200,200,150,palette_color[5]);
}

deinit();
return 0;
}
END_OF_MAIN()

void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res =
set_gfx_mode(GFX_AUTODETECT_WINDOWED,
640, 480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}

install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}

void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
Practica 5
Código Pantallazo
#include <allegro.h>

void init();
void deinit();

int main() {
init();

while (!key[KEY_ESC]) {

circlefill(screen,300,100,50,palette_color[35]);
}

deinit();
return 0;
}
END_OF_MAIN()

void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res =
set_gfx_mode(GFX_AUTODETECT_WINDOWED,
640, 480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}

install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}

void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
Practica 6
Código Pantallazo
#include <allegro.h>
void init();
void deinit();
int main() {
init();
while (!key[KEY_ESC]) {

rect(screen,100,100,200,200,palette_color[35]);

rect(screen,150,150,250,250,palette_color[35]);

line(screen,200,200,250,250,palette_color[3]);

line(screen,100,100,150,150,palette_color[3]);

line(screen,100,200,150,250,palette_color[3]);

line(screen,250,150,200,100,palette_color[3]);
}
deinit();
return 0;
}
END_OF_MAIN()

void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res =
set_gfx_mode(GFX_AUTODETECT_WINDOWED,
640, 480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}
install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}

void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
Practica 7
Código Pantallazo
#include <allegro.h>

void init();
void deinit();

int main() {
init();

while (!key[KEY_ESC]) {
circle(screen,150,150,70,palette_color[85]);

circle(screen,150,350,70,palette_color[85]);

line(screen,80,160,80,340,palette_color[85]);

line(screen,220,160,220,340,palette_color[85]);
}

deinit();
return 0;
}
END_OF_MAIN()
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res =
set_gfx_mode(GFX_AUTODETECT_WINDOWED,
640, 480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}

install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}
void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
Practica 8
Código Pantallazo
#include <allegro.h>
void init();
void deinit();
int main() {
init();

while (!key[KEY_ESC]) {

triangle(screen,150,100,125,150,175,150,palette_color[10
0]);

triangle(screen,150,150,125,200,175,200,palette_color[10
0]);
line(screen,150,100,150,150,palette_color[10]);
line(screen,125,150,125,200,palette_color[10]);
line(screen,175,150,175,200,palette_color[10]);
rest(50);
}
deinit();
return 0;
}
END_OF_MAIN()

void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res =
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480,
0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}
install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}
void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
Practica 9
Código Pantallazo
#include <allegro.h>
void init();
void deinit();
int main() {
init();
int x1=50;
int y1=50;
int x2=120;
int y2=120;
while (!key[KEY_ESC]) {
clear_bitmap(screen);
line(screen,x1,y1,x2,y2,palette_color[15]);
if (key[KEY_LEFT])
{
x1--;
x2--;
}
if (key[KEY_RIGHT])
{
x1++;
x2++;
}
if (key[KEY_UP])
{
y1--;
y2--;
}
if (key[KEY_DOWN])
{
y1++;
y2++;
}
rest(50);
}
deinit();
return 0;
}
END_OF_MAIN()
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}
install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}
void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
Practica 10
Código Pantallazo
#include <allegro.h>
void init();
void deinit();
int main() {
init();
int x1=200;
int y1=200;
int x2=300;
int y2=300;
while (!key[KEY_ESC]) {
clear_bitmap(screen);
rect(screen,x1,y1,x2,y2,palette_color[54]);
if (key[KEY_LEFT])
{
x1--;
x2--;
}
if (key[KEY_RIGHT])
{
x1++;
x2++;
}
if (key[KEY_UP])
{
y1--;
y2--;
}
if (key[KEY_DOWN])
{
y1++;
y2++;
}
rest(50);
}

deinit();
return 0;
}
END_OF_MAIN()
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}

install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}

void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
Practica 11
Código Pantallazo
#include <allegro.h>
void init();
void deinit();
int main() {
init();
int x1=250;
int y1=250;
int x2=350;
int y2=350;

while (!key[KEY_ESC]) {
clear_bitmap(screen);
rectfill(screen,x1,y1,x2,y2,palette_color[5]);
if (key[KEY_LEFT])
{ x1--;
x2--;
}
if (key[KEY_RIGHT])
{x1++;
x2++;
}
if (key[KEY_UP])
{y1--;
y2--;
}
if (key[KEY_DOWN])
{
y1++;
y2++;
}
rest(50);
}

deinit();
return 0;
}
END_OF_MAIN()

void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}

install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}
void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
Practica 12
Código Pantallazo
#include <allegro.h>
void init();
void deinit();
int main() {
init();
int x1=100;
int y1=200;
while (!key[KEY_ESC]) {
clear_bitmap(screen);
circle(screen,x1,y1,50,palette_color[38]);
if(key[KEY_LEFT])
{
x1--;
}
if (key[KEY_RIGHT])
{
x1++;
}
if(key[KEY_UP])
{
y1--;
}
if (key[KEY_DOWN])
{
y1++;
}
rest(30);
}
deinit();
return 0;
}
END_OF_MAIN()
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0,
0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}
install_timer();
install_keyboard();install_mouse();
/* add other initializations here */
}
void deinit() {clear_keybuf();
/* add other deinitializations here */ }
Practica 13
Código Pantallazo
#include <allegro.h>
void init();

void deinit();

int main() {

init();

while (!key[KEY_ESC]) {

int x1=200;

int y1=200;

while (!key[KEY_ESC]) {

clear_bitmap(screen);

circlefill(screen,x1,y1,100,palette_color[69]);

if(key[KEY_LEFT])

x1--;

if (key[KEY_RIGHT])

x1++;

if(key[KEY_UP])

y1--;

if (key[KEY_DOWN])

y1++;

rest(50);

deinit();
return 0;

END_OF_MAIN()

void init() {

int depth, res;

allegro_init();

depth = desktop_color_depth();

if (depth == 0) depth = 32;

set_color_depth(depth);

res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);

if (res != 0) {

allegro_message(allegro_error);

exit(-1);

install_timer();

install_keyboard();

install_mouse();

/* add other initializations here */

void deinit() {

clear_keybuf();

/* add other deinitializations here */

}
Practica 14
Código Pantallazo
#include <allegro.h>
void init();

void deinit();

int main() {

init();

int x1=100; int y1=100; int x2=200; int y2=200; int x3=150; int y3=50; int x4=250; int
y4=150;

while (!key[KEY_ESC]) {

clear_bitmap(screen);

rect(screen,x1,y1,x2,y2,palette_color[80]);

rect(screen,x3,y3,x4,y4,palette_color[80]);

line(screen,x1,y1,x3,y3,palette_color[15]);

line(screen,x2,y2,x4,y4,palette_color[15]);

line(screen,x1,y2,x3,y4,palette_color[15]);

line(screen,x2,y1,x4,y3,palette_color[15]);

if(key[KEY_LEFT])

x1--;

x2--;

x3--;

x4--;

if(key[KEY_RIGHT])

x1++;

x2++;

x3++;

x4++;

if(key[KEY_UP])

y1--;

y2--;

y3--;
y4--;

if(key[KEY_DOWN])

y1++;

y2++;

y3++;

y4++;

rest(50);

deinit();

return 0;

END_OF_MAIN()

void init() {

int depth, res; allegro_init(); depth = desktop_color_depth();

if (depth == 0) depth = 32;

set_color_depth(depth);

res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);

if (res != 0) { allegro_message(allegro_error); exit(-1); }

install_timer();install_keyboard();install_mouse();

/* add other initializations here */

void deinit() {

clear_keybuf();

/* add other deinitializations here */}

Practica 15
Código Pantallazo
#include <allegro.h>
void init();

void deinit();

int main() {

init();

int x1=200;

int y1=200;

int y2=100;

int x2=170;

int x3=230;

while (!key[KEY_ESC]) {

clear_bitmap(screen);

circle(screen,x1,y1,30,palette_color[69]);

circle(screen,x1,y2,30,palette_color[69]);

line(screen,x2,y1,x2,y2,palette_color[96]);

line(screen,x3,y1,x3,y2,palette_color[96]);

if(key[KEY_LEFT])

x1--;

x2--;

x3--;

if(key[KEY_RIGHT])

x1++;

x2++;

x3++;

if(key[KEY_UP])

y1--;

y2--;

if(key[KEY_DOWN])

{
y1++;

y2++;

rest(30);

deinit();

return 0;

END_OF_MAIN()

void init() {

int depth, res;

allegro_init();

depth = desktop_color_depth();

if (depth == 0) depth = 32;

set_color_depth(depth);

res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);

if (res != 0) {

allegro_message(allegro_error);

exit(-1);

install_timer(); install_keyboard(); install_mouse();

/* add other initializations here */

void deinit() {

clear_keybuf();

/* add other deinitializations here */}

Practica 16
Código Pantallazo
#include <allegro.h>
void init();
void deinit();
int main() {
init();
int x1=200;int y1=300;int x2=300;int y2=200;int x3=400;int y3=300;int x4=280;int y4=250;
int x5=380;int y5=150;int x6=480;int y6=250;
while (!key[KEY_ESC]) {
clear_bitmap(screen);
triangle(screen,x1,y1,x2,y2,x3,y3,palette_color[35]);
triangle(screen,x4,y4,x5,y5,x6,y6,palette_color[35]);
line(screen,x1,y1,x4,y4,palette_color[15]);
line(screen,x2,y2,x5,y5,palette_color[15]);
line(screen,x3,y3,x6,y6,palette_color[15]);
if(key[KEY_LEFT])
{
x1--;
x2--;
x3--;
x4--;
x5--;
x6--;
}
if(key[KEY_RIGHT])
{
x1++;
x2++;
x3++;
x4++;
x5++;
x6++;
}
if(key[KEY_UP])
{
y1--;
y2--;
y3--;
y4--;
y5--;
y6--;
}
if(key[KEY_DOWN])
{
y1++;
y2++;
y3++;
y4++;
y5++;
y6++;
}

rest(40);
}

deinit();
return 0;
}
END_OF_MAIN()

Practica 17
Código Pantallazo
#include <allegro.h>
void init();
void deinit();
int main() {
init();
int x=400;
int y=100;
while (!key[KEY_ESC]) {
clear_bitmap(screen);
line(screen,300,0,300,170,palette_color[89]);
line(screen,300,220,300,400,palette_color[89]);
circlefill(screen,x,y,10,palette_color[5]);
if(key[KEY_LEFT])
{ x--;
//barrera
if(x==310)
{x++;
//entrada
if(y>170&& y<220)
{ x--;}
}
}
if(key[KEY_RIGHT])
{ x++;
//barrera
if(x==290)
{x--;
//entrada
if(y>170&& y<220)
{ x++;}
}
}
if(key[KEY_UP])
{y--;}
if(key[KEY_DOWN])
{y++; }
rest(25);
}
deinit();
return 0;
}
END_OF_MAIN()
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 600, 400, 0, 0);
if (res != 0) {allegro_message(allegro_error);
exit(-1); }
install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}
void deinit() {
clear_keybuf();
/* add other deinitializations here */
}

Practica 18
Código Pantallazo
#include <allegro.h>
void init();
void deinit();
int main() {
init();
int x=50; int y=300;
while (!key[KEY_ESC]) {
clear_bitmap(screen);
line(screen,0,200,250,200,palette_color[100]);
line(screen,350,200,600,200,palette_color[100]);
circlefill(screen,x,y,5,palette_color[89]);
if (key[KEY_LEFT])
{ x--; }
if (key[KEY_RIGHT])
{ x++; }
if (key[KEY_UP])
{ y--;
if(y==205)
{ y++;
if (x>250 && x<350)
{ y--; }
}
}
if (key[KEY_DOWN])
{
y++;
if(y==195)
{
y--;
if(x>250 && x<350)
{
y++;
}
}
}
rest(25);
clear_keybuf();
}
deinit();
return 0;
}
END_OF_MAIN()
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 600, 400, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}
install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}
void deinit() {
clear_keybuf();
/* add other deinitializations here */}

Practica 19
Código Pantallazo
#include <allegro.h>
void init();

void deinit();

int x=200; int y=200;

int main() {

init();

while (!key[KEY_ESC]) {

clear_bitmap(screen);

rect(screen,100,100,300,300,palette_color[4]);

circlefill(screen,x,y,5,palette_color[6]);

if(key[KEY_LEFT])

{ x--;

//BARRERA

if(x==105)

x++;

if (key[KEY_RIGHT])

x++;

//BARRERA

if(x==295)

{ x--;

if(key[KEY_UP])

{ y--;

//BARRERA

if(y==105)

y++;

if (key[KEY_DOWN])
{ y++;

//BARRERA

if(y==295)

{ y--;

rest(30);

deinit();

return 0;

END_OF_MAIN()

void init() {

int depth, res; allegro_init(); depth = desktop_color_depth();

if (depth == 0) depth = 32;

set_color_depth(depth);

res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 400, 400, 0, 0);

if (res != 0) {allegro_message(allegro_error);

exit(-1);}

install_timer();install_keyboard();install_mouse();

/* add other initializations here */

void deinit() {

clear_keybuf();

/* add other deinitializations here */}

Practica 20
Código Pantallazo
#include <allegro.h>
void init(); void deinit();

int main() { init();

int x1=150;int y1=150;

while (!key[KEY_ESC]) {

clear_bitmap(screen);

rect(screen,100,100,300,300,palette_color[14]);

line(screen,100,170,100,230,palette_color[16]);

line(screen,300,170,300,230,palette_color[16]);

line(screen,170,100,230,100,palette_color[16]);

line(screen,170,300,230,300,palette_color[16]);

circlefill(screen,x1,y1,5,palette_color[13]);

if(key[KEY_LEFT])

{ x1--;

if(x1==105 || x1==305)

{ x1++;

if(y1>175 && y1<225 || y1<95 || y1>305)

{ x1--;

if(key[KEY_RIGHT])

{ x1++;

if(x1==295 || x1==95)

{ x1--;

if(y1>175 && y1<225 || y1<95 || y1>305)

{ x1++;

if(key[KEY_UP])

{y1--;

if(y1==105 || y1==305)

{y1++;

if(x1>175 && x1<225 || x1<95 || x1>305)


{y1--;

if(key[KEY_DOWN])

{ y1++;

if(y1==295 || y1==95)

{y1--;

if(x1>175 && x1<225 || x1<95 || x1>305)

{ y1++; }

rest(50);

deinit();

return 0;

END_OF_MAIN()

void init() {int depth, res;allegro_init();depth = desktop_color_depth();

if (depth == 0) depth = 32;set_color_depth(depth);

res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 400, 400, 0, 0);

if (res != 0) {allegro_message(allegro_error); exit(-1); }

install_timer();install_keyboard();install_mouse();

/* add other initializations here */}

void deinit() {clear_keybuf();/* add other deinitializations here */}

Conclusión

También podría gustarte