-
Notifications
You must be signed in to change notification settings - Fork 2
/
breakout.cpp
89 lines (66 loc) · 1.69 KB
/
breakout.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<iostream>
#include<stdio.h>
#include<unistd.h>
using namespace std;
#include<GL/glut.h>
#include<GL/gl.h>
#include"gameObjects.hpp"
gameObjects game_objs;
void display();
void keyboard(unsigned char key, int x, int y){
switch(key){
//case GLUT_KEY_LEFT:
case 'a':// case '^[[D':
game_objs.left_pressed=true;
//game_objs.right_pressed=false;
break;
//case GLUT_KEY_RIGHT:
case 'd':// case '^[[C':
game_objs.right_pressed=true;
//game_objs.left_pressed=false;
break;
}
}
void keyboardUp(unsigned char key, int x, int y){
switch(key){
case ' ':
game_objs.ball.moving=true;
break;
case 'a':// case '^[[D':
game_objs.left_pressed=false;
break;
case 'd':// case '^[[C':
game_objs.right_pressed=false;
//game_objs.left_pressed=false;
break;
}
}
/*
void mouse(int x, int){
game_objs.movePaddleOnMouse((float)x/1000);
}
*/
int main(int argc, char * argv[]){
//initialize glut library
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(600,600);
glutInitWindowPosition(0,0);
glutCreateWindow("Atari Breakout!");
glClearColor(1.0f,1.0f,1.0f,1.0f);
glOrtho(-1.0f, +1.0f, -1.0f,+1.0f,1,1);
glutDisplayFunc(display);
glutIdleFunc(display);
glutKeyboardFunc(keyboard);
glutKeyboardUpFunc(keyboardUp);
//glutPassiveMotionFunc(mouse);
glutMainLoop();
return 0;
}
void display(){
usleep(10000);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//draw here
game_objs.draw();
glutSwapBuffers();
}