00001
00008 #include "Quaxbomber.h"
00009 #include "GameArea.h"
00010 #include "GameTile.h"
00011 #include "CoveredGameTileModel.h"
00012 #include "UncoveredGameTileModel.h"
00013
00014 #include <gl/gl.h>
00015 #include <gl/glu.h>
00016 #include <gl/glut.h>
00017
00018
00019 #include <iostream>
00020 #include <math.h>
00021 #include <time.h>
00022
00023 using namespace std;
00024
00025
00026 void display(void);
00027 void initGL(void);
00028 void setViewpoint(GLfloat radius, GLfloat rotX, GLfloat rotY);
00029
00030
00031
00032 GLint angleX = STARTANGLE;
00033
00034 GLfloat angleY = STARTANGLE;
00035
00036 GameArea *gA;
00037
00046 void setViewpoint(GLfloat radius, GLfloat rotX, GLfloat rotY) {
00047
00048 glTranslated(0.0, 0.0, -radius);
00049
00050 glRotatef(-rotX, 1.0, 0.0, 0.0);
00051
00052 glRotatef(rotY, 0.0, 1.0, 0.0);
00053 }
00054
00055
00059 void display(void) {
00060 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00061 glLoadIdentity();
00062
00063 setViewpoint(CAMRADIUS, angleX, angleY);
00064 glTranslatef((GLfloat)-TILESOFFSET, 0.0f, (GLfloat)-TILESOFFSET);
00065 gA->renderGameArea();
00066 glutSwapBuffers();
00067 }
00068
00069
00070
00071 void reshape (int w, int h) {
00072
00073
00074 glViewport (0, 0, (GLsizei) w, (GLsizei) h);
00075
00076
00077 glMatrixMode (GL_PROJECTION);
00078 glLoadIdentity ();
00079 gluPerspective(60, (GLdouble)w/h, 1.5, 30.0);
00080
00081 glMatrixMode (GL_MODELVIEW);
00082 glLoadIdentity();
00083 }
00084
00088 void initGL (void) {
00089 glClearColor (0.0, 0.0, 0.0, 0.0);
00090 glEnableClientState(GL_VERTEX_ARRAY);
00091 glEnableClientState(GL_COLOR_ARRAY);
00092
00093 glShadeModel(GL_SMOOTH);
00094 glEnable(GL_DEPTH_TEST);
00095 }
00096
00097
00101 void keyEvent(unsigned char key, int x, int y) {
00102 long s;
00103 srand(time(&s));
00104 int a = (rand()) % (gA->dim);
00105 int b = (rand()) % (gA->dim);
00106
00107 switch(key) {
00108 case 'b':
00109 gA->uncoverTile(a, b);
00110 cout << "x, y: " << a << ", " << b << endl;
00111 break;
00112 case 27:
00113 exit(0);
00114 break;
00115 default:
00116 break;
00117 }
00118 }
00119
00120
00121
00125 int main(int argc, char** argv) {
00126 gA = new GameArea(GameArea::EASY);
00127 gA -> debugArrays(true, true, true);
00128 glutInit(&argc, argv);
00129 glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
00130 glutInitWindowSize (800, 600);
00131 glutInitWindowPosition (100, 100);
00132 glutCreateWindow ("Quaxbomber 0.1");
00133 initGL();
00134 glutDisplayFunc(display);
00135 glutReshapeFunc(reshape);
00136 glutKeyboardFunc(keyEvent);
00137 glutMainLoop();
00138 return 0;
00139 }