Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <GL/glut.h>
- #include <iostream>
- using namespace std;
- #define FPS 60
- enum MENU_TYPE
- {
- MENU_START,
- MENU_EXIT,
- };
- GLint count_timer = 0;
- int i;
- int timestep = 0;
- float gravity = 0.0098;
- float velo = 0.0f;
- int view_pos = 0;
- int game_w = 400;
- int game_h = 700;
- float square_x1 = -0.06;
- float square_x2 = 0.06;
- float square_y1 = 1;
- float square_y2 = 0.9;
- int a = 0;
- float x_left[] = { -0.2,-0.1,0.0,-0.1,-0.2,-0.3,-0.2,-0.1,0.0,-0.1,-0.2,-0.3,-0.2,-0.1,0.0,-0.1,-0.2,-0.1 };
- float y_left[] = { 0.7,0.6,0.5,0.4,0.3,0.2,0.1,0.0,-0.1,-0.2,-0.3,-0.4,-0.5,-0.6,-0.7,-0.8,-0.9,-1.0 };
- float x_right[] = { 0.1,0.2,0.3,0.2,0.1,0.0,0.1,0.2,0.3,0.2,0.1,0.0,0.1,0.2,0.3,0.2,0.1,0.0 };
- float y_right[] = { 0.7,0.6,0.5,0.4,0.3,0.2,0.1,0.0,-0.1,-0.2,-0.3,-0.4,-0.5,-0.6,-0.7,-0.8,-0.9,-1.0 };
- float timerC[] = { 18,28,38,48,58,68,78,88,98,108,118,128,138,148,158,168,178,198,208 };
- GLfloat xstep = 0.1f;
- GLfloat ystep = 0.01f;
- void background() {
- glBegin(GL_QUADS); // Each set of 4 vertices form a quad
- glColor3f(0.0f, 0.1, 0.1); //new1
- glVertex2f(-1.0f, 0.6f);
- glVertex2f(-0.2f, 0.6f);
- glVertex2f(-0.2f, 0.7f);
- glVertex2f(-1.0f, 0.7f);
- glColor3f(0.0f, 0.1, 0.1); //new1.1
- glVertex2f(0.1f, 0.6f);
- glVertex2f(1.0f, 0.6f);
- glVertex2f(1.0f, 0.7f);
- glVertex2f(0.1f, 0.7f);
- glColor3f(0.0f, 0.2, 0.2); //new2
- glVertex2f(-1.0f, 0.5f);
- glVertex2f(-0.1f, 0.5f);
- glVertex2f(-0.1f, 0.6f);
- glVertex2f(-1.0f, 0.6f);
- glColor3f(0.0f, 0.2, 0.2); //new2.1
- glVertex2f(0.2f, 0.5f);
- glVertex2f(1.0f, 0.5f);
- glVertex2f(1.0f, 0.6f);
- glVertex2f(0.2f, 0.6f);
- glColor3f(0.0f, 0.3, 0.3); //new3
- glVertex2f(-1.0f, 0.4f);
- glVertex2f(0.0f, 0.4f);
- glVertex2f(0.0f, 0.5f);
- glVertex2f(-1.0f, 0.5f);
- glColor3f(0.0f, 0.4, 0.4); //new3.1
- glVertex2f(0.3f, 0.4f);
- glVertex2f(1.0f, 0.4f);
- glVertex2f(1.0f, 0.5f);
- glVertex2f(0.3f, 0.5f);
- glColor3f(0.0f, 0.5, 0.5); //new4
- glVertex2f(-1.0f, 0.3f);
- glVertex2f(-0.1f, 0.3f);
- glVertex2f(-0.1f, 0.4f);
- glVertex2f(-1.0f, 0.4f);
- glColor3f(0.0f, 0.5, 0.5); //new4.1
- glVertex2f(0.2f, 0.3f);
- glVertex2f(1.0f, 0.3f);
- glVertex2f(1.0f, 0.4f);
- glVertex2f(0.2f, 0.4f);
- glColor3f(0.0f, 0.6, 0.6); //new5
- glVertex2f(-1.0f, 0.2f);
- glVertex2f(-0.2f, 0.2f);
- glVertex2f(-0.2f, 0.3f);
- glVertex2f(-1.0f, 0.3f);
- glColor3f(0.0f, 0.6, 0.6); //new5.1
- glVertex2f(0.1f, 0.2f);
- glVertex2f(1.0f, 0.2f);
- glVertex2f(1.0f, 0.3f);
- glVertex2f(0.1f, 0.3f);
- glColor3f(0.0f, 0.7, 0.7); //new6
- glVertex2f(-1.0f, 0.1f);
- glVertex2f(-0.3f, 0.1f);
- glVertex2f(-0.3f, 0.2f);
- glVertex2f(-1.0f, 0.2f);
- glColor3f(0.0f, 0.7, 0.7); //new6.1
- glVertex2f(0.0f, 0.1f);
- glVertex2f(1.0f, 0.1f);
- glVertex2f(1.0f, 0.2f);
- glVertex2f(0.0f, 0.2f);
- glColor3f(0.0f, 0.8, 0.8); //new7 00 coordinates
- glVertex2f(-1.0f, 0.0f);
- glVertex2f(-0.2f, 0.0f);
- glVertex2f(-0.2f, 0.1f);
- glVertex2f(-1.0f, 0.1f);
- glColor3f(0.0f, 0.8, 0.8); //new7.1
- glVertex2f(0.1f, 0.0f);
- glVertex2f(1.0f, 0.0f);
- glVertex2f(1.0f, 0.1f);
- glVertex2f(0.1f, 0.1f);
- glColor3f(0.0f, 0.9, 0.9); //new8
- glVertex2f(-1.0f, -0.1f);
- glVertex2f(-0.1f, -0.1f);
- glVertex2f(-0.1f, 0.0f);
- glVertex2f(-1.0f, 0.0f);
- glColor3f(0.0f, 0.9, 0.9); //new8.1
- glVertex2f(0.2f, -0.1f);
- glVertex2f(1.0f, -0.1f);
- glVertex2f(1.0f, 0.0f);
- glVertex2f(0.2f, 0.0f);
- glColor3f(0.0f, 1.0, 1.0); //new9
- glVertex2f(-1.0f, -0.2f);
- glVertex2f(0.0f, -0.2f);
- glVertex2f(0.0f, -0.1f);
- glVertex2f(-1.0f, -0.1f);
- glColor3f(0.0f, 1.0, 1.0); //new9.1
- glVertex2f(0.3f, -0.2f);
- glVertex2f(1.0f, -0.2f);
- glVertex2f(1.0f, -0.1f);
- glVertex2f(0.3f, -0.1f);
- glColor3f(0.0f, 0.9, 0.9); //new10
- glVertex2f(-1.0f, -0.3f);
- glVertex2f(-0.1f, -0.3f);
- glVertex2f(-0.1f, -0.2f);
- glVertex2f(-1.0f, -0.2f);
- glColor3f(0.0f, 0.9, 0.9); //new10
- glVertex2f(0.2f, -0.3f);
- glVertex2f(1.0f, -0.3f);
- glVertex2f(1.0f, -0.2f);
- glVertex2f(0.2f, -0.2f);
- glColor3f(0.0f, 0.8, 0.8); //new11
- glVertex2f(-1.0f, -0.4f);
- glVertex2f(-0.2f, -0.4f);
- glVertex2f(-0.2f, -0.3f);
- glVertex2f(-1.0f, -0.3f);
- glColor3f(0.0f, 0.8, 0.8); //new11.1
- glVertex2f(0.1f, -0.4f);
- glVertex2f(1.0f, -0.4f);
- glVertex2f(1.0f, -0.3f);
- glVertex2f(0.1f, -0.3f);
- glColor3f(0.0f, 0.7, 0.7); //new12
- glVertex2f(-1.0f, -0.5f);
- glVertex2f(-0.3f, -0.5f);
- glVertex2f(-0.3f, -0.4f);
- glVertex2f(-1.0f, -0.4f);
- glColor3f(0.0f, 0.7, 0.7); //new12.1
- glVertex2f(0.0f, -0.5f);
- glVertex2f(1.0f, -0.5f);
- glVertex2f(1.0f, -0.4f);
- glVertex2f(0.0f, -0.4f);
- glColor3f(0.0f, 0.6, 0.6); //new13
- glVertex2f(-1.0f, -0.6f);
- glVertex2f(-0.2f, -0.6f);
- glVertex2f(-0.2f, -0.5f);
- glVertex2f(-1.0f, -0.5f);
- glColor3f(0.0f, 0.6, 0.6); //new13.1
- glVertex2f(0.1f, -0.6f);
- glVertex2f(1.0f, -0.6f);
- glVertex2f(1.0f, -0.5f);
- glVertex2f(0.1f, -0.5f);
- glColor3f(0.0f, 0.5, 0.5); //new14
- glVertex2f(-1.0f, -0.7f);
- glVertex2f(-0.1f, -0.7f);
- glVertex2f(-0.1f, -0.6f);
- glVertex2f(-1.0f, -0.6f);
- glColor3f(0.0f, 0.5, 0.5); //new14.1
- glVertex2f(0.2f, -0.7f);
- glVertex2f(1.0f, -0.7f);
- glVertex2f(1.0f, -0.6f);
- glVertex2f(0.2f, -0.6f);
- glColor3f(0.0f, 0.4, 0.4); //new15
- glVertex2f(-1.0f, -0.8f);
- glVertex2f(0.0f, -0.8f);
- glVertex2f(0.0f, -0.7f);
- glVertex2f(-1.0f, -0.7f);
- glColor3f(0.0f, 0.4, 0.4); //new15.1
- glVertex2f(0.3f, -0.8f);
- glVertex2f(1.0f, -0.8f);
- glVertex2f(1.0f, -0.7f);
- glVertex2f(0.3f, -0.7f);
- glColor3f(0.0f, 0.3, 0.3); //new16
- glVertex2f(-1.0f, -0.9f);
- glVertex2f(-0.1f, -0.9f);
- glVertex2f(-0.1f, -0.8f);
- glVertex2f(-1.0f, -0.8f);
- glColor3f(0.0f, 0.3, 0.3); //new16.1
- glVertex2f(0.2f, -0.9f);
- glVertex2f(1.0f, -0.9f);
- glVertex2f(1.0f, -0.8f);
- glVertex2f(0.2f, -0.8f);
- glColor3f(0.0f, 0.2, 0.2); //new17
- glVertex2f(-1.0f, -1.0f);
- glVertex2f(-0.2f, -1.0f);
- glVertex2f(-0.2f, -0.9f);
- glVertex2f(-1.0f, -0.9f);
- glColor3f(0.0f, 0.2, 0.2); //new17.1
- glVertex2f(0.1f, -1.0f);
- glVertex2f(1.0f, -1.0f);
- glVertex2f(1.0f, -0.9f);
- glVertex2f(0.1f, -0.9f);
- glEnd();
- glutPostRedisplay();
- glFlush(); // Render now
- }
- void drawText(const char *text, int length, int x, int y) {
- glMatrixMode(GL_PROJECTION);
- double *matrix = new double[16];
- glGetDoublev(GL_PROJECTION_MATRIX, matrix);
- glLoadIdentity();
- glOrtho(0, 800, 0, 600, -5, 5);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glPushMatrix();
- glLoadIdentity();
- glRasterPos2i(x, y);
- for (int k = 0; k < length; k++) {
- glutBitmapCharacter(GLUT_BITMAP_9_BY_15, (int)text[k]);
- }
- glPopMatrix();
- glMatrixMode(GL_PROJECTION);
- glLoadMatrixd(matrix);
- glMatrixMode(GL_MODELVIEW);
- }
- float index = 0.8f;
- void TimerFunction(int value)
- {
- square_y1 -= 0.002;
- square_y2 -= 0.002;
- // Control time
- count_timer++;
- for (i = 0; i < 16; i++) {
- if (count_timer >= timerC[i] & count_timer < timerC[i + 1]) {
- if (square_x1 < x_left[i]) {
- printf("Left Collision.\n");
- printf("Final score : %d", count_timer);
- getchar();
- exit(0);
- }
- else if (square_x2 > x_right[i]) {
- printf("Right collision.\n");
- printf("Final score : %d", count_timer);
- getchar();
- exit(0);
- }
- }
- }
- // Actually move the square
- index -= ystep;
- //Redraw the scene with new coordinates
- glutPostRedisplay();
- glutTimerFunc(50, TimerFunction, 1); //The rectangle moves every 33 seconds..1 is for enable the function
- }
- void display() {
- velo += 1.7;
- //glClear(GL_COLOR_BUFFER_BIT);
- background();
- glColor3f(0.0, 0.5, 0.5); //new17
- glRectd(square_x1, index, square_x2, index + 0.06);
- //index -= 0.00007;
- std::string text;
- text = "Dancing Lines";
- glColor3f(0, 0.5, 0.2);
- drawText(text.data(), text.size(), 490, 580);
- //glViewport(0, -game_h / 2 + velo, game_w, game_h);
- glutSwapBuffers();
- //glFlush(); // Render now
- }
- void SpecialKeys(int key, int x, int y) {
- if (key == GLUT_KEY_LEFT) {
- square_x1 -= 0.10;
- square_x2 -= 0.10;
- }
- if (key == GLUT_KEY_RIGHT) {
- square_x1 += 0.10;
- square_x2 += 0.10;
- }
- glutPostRedisplay();
- }
- float epsilon = 0.01;
- void timer_callback(int) {
- glutPostRedisplay();
- glutTimerFunc(1000 / FPS, timer_callback, 0);
- }
- // Main function: GLUT runs as a Console Application
- int main(int argc, char** argv) {
- glutInit(&argc, argv); // Initialize GLUT
- glutInitWindowSize(game_w, game_h); // Set the initial Window's width and height
- glutInitWindowPosition(50, 50); // Position the initial Window's top-left corner
- glutCreateWindow("Marcin & Srison"); // Create window with the given title
- glutSpecialFunc(SpecialKeys);
- glutTimerFunc(100, TimerFunction, 1);
- glutDisplayFunc(display); // Register callback handler for window re-paint event
- //initGL(); // Our own OpenGL initialization
- glutMainLoop(); // Enter infinitely event-processing loop
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement