/******************************************************************** File: brickbreak.h Author: Dana Vrajitoru Project: A simple 2D animation program based on the Breakout game. Last updated: February 3, 2011. The interface of the program, keeping all the objects together and definisng their interaction. ********************************************************************/ #include #include #include "ball.h" #include "brickbreak.h" const float bwidth = 100, bheight = 100, rad = 2; Ball the_ball(rad); // Draws all the objects in the scene void draw() { glClear(GL_COLOR_BUFFER_BIT); the_ball.draw(); glutSwapBuffers(); } // Moves all the objects in the scene void move() { the_ball.move(); if (the_ball.y < -rad) glutIdleFunc(NULL); glutPostRedisplay(); } // 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); case '1': glutPostRedisplay(); break; } } // Callback function for a special key being pressed void spkey(int key, int x, int y) { switch (key) { case GLUT_KEY_LEFT: glutPostRedisplay(); break; case GLUT_KEY_RIGHT: glutPostRedisplay(); break; } } // Initializes all the objects with their initial positions. void reset_obj() { the_ball.set_box(bwidth, bheight); the_ball.move_to(bwidth/2, rad); //the_ball.set_speed(1, 1); the_ball.randomize_speed(2); } // Application parameters void myinit() { reset_obj(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, bwidth, 0, bheight); glMatrixMode(GL_MODELVIEW); glClearColor (0, 0, 0, 1.0); glColor3f(1.0,0.0,0.0); //glLineWidth(2); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL); }