#include <gl/glut.h>
#include <stdio.h>
#include <string.h>
#include<math.h>
float ttx=0;
float tty=0;
float ttz=0;
float tx=0;
float ty=0;
float tz=0;
float MoveBird1=0;
float MoveSmlShip=0;
float MoveBigShip = 0;
float MoveBomb=0;
bool gameOver = true;
int j,i,q;
void init(){
glClearColor( 0.00 , 0.00 ,0.61,0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,950,0,1000);
}
void drawText(char ch[],int xpos, int ypos)
{
int numofchar = strlen(ch);
glRasterPos2f( xpos , ypos);
for (i = 0; i <= numofchar - 1; i++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, ch[i]);
}
}
void drawBomb(){
glBegin(GL_POLYGON);
glColor3f( 0 , 0 , 0);
glVertex2f(125,550);
glVertex2f(125,600);
glVertex2f(225,600);
glVertex2f(225,550);
glVertex2f(175,600);
glVertex2f(290,650);
glVertex2f(270,680);
glVertex2f(250,610);
glEnd();
}
void drawSun(){
float x1,y1,x2,y2;
float angle;
double radius=150.0;
x1 = 450.0,y1=200.0;
glColor3f(1.0,1.0,0.0);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x1,y1);
glColor3f(0.98, 0.625, 0.12);
for (angle=1.0f;angle<361.0f;angle+=0.2)
{
x2 = x1+sin(angle)*radius;
y2 = y1+cos(angle)*radius;
glVertex2f(x2,y2);
}
glEnd();
}
void drawSea(){
glColor3f(0.196078 , 0.196078 ,0.8);
glBegin(GL_POLYGON);
glVertex2f(250,200);
glVertex2f(950,200);
glColor3f(0.0,0.7,1.0);
glVertex2f(950,0);
glVertex2f(250,0);
glColor3f(0.196078 , 0.196078 ,0.8);
glEnd();
}
void drawSky(){
glColor3f(0.00 , 0.00 ,0.61);
glBegin(GL_POLYGON);
glVertex2f(0,1000);
glVertex2f(950,1000);
glColor3f(0.00 , 0.00 ,0.61);
glVertex2f(950,550);
glVertex2f(0,550);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.00 , 0.00 ,0.61);
glVertex2f(250,550);
glVertex2f(950,550);
glColor3f( 0.74902 , 0.847059 , 0.847059);
glVertex2f(950,0);
glVertex2f(250,0);
glEnd();
}
void drawMountain(){
glBegin(GL_POLYGON);
glColor3f( 0.36 , 0.25 ,0.20);
glVertex2f(0,0);
glVertex2f(0,550);
glVertex2f(250,550);
glVertex2f(250,0);
glEnd();
}
void drawBigShip(){
glPushMatrix();
glTranslatef(tx-MoveBigShip,ty,tz);
glBegin(GL_POLYGON);
glColor3f(0.35 , 0.16 , 0.14);
glVertex2f(675,120);
glVertex2f(625,225);
glVertex2f(925,225);
glVertex2f(875,120);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.35 , 0.16 , 0.14);
glVertex2f(775,225);
glVertex2f(790,495);
glVertex2f(775,495);
glVertex2f(790,225);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0.91 , 0.76, 0.65);
glVertex2f(775,225);
glVertex2f(675,270);
glVertex2f(765,450);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0.91 , 0.76, 0.65);
glVertex2f(790,225);
glVertex2f(875,270);
glVertex2f(800,450);
glEnd();
glPopMatrix();
}
void drawSmallShip(){
glPushMatrix();
glTranslatef(MoveSmlShip,0,0);
glBegin(GL_POLYGON);
glColor3f(0.52 ,0.37 ,0.26);
glVertex2f(300,20);
glVertex2f(275,50);
glVertex2f(425,50);
glVertex2f(400,20);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0.92 , 0.78 , 0.62);
glVertex2f(275,60);
glVertex2f(350,120);
glVertex2f(425,60);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.52 ,0.37 ,0.26);
glVertex2f(350,50);
glVertex2f(350,80);
glVertex2f(355,80);
glVertex2f(355,50);
glEnd();
glPopMatrix();
}
void drawBird1(){
glPushMatrix();
glTranslatef(MoveBird1,0,0);
glBegin(GL_LINE_STRIP);
glColor3f(1.0 , 1.0 ,1.0);
glVertex2f(90,800);
glVertex2f(110,830);
glVertex2f(130,800);
glVertex2f(150,830);
glVertex2f(170,800);
glVertex2f(150,820);
glVertex2f(130,790);
glVertex2f(110,820);
glVertex2f(90,800);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(110,830,0);
glVertex3f(110,820,0);
glVertex3f(90,800,0);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(150,830,0);
glVertex3f(150,820,0);
glVertex3f(170,800,0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0 , 1.0 ,1.0);
glVertex2f(110,830);
glVertex2f(110,820);
glVertex2f(130,790);
glVertex2f(130,800);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0 , 1.0 ,1.0);
glVertex2f(130,800);
glVertex2f(150,830);
glVertex2f(150,820);
glVertex2f(130,790);
glEnd();
glPopMatrix();
glFlush();
}
void drawBird2(){
glPushMatrix();
glTranslatef(MoveBird1,0,0);
glBegin(GL_LINE_STRIP);
glColor3f(1.0 , 1.0 ,1.0);
glVertex2f(200,700);
glVertex2f(220,730);
glVertex2f(240,700);
glVertex2f(260,730);
glVertex2f(280,700);
glVertex2f(260,720);
glVertex2f(240,690);
glVertex2f(220,720);
glVertex2f(200,700);
glEnd();
glFlush();
glBegin(GL_TRIANGLES);
glColor3f(1.0 , 1.0 ,1.0);
glVertex3f(220,730,0);
glVertex3f(220,720,0);
glVertex3f(200,700,0);
glEnd();
glFlush();
glBegin(GL_TRIANGLES);
glColor3f(1.0 , 1.0 ,1.0);
glVertex3f(260,730,0);
glVertex3f(260,720,0);
glVertex3f(280,700,0);
glEnd();
glFlush();
glBegin(GL_POLYGON);
glColor3f(1.0 , 1.0 ,1.0);
glVertex2f(220,730);
glVertex2f(220,720);
glVertex2f(240,690);
glVertex2f(240,700);
glEnd();
glFlush();
glBegin(GL_POLYGON);
glColor3f(1.0 , 1.0 ,1.0);
glVertex2f(240,700);
glVertex2f(260,730);
glVertex2f(260,720);
glVertex2f(240,690);
glEnd();
glPopMatrix();
glFlush();
}
void drawBird3(){
glPushMatrix();
glTranslatef(MoveBird1,0,0);
glBegin(GL_LINE_STRIP);
glColor3f(1.0 , 1.0 ,1.0);
glVertex2f(300,900);
glVertex2f(320,930);
glVertex2f(340,900);
glVertex2f(360,930);
glVertex2f(380,900);
glVertex2f(360,920);
glVertex2f(340,890);
glVertex2f(320,920);
glVertex2f(300,900);
glEnd();
glFlush();
glBegin(GL_TRIANGLES);
glColor3f(1.0 , 1.0 ,1.0);
glVertex3f(320,930,0);
glVertex3f(320,920,0);
glVertex3f(300,900,0);
glEnd();
glFlush();
glBegin(GL_TRIANGLES);
glColor3f(1.0 , 1.0 ,1.0);
glVertex3f(360,930,0);
glVertex3f(360,920,0);
glVertex3f(380,900,0);
glEnd();
glFlush();
glBegin(GL_POLYGON);
glColor3f(1.0 , 1.0 ,1.0);
glVertex2f(320,930);
glVertex2f(320,920);
glVertex2f(340,890);
glVertex2f(340,900);
glEnd();
glFlush();
glBegin(GL_POLYGON);
glColor3f(1.0 , 1.0 ,1.0);
glVertex2f(340,900);
glVertex2f(360,930);
glVertex2f(360,920);
glVertex2f(340,890);
glEnd();
glPopMatrix();
glFlush();
}
void Translate()
{
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(5, 2, 0.0);
drawSmallShip();
glPopMatrix();
}
void drawBoom(){
float x1,y1,x2,y2;
float angle;
double radius=20.0;
x1 = 300,y1=670;
glPushMatrix();
glTranslatef(ttx+MoveBomb,tty,ttz);
glColor3f(0.0,0.0,0.0);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x1,y1);
for (angle=1.0f;angle<361.0f;angle+=0.2)
{
x2 = x1+sin(angle)*radius;
y2 = y1+cos(angle)*radius;
glVertex2f(x2,y2);
}
glEnd();
glPopMatrix();
glFlush();
}
void myDisplay(void)
{
drawSky();
drawSun();
drawSea();
drawMountain();
drawBomb();
drawBoom();
drawSmallShip();
drawBigShip();
drawBird1();
drawBird2();
drawBird3();
glColor3f(1,1,1);
drawText("PIRATES BOMB", 20, 950);
drawText("TO EXIT PRESS F4", 20, 920);
glFlush();
glutSwapBuffers();
}
void mySpecialKey(int key, int x, int y)
{
switch(key)
{
case GLUT_KEY_UP : ty += 10; break;
case GLUT_KEY_DOWN : ty -= 10; break;
case GLUT_KEY_RIGHT : tx += 10; break;
case GLUT_KEY_LEFT : tx -= 10; break;
case GLUT_KEY_F1 : tz -= 10; break;
case GLUT_KEY_F2 : tz += 10; break;
case GLUT_KEY_F3 : tty -= 10; break;
case GLUT_KEY_F5 : ttx += 10; break;
case GLUT_KEY_F4:exit(0);
}
glutPostRedisplay();
}
void mainloopF(int v)
{
MoveBird1 += 4;
MoveSmlShip +=2;
MoveBigShip +=3;
MoveBomb+=7;
if (MoveBomb>150) tty -= 20 ;
if(MoveBird1>400) MoveBird1 = 0;
if(MoveSmlShip>300) MoveSmlShip = 0;
if(MoveBigShip>300) MoveBigShip = 0;
glutPostRedisplay();
glutTimerFunc(100,mainloopF,0);
}
int main(int argc, char **argv){
glutInit(& argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(900,900);
glutInitWindowPosition(0,0);
glutCreateWindow("pirates bomb");
glutSpecialFunc(mySpecialKey);
glutTimerFunc(500,mainloopF,0);
glutDisplayFunc(myDisplay);
init();
glutMainLoop();
}
my project is a game called pirates bomb
the bomber shoot the bomb (ball) and then if it hit the ship it will explode and drown
i just want one object to be 3d
i tried to do drawBoom() in 3d but i failed<<< that's the ball that coming from the bomber (drawBomb)
i want the drawBoom() to be in 3d just that
please help me and i will be very thankful