Laberinto Marquez

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

LABERINTO MARQUEZ

#include <GL/glut.h>

#include <math.h>

#include <stdlib.h>

#include <stdio.h>

double lab_x = -0.9f;

double lab_y = -0.9f;

double persona_x = -8;

double persona_y = 8;

int sw1 = 0;

int pos = 0;

void iniciar(){

glMatrixMode(GL_PROJECTION);

gluOrtho2D(-10,10,-10,10);

glClearColor(0.0,0.0,0.0,0.0);}

void dibujar(){

glClear(GL_COLOR_BUFFER_BIT);

//dibujar flecha

glPushMatrix();

glTranslatef(persona_x, persona_y, 0);

//glRotated(-50,0,0,1);

glPointSize(12);

glBegin(GL_POINTS);

glColor3f(1.f,0.f,0);

glVertex2f(0,0);

glEnd();
glBegin(GL_QUADS);

glColor3f(1.f,1.f,0);

glVertex2f(-0.02, -0.02);

glVertex2f(0.02, -0.02);

glVertex2f(0.02, -0.09);

glVertex2f(-0.02, -0.09);

glEnd();

glPopMatrix();

//dibujar laberinto

glPushMatrix();

glTranslatef(lab_x, lab_y, 0);

glColor3f(1.0,0.0,0.0);

glBegin(GL_LINES);

glVertex2f(-6,8);glVertex2i(8,8);

glVertex2i(-6,8);glVertex2i(-6,5);

glVertex2i(-8,8);glVertex2i(-8,-8);

glVertex2f(-8,-8);glVertex2i(8,-8);

glVertex2f(8,8);glVertex2i(8,0);

glVertex2f(8,0);glVertex2i(0,0);

glVertex2f(0,0);glVertex2i(0,-3);

glVertex2f(0,-3);glVertex2i(-6,-3);

glVertex2f(-6,0);glVertex2i(-6,-6);

glVertex2f(8,-8);glVertex2i(8,-3);
glVertex2f(8,-3);glVertex2i(6,-3);

glVertex2f(6,-3);glVertex2i(6,-6);

glVertex2f(6,-6);glVertex2i(-3,-6);

glVertex2f(-8,2);glVertex2i(-4,2);

glVertex2f(-4,0);glVertex2i(-4,5);

glVertex2f(6,0);glVertex2i(6,5);

glVertex2f(-4,5);glVertex2i(2,5);

glVertex2f(2,0);glVertex2i(2,-3);

glVertex2f(4,-6);glVertex2i(4,-3);

glVertex2f(-2,-3);glVertex2i(-2,2);

glVertex2f(-2,2);glVertex2i(4,2);

glVertex2f(4,2);glVertex2i(4,5);

glEnd();

glPopMatrix();

glutSwapBuffers();}

void actualizar (){

if(persona_y > -0.3f&& pos < 401){

persona_y -=0.05;

pos +=4;

if(persona_x <= 0.9f && pos >= 400 && pos < 701 ){

persona_x += 0.02;

pos +=3;

if(persona_y> 0.3f && pos >= 700 && pos <= 1000){

persona_y += 0.03;

pos +=3;

}
if(persona_x < 1.5f && pos >= 1000 && pos <= 1300){

persona_x += 0.05;

pos +=2;

if(persona_y > 1.3f && pos >= 1300 && pos <= 1600){

persona_y -=0.05;

pos +=4;

if(persona_x > -4.9f && pos >= 1600 && pos <= 1901){

persona_x -= 0.05;

pos +=3;

if(persona_y > -1.9f && pos >= 1901 && pos <= 2201){

persona_y -= 0.05;

pos +=2;

if(persona_x > -1.9f && pos >= 2201 && pos <= 2802){

persona_x -= 0.05;

pos +=3;

/*if(persona_x < -1 && pos >= 2802 && pos <= 3103){

persona_x += 0.01;

pos +=1;

if(persona_y > -7 && pos >=3103 && pos <= 3303){

persona_x -= 0.1;

pos +=1;

}
if(persona_x > -7 && pos >= 3303 && pos <= 3904){

persona_x -= 0.1;

pos +=1;

if(persona_y < 1 && pos >= 3904 && pos <= 4705){

persona_y += 0.1;

pos +=1;

if(persona_x > -8 && pos >= 4705){

persona_x -= 0.1;

pos +=1;

}*/

glutPostRedisplay();

void teclado (unsigned char tecla, int x, int y){

switch(tecla){

case 'w':

glutIdleFunc(actualizar);

break;

case 's':

glutIdleFunc(actualizar);

break;

case 'a':

glutIdleFunc(actualizar);

break;

case 'd':
glutIdleFunc(actualizar);

break;

void teclado_especial(int tecla, int x, int y){

if(tecla == GLUT_KEY_RIGHT){

glutIdleFunc(actualizar);

if(tecla == GLUT_KEY_LEFT){

glutIdleFunc(actualizar);

if(tecla == GLUT_KEY_DOWN){

glutIdleFunc(actualizar);

if(tecla == GLUT_KEY_UP){

glutIdleFunc(actualizar);

int main(int argc, char **argv){

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);

glutInitWindowSize(500,500);

glutInitWindowPosition(0,0);

glutCreateWindow("LABERINTO");

iniciar();

glutDisplayFunc(dibujar);

glutKeyboardFunc(teclado);
glutSpecialFunc(teclado_especial);

glutMainLoop();

return 0;}

PARA HACER CORRER EL LABERINTO

You might also like