-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
61 lines (59 loc) · 1.57 KB
/
main.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
#include "move.cpp"
void mainDisplay()
{
backGround();
display();
}
//move player using keyboard
void key(int key,int x,int y)
{
if(key==GLUT_KEY_RIGHT && player.head.Xc<(w-headRadius))
{
player.head.Xc += 0.26*Xspeed;
}
if(key==GLUT_KEY_LEFT && player.head.Xc>(headRadius))
{
player.head.Xc -= 0.26*Xspeed;
}
glutPostRedisplay();
}
//Changing of gamestate using keyboard
void keyboard(unsigned char key,int x,int y)
{
switch(key)
{
case 'S':
case 's': if(game_state==menu){game_state=play;}
break;
case 'q':
case 'Q':
case 'E':
case 'e': if(game_state==menu || game_state==play){game_state=gameexit;}
break;
case 'P':
case 'p':if(game_state==play){game_state=pause;}
break;
case '1': if(game_state==pause){game_state=play;}
break;
case '2': if(game_state==pause || game_state==over){game_state=menu;}
break;
case '3': if(game_state==pause || game_state==over){game_state=gameexit;}
break;
}
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(1350,720);
glutInitWindowPosition(0,0);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("COIN COLLECTING GAME");
glutDisplayFunc(mainDisplay);
glutIdleFunc(display);
glutReshapeFunc(reshape);
glutTimerFunc(16,Timer,0);
glutKeyboardFunc(keyboard);
glutSpecialFunc(key);
glutMainLoop();
return EXIT_SUCCESS;
}