void collision_bug_one(float x, float y)
{
glEnable(GL_TEXTURE_2D);//collision sprite
glBindTexture(GL_TEXTURE_2D, _textureId_four);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_POLYGON);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(x, y, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(x, y-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(x+1.0f, y-1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(x+1.0f, y, 0.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void collision(int value)
{
flag[0][0] = 1;
glutTimerFunc(1000, collision, 5);
}
void coll_bug_one()
{
float x = -0.5f + scroll;
float y = -8.0f + up;
float oWidth = 0.5f;
float oHeight = 0.5f;
float xTwo = -2.0f;
float yTwo = 9.0f;
float oTwoWidth = 0.5f;
float oTwoHeight = 0.5f;
if (checkCollide(x, y, oWidth, oHeight, xTwo, yTwo, oTwoWidth, oTwoHeight) == 1)
{
collision_bug_one(-2.0f, 10.0f);
Sleep(50);
glutTimerFunc(25, collision, 5);
}
}
void erase_sprite()
{
if (flag[0][0] == 1)
{
glColor3f(0.0f, 0.0f, 0.0f);
glBegin(GL_POLYGON);
glVertex3f(-2.0f, 10.0f, 0.0f);
glVertex3f(-2.0f, 9.0f, 0.0f);
glVertex3f(-1.0f, 9.0f, 0.0f);
glVertex3f(-1.0f, 10.0f, 0.0f);
glEnd();
}
}
void delay()
{
float velocity = 20.0f, init_position = 0.0f;
static int prvMs = glutGet(GLUT_ELAPSED_TIME);
drawScene_bug_two(position, 10.0f);
const int curMs = glutGet(GLUT_ELAPSED_TIME);
const double dt = (curMs - prvMs) / 1000.0;
prvMs = curMs;
position = velocity*dt + init_position;
cout << position << endl;
}
void move(int v)
{
move_right++;
if (move_right >= 9.0f)
{
move_right = 9.0f;
}
drawScene_bug_two(move_right, 10.0f);
glutPostRedisplay();
glutTimerFunc(1000, move, 0);
}
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT);
bullet();
drawScene_bug_one(-2.0f, 10.0f);
move(0);
glutTimerFunc(1000, move, 0);
coll_bug_one();
erase_sprite();
drawScene_ship_one();
glutSwapBuffers();
}
void shoot()
{
up += 0.5f;
if (up >= 17.5f)
{
animate = 0;
up = move_up;
glutIdleFunc(NULL);
}
glutPostRedisplay();
}
void handleKeypress(unsigned char key, int x, int y) {
switch (key) {
case 27: //Escape key
exit(0);
break;
case 32:
animate = !animate;
if (animate)
{
glutIdleFunc(shoot);
}
else
{
glutIdleFunc(NULL);
}
break;
}
glutPostRedisplay();
}
void handleSpecialKeypress(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_UP:
move_up += 0.1f;
break;
case GLUT_KEY_DOWN:
move_up -= 0.1f;
if (move_up <= 0.0f)
{
move_up = 0.0f;
}
break;
case GLUT_KEY_LEFT:
scroll -= 0.1f;
if (scroll <= -9.0f)
{
scroll = -9.0f;
}
break;
case GLUT_KEY_RIGHT:
scroll += 0.1f;
if (scroll >= 9.0f)
{
scroll = 9.0f;
}
break;
}
glutPostRedisplay();
}
void update(int value)
{
down -= 0.1f;
if (down <= -20.0f)
{
down = 0.0f;
}
glutPostRedisplay();
glutTimerFunc(25, update, 0);
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(500, 200);
glutInitWindowSize(800, 600);
glutCreateWindow("Bug Wars");
initRendering();
initRendering_two();
initRendering_three();
initRendering_four();
initRendering_five();
glutDisplayFunc(drawScene);
glutTimerFunc(25, update, 0);
// glutTimerFunc(1000, move, 5);
glutKeyboardFunc(handleKeypress);
glutSpecialFunc(handleSpecialKeypress);
glutReshapeFunc(handleResize);
glutMainLoop();
return 0;
}
well here is more of my code