-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.cpp
182 lines (158 loc) · 3.37 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <floppy.h>
#include <vector>
#include <math.h>
#include <string.h>
using namespace std;
double queuedMilliseconds,prev0,fps,responseTime;
int resX,resY,movementX,startFlag,god;
double movementY;
//... Reshaping settings & rendering parameters.
void reshape(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glOrtho(0,resX,0,resY,-5,10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//.... Keyboard input and movement physics
vector<char> inputKey;
double g,v,tmp2;
int cnt;
void gameoverAnimation()
{
inputKey.push_back('U');
v=1.2;
}
void movePhysics()
{
unsigned int ii;
g=10;
for(ii=0;ii<inputKey.size();ii++)
{
if(inputKey[ii]=='U')
{
if((movementY+(resY/2)+50)<resY)
movementY+=4;
cnt++;
}
if(cnt>=10)
{
cnt=0;
inputKey.erase(inputKey.begin()+ii);
}
}
if(startFlag==1)
{
//...GRAVITY
if(inputKey.size()==0)
{
// 0.021125
if(gameover==0)
{
tmp2=resY/2;
v=0.65+(abs(movementY)/tmp2)/5;
}
else
{
if( (inputKey.size()==0 ) && (movementY <- (resY/2) ) )
{
gameover=0;
resetFunc();
}
}
if( (movementY<-(resY/2-30)) )
{
if(god==0)
movementY-= v*v/2*g;
}
else
movementY-= v*v/2*g;
}
}
}
int godcnt,abcindex;
char abc[13];
void keyboard (unsigned char key, int x, int y)
{
if(key==32)
startFlag=1;
else
abc[abcindex++]=key;
switch (key) {
case 27:
exit(0);
break;
case 32:
if(gameover==0)
inputKey.push_back('U');
break;
}
if(abcindex==13)
{
if(strcmp(abc,"rocksdanister")==0)
god=1;
else
abcindex=0;
}
}
//... keyboard input end.
int main(int argc, char** argv)
{
//..frame-update setup
queuedMilliseconds=0;
prev0=0;
fps=60;
responseTime=(1/fps)*1000;
//... Rendering resoultion
resX=854;resY=480;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutGameModeString("10x10");
display_test:
if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
glutEnterGameMode();
else {
printf("Select Screen Resolution, if you are unsure select Window mode\n"
"1. 1920x1080\n2. 1600x900\n3. 1280x720\n4. 1368x768 \n"
"5. 1366x768 \n6. 800x600\n7. 640x480\n8. Window(try to avoid this!)");
int ch;
scanf("%d",&ch);
if(ch==8)
{
printf("\n*WARNING: The selected resolution not available, "
"Enter xrandr in terminal.\nChange parameter in glutGameModeString to available resolution in xrandr.\n"
"Currently running in windowmode.\nVsync may not perform correctly resulting in poor performance.\n");
glutInitWindowSize(1280, 720);
glutCreateWindow("Floppy Bird");
glutFullScreen();
}
else if(ch==1)
glutGameModeString("1920x1080");
else if(ch==2)
glutGameModeString("1600x900");
else if(ch==3)
glutGameModeString("1280x720");
else if(ch==4)
glutGameModeString("1368x768");
else if(ch==5)
glutGameModeString("1366x768");
else if(ch==6)
glutGameModeString("800x600");
else
glutGameModeString("640x480");
if(ch!=8)
goto display_test;
}
glutIgnoreKeyRepeat(1);
glutDisplayFunc(draw);
glutIdleFunc(mixedStepLoop);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}