/******************************************************************** File: brickbreak.cc Author: Dana Vrajitoru Project: A simple 2D animation program based on the Breakout game. Last updated: February 6, 2017. The interface of the program, keeping all the objects together and definisng their interaction. ********************************************************************/ #include #include "glheader.h" #include "Ball.h" #include "brickbreak.h" int winWidth = 500, winHeight = 500; const float bwidth = 100, bheight = 100, rad = 2; Ball theBall(rad); // Draws all the objects in the scene void draw() { glClear(GL_COLOR_BUFFER_BIT); theBall.draw(); glutSwapBuffers(); } // Moves all the objects in the scene void move() { theBall.move(); if (theBall.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 resetObj() { theBall.setBox(bwidth, bheight); theBall.jumpTo(bwidth/2, rad); //theBall.set_speed(1, 1); theBall.randomizeSpeed(2); } // Application parameters void myinit() { resetObj(); 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); } // Initialize the window and the GUI callbacks void initWindowGui() { glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGB ); glutInitWindowSize(winWidth, winHeight); glutCreateWindow("Breakout"); glutDisplayFunc(draw); glutIdleFunc(move); glutKeyboardFunc(key); //glutSpecialFunc(spkey); //glutMouseFunc(mouse); } // To be called whenever the window is resized. void myResize(int w, int h) { winWidth = w; winHeight = h; glViewport(0, 0, w, h); }