/******************************************************************** File: interface.cc Author: Dana Vrajitoru Description: Bringing the maze together. Project: A sprite moving through a maze application. Last updated: February 10, 2011. ********************************************************************/ #include #include #include "bus.h" #include "maze.h" #include "interface.h" const int vieww = 8, viewh = 6; int viewoffx = -1, viewoffy=-1; Bus the_bus; Maze the_maze; // Draws all the objects in the scene void draw() { glClear(GL_COLOR_BUFFER_BIT); glClearColor (0, 0.1, 0, 1.0); glPushMatrix(); glTranslatef(float(viewoffx), float(viewoffy), 0); the_maze.draw(); the_bus.draw(); glPopMatrix(); glutSwapBuffers(); } // Callback function for an Ascii key being pressed void key(unsigned char key, int x, int y) { switch (key) { case 'q': case 'Q': exit(0); } } // Moves the bus in the given direction. If the move ends up in a // wall, the bus is turned back. void move_bus(Direction where) { the_bus.move(where); if (the_maze.table[int(the_bus.x)][int(the_bus.y)] == wallCl) the_bus.move(opposite(where)); } // Callback function for a special key being pressed void spkey(int key, int x, int y) { switch (key) { case GLUT_KEY_LEFT: move_bus(west); glutPostRedisplay(); break; case GLUT_KEY_RIGHT: move_bus(east); glutPostRedisplay(); break; case GLUT_KEY_UP: move_bus(north); glutPostRedisplay(); break; case GLUT_KEY_DOWN: move_bus(south); glutPostRedisplay(); break; } } // Initializes all the objects with their initial positions. void init_obj() { the_bus.init(4, 1); the_maze.init(); } // Application parameters void myinit() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, vieww, 0, viewh); glMatrixMode(GL_MODELVIEW); glClearColor (0, 0.1, 0, 1.0); glColor3f(1.0,0.0,0.0); glLineWidth(2); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); init_obj(); }