-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBallDemo.cpp
110 lines (94 loc) · 2.33 KB
/
BallDemo.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
author: S. M. Shahriar Nirjon
last modified: August 8, 2008
*/
# include "iGraphics.h"
# include "gl.h"
int ball_x, ball_y;
int dx, dy;
/*
function iDraw() is called again and again by the system.
*/
void iDraw()
{
//place your drawing codes here
iClear();
iSetColor(255, 100, 10);
iFilledCircle(ball_x, ball_y, 7);
iSetColor(255, 255, 255);
iText(10, 10, "Press p for pause, r for resume, END for exit.");
}
/*
function iMouseMove() is called when the user presses and drags the mouse.
(mx, my) is the position where the mouse pointer is.
*/
void iMouseMove(int mx, int my)
{
//place your codes here
}
/*
function iMouse() is called when the user presses/releases the mouse.
(mx, my) is the position where the mouse pointer is.
*/
void iMouse(int button, int state, int mx, int my)
{
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
//place your codes here
}
if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
{
//place your codes here
}
}
/*
function iKeyboard() is called whenever the user hits a key in keyboard.
key- holds the ASCII value of the key pressed.
*/
void iKeyboard(unsigned char key)
{
if(key == 'p')
{
//do something with 'q'
iPauseTimer(0);
}
if(key == 'r')
{
iResumeTimer(0);
}
//place your codes for other keys here
}
/*
function iSpecialKeyboard() is called whenver user hits special keys like-
function keys, home, end, pg up, pg down, arraows etc. you have to use
appropriate constants to detect them. A list is:
GLUT_KEY_F1, GLUT_KEY_F2, GLUT_KEY_F3, GLUT_KEY_F4, GLUT_KEY_F5, GLUT_KEY_F6,
GLUT_KEY_F7, GLUT_KEY_F8, GLUT_KEY_F9, GLUT_KEY_F10, GLUT_KEY_F11, GLUT_KEY_F12,
GLUT_KEY_LEFT, GLUT_KEY_UP, GLUT_KEY_RIGHT, GLUT_KEY_DOWN, GLUT_KEY_PAGE UP,
GLUT_KEY_PAGE DOWN, GLUT_KEY_HOME, GLUT_KEY_END, GLUT_KEY_INSERT
*/
void iSpecialKeyboard(unsigned char key)
{
if(key == GLUT_KEY_END)
{
exit(0);
}
//place your codes for other keys here
}
void ballChange(){
ball_x += dx;
ball_y += dy;
if(ball_x > 400 || ball_x < 0)dx = -dx;
if(ball_y > 400 || ball_y < 0)dy = -dy;
}
int main()
{
// PlaySound((LPCSTR) "C:\\Users\\Public\\Music\\Sample Music\\Sleep Away.mp3", NULL, SND_FILENAME | SND_ASYNC);
// DWORD dwError = GetLastError();
//place your own initialization codes here.
iSetTimer(5, ballChange);
dx = 5;
dy = 7;
iInitialize(400, 400, "Ball Demo");
return 0;
}