PDA

View Full Version : Making a simple tank fire



04-04-2002, 11:45 AM
I want to know how to make a tank i drew fire a simple square bullet across the screen. I call a function that makes bullet = true. My code looks like this:

if(bullet == true)
{
for(float e = 0.0; e<=25; e = e + .01)
{
glTranslatef(0.0, e, 0.0);

glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 20.0);
glVertex2f(-1.0, 20.0);
glEnd();
glutPostRedisplay();
}
bullet = false;
}
When i hit the space bar (the fire button) the bullet appears for a split second and then disappears. Any help would be greatly appreciated. Thanks.

nexusone
04-04-2002, 12:05 PM
First you do not have your program coded correctly.

The reason your bullet only shows up once is that you draw it in only one frame!

Your program should work like this:

first set variables after the #include.
float e; your bullet
int bullet; State of your bullet


void display()
{

if(bullet == true)
{
glTranslatef(0.0, e, 0.0);

glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 20.0);
glVertex2f(-1.0, 20.0);
glEnd();
}


void update_objects(void)
{

if (bullet == true)
{
e = e + 0.01;
if (e > 25 ) bullet = false;
}
glutPostRedisplay();
}


main()
{
// add other glut functions here.
glutDisplayFunc(display); What to call when using glutPostRedisplay()
glutIdelFunc(update_objects); What to call to make out bullet animate, or any other object.
glutMainLoop();
}

Let me know if you do not understand any of this, the only other thing we may need to add is a delay in how fast the bullet travels.



Originally posted by Cape:
I want to know how to make a tank i drew fire a simple square bullet across the screen. I call a function that makes bullet = true. My code looks like this:

if(bullet == true)
{
for(float e = 0.0; e<=25; e = e + .01) Putting this loop here does nothing.
{
glTranslatef(0.0, e, 0.0);

glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 20.0);
glVertex2f(-1.0, 20.0);
glEnd();
glutPostRedisplay();
}
bullet = false;
}
When i hit the space bar (the fire button) the bullet appears for a split second and then disappears. Any help would be greatly appreciated. Thanks.



[This message has been edited by nexusone (edited 04-04-2002).]

04-04-2002, 12:19 PM
Wow. That worked great. Its awesome. Thank you so much. I have a question though. Is update_objects a real open gl function or is it just a name you made made up for the function?

04-04-2002, 12:21 PM
ooops. I just tried it again and realized that it only fires once. Why??

nexusone
04-04-2002, 12:25 PM
You ether need to reset your variables, or there is something else in your code....
post your program so I can see what you are doing.


Originally posted by Cape:
ooops. I just tried it again and realized that it only fires once. Why??

nexusone
04-04-2002, 12:28 PM
As your learn to program you will find that you make maybe 80% of the functions in your program.

update_objects is a name I made up, one of the nice things with C is that you can call you routines things that are discriptive....



Originally posted by Cape:
Wow. That worked great. Its awesome. Thank you so much. I have a question though. Is update_objects a real open gl function or is it just a name you made made up for the function?

04-04-2002, 01:21 PM
Here is the code:

#include <Gl/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;
using std::setw;
using std::setiosflags;
using std::setprecision;

void display(void);
void exits(int);

void moveright(void);
void moveleft(void);
void moveup(void);
void movedown(void);

void shoot(void);
void update_objects(void);

static void key(unsigned char key, int x, int y);

void spinright(void);
void spinleft(void);

//void DrawCircle( double r );
//void DrawEllipse( double a, double b );

void reshape(int, int);

void init(void);

bool tank2 = true;
bool bullet = false;

float e;

int main (int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(450, 450);
glutInitWindowPosition(200, 100);
glutCreateWindow("Tank Attempt");
init();
glutDisplayFunc(display);
glutIdleFunc(update_objects);
glutReshapeFunc(reshape);
glutKeyboardFunc(key);
glutMainLoop();
return 0;
}

void init(void)
{
glClearColor(0.1, 0.5, 0.1, 0.0);
glShadeModel(GL_SMOOTH);

glutCreateMenu(exits);
glutAddMenuEntry("Exit", 1);
glutAddMenuEntry("Willy P.", 2);
glutAddMenuEntry("Tank # 2", 4);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();

//DrawCircle(5.0);

if (tank2 == true)
{
glBegin(GL_QUADS);
glColor3f(0.5, 0.1, 0.2);
glVertex2f(-8.0, -20.0);
glVertex2f(-10.0, 5.0);
glVertex2f(10.0, 5.0);
glVertex2f(8.0, -20.0);
glEnd();
glBegin(GL_QUADS);
glColor3f(0.5, 0.1, 0.2);
glVertex2f(-10.0, 5.0);
glVertex2f(-8.0, 10.0);
glVertex2f(8.0, 10.0);
glVertex2f(10.0, 5.0);
glEnd();
glBegin(GL_QUADS);
glColor3f(0.5, 0.1, 0.2);
glVertex2f(-1.0, 10.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 10.0);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0, 0.1, 0.0);
glVertex2f(-4.0, 0.0);
glVertex2f(-1.5, 0.0);
glVertex2f(0.0, 3.0);
glVertex2f(1.5, 0.0);
glVertex2f(4.0, 0.0);
glVertex2f(2.25, -3.0);
glVertex2f(3.0, -6.5);
glVertex2f(0.0, -4.0);
glVertex2f(-3.0, -6.5);
glVertex2f(-2.25, -3.0);
glEnd();
}

if(bullet == true)
{
glTranslatef(0.0, e, 0.0);

glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 20.0);
glVertex2f(-1.0, 20.0);
glEnd();
}

/*if(bullet == true)
{
for(e = 0.0; e<=25; e = e + .001)
{
glTranslatef(0.0, e, 0.0);

glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 20.0);
glVertex2f(-1.0, 20.0);
glEnd();
glutPostRedisplay();
}
bullet = false;
}*/

glPopMatrix();
glutSwapBuffers();
}

void reshape (int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void exits(int value)
{
if(value==1) exit(0);
if(value==2)
{
tank2 = false;
bullet = false;
glutPostRedisplay();
glClearColor(1.0, 1.0, 1.0, 0.0);
}
if(value==4)
{
tank2 = true;
glutPostRedisplay();
}

}


static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 'Q':
case 'q':
exit(0);
glutPostRedisplay();
break;
case 'H':
case 'h':
moveright();
glutPostRedisplay();
break;
case 'F':
case 'f':
moveleft();
glutPostRedisplay();
break;
case 'T':
case 't':
moveup();
glutPostRedisplay();
break;
case 'G':
case 'g':
movedown();
glutPostRedisplay();
break;
case 32:
shoot();
glutPostRedisplay();
break;
case 'O':
case 'o':
spinleft();
glutPostRedisplay();
break;
case 'P':
case 'p':
spinright();
glutPostRedisplay();
break;
default:
break;
}
cout << key << static_cast<int>(key) << endl;
}

void moveright(void)
{

for(int b = 0; b<=1; b++)
{
glTranslatef(b, 0.0, 0.0);
glutPostRedisplay();
}

}

void moveleft(void)
{
for(int a = 0; a>=-1; a--)
{
glTranslatef(a, 0.0, 0.0);
glutPostRedisplay();
}

}

void moveup(void)
{
for(int c = 0; c<=1; c++)
{
glTranslatef(0.0, c, 0.0);
glutPostRedisplay();
}

}

void movedown(void)
{
for(int d = 0; d>=-1; d--)
{
glTranslatef(0.0, d, 0.0);
glutPostRedisplay();
}

}

void shoot(void)
{
bullet = true;
cout << "shooting\n" << endl;
}

void spinleft(void)
{
glRotatef(22.5, 0.0, 0.0, 1.0);
glutPostRedisplay();
}

void spinright(void)
{
glRotatef(-22.5, 0.0, 0.0, 1.0);
glutPostRedisplay();
}

void update_objects(void)
{
if (bullet == true)
{
e = e + .25;
if (e > 60 ) bullet = false;
}
glutPostRedisplay();
}

nexusone
04-04-2002, 04:43 PM
Forgot to reset the e variable:

if (bullet == true)
{
e = e + 0.01;
if (e > 25 )
{
bullet = false;
e = 0;
}
}
glutPostRedisplay();
}



Originally posted by Cape:
ooops. I just tried it again and realized that it only fires once. Why??

zeckensack
04-04-2002, 04:50 PM
Cape: please edit your last post and insert CODE tags. This will make it more readable.

Beginning of block -> [ CODE]
End of block -> [ /CODE]
leave out the spaces, I can't demonstrate that here, if I did it right, you wouldn't be able to see the tags at all. But you can look at my posting (via 'quote'). It should then look like this:


My code, hurrah!

nexusone
04-04-2002, 05:32 PM
I am sorting thought your code.

I need more of an idea what you are trying to do....

From what you have stated you are wanting to write a tank battle game?

Am I currect that the tank does not move with your code right now?

Now do you want to have the screen look as if you where the driver or if you where looking from behind the tank as it moves forward?

I have edited your code, there are a few things that you should change in how you handle your object movement.


#include <Gl/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h> // Don't need
#include <gl\gl.h> // do you get a error or warning here?
#include <gl\glu.h> // same here?
#include <iostream> // Don't need
#include <cmath> // Don't need
#include <cstdlib> // Don't need
#include <iomanip> // Don't need

using std::cout; // Don't need
using std::cin; // Don't need
using std::endl; // Don't need
using std::setw; // Don't need
using std::setiosflags; // Don't need
using std::setprecision; // Don't need

void display(void);
void exits(int);

void moveright(void);
void moveleft(void);
void moveup(void);
void movedown(void);

void shoot(void);
void update_objects(void);

static void key(unsigned char key, int x, int y);

void spinright(void);
void spinleft(void);

//void DrawCircle( double r );
//void DrawEllipse( double a, double b );

void reshape(int, int);

void init(void);

bool tank2 = true;
bool bullet = false;

float e;

int main (int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(450, 450);
glutInitWindowPosition(200, 100);
glutCreateWindow("Tank Attempt");
init();
glutDisplayFunc(display);
glutIdleFunc(update_objects);
glutReshapeFunc(reshape);
glutKeyboardFunc(key);
glutMainLoop();
return 0;
}

void init(void)
{
glClearColor(0.1, 0.5, 0.1, 0.0);
glShadeModel(GL_SMOOTH);

glutCreateMenu(exits);
glutAddMenuEntry("Exit", 1);
glutAddMenuEntry("Willy P.", 2);
glutAddMenuEntry("Tank # 2", 4);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glPushMatrix();

//DrawCircle(5.0);

if (tank2 == true)
{
glBegin(GL_QUADS);
glColor3f(0.5, 0.1, 0.2);
glVertex2f(-8.0, -20.0);
glVertex2f(-10.0, 5.0);
glVertex2f(10.0, 5.0);
glVertex2f(8.0, -20.0);
glEnd();
glBegin(GL_QUADS);
glColor3f(0.5, 0.1, 0.2);
glVertex2f(-10.0, 5.0);
glVertex2f(-8.0, 10.0);
glVertex2f(8.0, 10.0);
glVertex2f(10.0, 5.0);
glEnd();
glBegin(GL_QUADS);
glColor3f(0.5, 0.1, 0.2);
glVertex2f(-1.0, 10.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 10.0);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0, 0.1, 0.0);
glVertex2f(-4.0, 0.0);
glVertex2f(-1.5, 0.0);
glVertex2f(0.0, 3.0);
glVertex2f(1.5, 0.0);
glVertex2f(4.0, 0.0);
glVertex2f(2.25, -3.0);
glVertex2f(3.0, -6.5);
glVertex2f(0.0, -4.0);
glVertex2f(-3.0, -6.5);
glVertex2f(-2.25, -3.0);
glEnd();
}

if(bullet == true)
{
glTranslatef(0.0, e, 0.0);

glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 20.0);
glVertex2f(-1.0, 20.0);
glEnd();
}

/*if(bullet == true)
{
for(e = 0.0; e<=25; e = e + .001)
{
glTranslatef(0.0, e, 0.0);

glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 20.0);
glVertex2f(-1.0, 20.0);
glEnd();
glutPostRedisplay();
}
bullet = false;
}*/

glPopMatrix();
glutSwapBuffers();
}

void reshape (int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void exits(int value)
{
if(value==1) exit(0);
if(value==2)
{
tank2 = false;
bullet = false;
glutPostRedisplay();
glClearColor(1.0, 1.0, 1.0, 0.0);
}
if(value==4)
{
tank2 = true;
glutPostRedisplay();
}

}


static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 'Q': // This does nothing, none of you Cap. letters do anything.
case 'q':
exit(0); // Program quits here next line does nothing!
glutPostRedisplay(); // Don't need
break;
case 'H':
case 'h':
moveright();
glutPostRedisplay(); // Don't need
break;
case 'F':
case 'f':
moveleft();
glutPostRedisplay(); // Don't need
break;
case 'T':
case 't':
moveup();
glutPostRedisplay(); // Don't need
break;
case 'G':
case 'g':
movedown();
glutPostRedisplay(); // Don't need
break;
case 32:
shoot();// replace shoot with bullet = true;
glutPostRedisplay(); // Don't need
break;
case 'O':
case 'o':
spinleft();
glutPostRedisplay(); // Don't need
break;
case 'P':
case 'p':
spinright();
glutPostRedisplay();
break;
default:
break;
}
cout << key << static_cast<int>(key) << endl; // Don't need
}

void moveright(void)
{

for(int b = 0; b<=1; b++)
{
glTranslatef(b, 0.0, 0.0);
glutPostRedisplay(); // Don't need
}

}

void moveleft(void)
{
for(int a = 0; a>=-1; a--)
{
glTranslatef(a, 0.0, 0.0);
glutPostRedisplay(); // Don't need
}

}

void moveup(void)
{
for(int c = 0; c<=1; c++)
{
glTranslatef(0.0, c, 0.0);
glutPostRedisplay(); // Don't need
}

}

void movedown(void)
{
for(int d = 0; d>=-1; d--)
{
glTranslatef(0.0, d, 0.0);
glutPostRedisplay(); // Don't need
}

}

void shoot(void) // See my note
{
bullet = true; // I would just put this in the keyboard input switch statement
cout << "shooting\n" << endl; // Don't need
}

void spinleft(void)
{
glRotatef(22.5, 0.0, 0.0, 1.0);
glutPostRedisplay(); // Don't need
}

void spinright(void)
{
glRotatef(-22.5, 0.0, 0.0, 1.0);
glutPostRedisplay(); // Don't need
}

void update_objects(void)
{
if (bullet == true)
{
e = e + .25;
if (e > 60 ) bullet = false;
}
glutPostRedisplay();
}



[This message has been edited by nexusone (edited 04-04-2002).]

04-04-2002, 06:34 PM
#include <Gl/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;
using std::setw;
using std::setiosflags;
using std::setprecision;

void display(void);
void exits(int);

void moveright(void);
void moveleft(void);
void moveup(void);
void movedown(void);

void shoot(void);
void update_objects(void);

static void key(unsigned char key, int x, int y);

void spinright(void);
void spinleft(void);

//void DrawCircle( double r );
//void DrawEllipse( double a, double b );

void reshape(int, int);

void init(void);

bool tank2 = true;
bool bullet = false;

float e;

int main (int argc,char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(450, 450);
glutInitWindowPosition(200, 100);
glutCreateWindow("Tank Attempt");
init();
glutDisplayFunc(display);
glutIdleFunc(update_objects);
glutReshapeFunc(reshape);
glutKeyboardFunc(key);
glutMainLoop();
return 0;
}

void init(void)
{
glClearColor(0.1, 0.5, 0.1, 0.0);
glShadeModel(GL_SMOOTH);

glutCreateMenu(exits);
glutAddMenuEntry("Exit", 1);
glutAddMenuEntry("Willy P.", 2);
glutAddMenuEntry("Tank # 2", 4);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();

//DrawCircle(5.0);

if (tank2 == true)
{
glBegin(GL_QUADS);
glColor3f(0.5, 0.1, 0.2);
glVertex2f(-8.0, -20.0);
glVertex2f(-10.0, 5.0);
glVertex2f(10.0, 5.0);
glVertex2f(8.0, -20.0);
glEnd();
glBegin(GL_QUADS);
glColor3f(0.5, 0.1, 0.2);
glVertex2f(-10.0, 5.0);
glVertex2f(-8.0, 10.0);
glVertex2f(8.0, 10.0);
glVertex2f(10.0, 5.0);
glEnd();
glBegin(GL_QUADS);
glColor3f(0.5, 0.1, 0.2);
glVertex2f(-1.0, 10.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 10.0);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0, 0.1, 0.0);
glVertex2f(-4.0, 0.0);
glVertex2f(-1.5, 0.0);
glVertex2f(0.0, 3.0);
glVertex2f(1.5, 0.0);
glVertex2f(4.0, 0.0);
glVertex2f(2.25, -3.0);
glVertex2f(3.0, -6.5);
glVertex2f(0.0, -4.0);
glVertex2f(-3.0, -6.5);
glVertex2f(-2.25, -3.0);
glEnd();
}

if(bullet == true)
{
glTranslatef(0.0, e, 0.0);

glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 20.0);
glVertex2f(-1.0, 20.0);
glEnd();
}

/*if(bullet == true)
{
for(e = 0.0; e<=25; e = e + .001)
{
glTranslatef(0.0, e, 0.0);

glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 20.0);
glVertex2f(-1.0, 20.0);
glEnd();
glutPostRedisplay();
}
bullet = false;
}*/

glPopMatrix();
glutSwapBuffers();
}

void reshape (int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void exits(int value)
{
if(value==1) exit(0);
if(value==2)
{
tank2 = false;
bullet = false;
glutPostRedisplay();
glClearColor(1.0, 1.0, 1.0, 0.0);
}
if(value==4)
{
tank2 = true;
glutPostRedisplay();
}

}


static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 'Q':
case 'q':
exit(0);
glutPostRedisplay();
break;
case 'H':
case 'h':
moveright();
glutPostRedisplay();
break;
case 'F':
case 'f':
moveleft();
glutPostRedisplay();
break;
case 'T':
case 't':
moveup();
glutPostRedisplay();
break;
case 'G':
case 'g':
movedown();
glutPostRedisplay();
break;
case 32:
shoot();
glutPostRedisplay();
break;
case 'O':
case 'o':
spinleft();
glutPostRedisplay();
break;
case 'P':
case 'p':
spinright();
glutPostRedisplay();
break;
default:
break;
}
cout << key << static_cast<int>(key) << endl;
}

void moveright(void)
{

for(int b = 0; b<=1; b++)
{
glTranslatef(b, 0.0, 0.0);
glutPostRedisplay();
}

}

void moveleft(void)
{
for(int a = 0; a>=-1; a--)
{
glTranslatef(a, 0.0, 0.0);
glutPostRedisplay();
}

}

void moveup(void)
{
for(int c = 0; c<=1; c++)
{
glTranslatef(0.0, c, 0.0);
glutPostRedisplay();
}

}

void movedown(void)
{
for(int d = 0; d>=-1; d--)
{
glTranslatef(0.0, d, 0.0);
glutPostRedisplay();
}

}

void shoot(void)
{
bullet = true;
cout << "shooting\n" << endl;
}

void spinleft(void)
{
glRotatef(22.5, 0.0, 0.0, 1.0);
glutPostRedisplay();
}

void spinright(void)
{
glRotatef(-22.5, 0.0, 0.0, 1.0);
glutPostRedisplay();
}

void update_objects(void)
{
if (bullet == true)
{
e = e + .25;
if (e > 60 ) bullet = false;
}
glutPostRedisplay();
}

04-04-2002, 06:35 PM
It is supposed to be the top view of a tank. And on my computer it moves fine. Thank you very much, I reset the variable and it works great now.

nexusone
04-05-2002, 05:06 AM
As per my last message, I think there are a lot of other things that could be done diffrent and may cause problems later when you add other objects. Like things to shoot at, do you understand now why your bullet did not shoot correctly?

Have you looked the tutors at nehe.gamedev.net a good place to get ideas.


Originally posted by Cape:
It is supposed to be the top view of a tank. And on my computer it moves fine. Thank you very much, I reset the variable and it works great now.

04-05-2002, 09:34 AM
Yes i understand it completely now. What are some general thing that you would suggest i change??

nexusone
04-05-2002, 10:08 AM
First read through this forum other peoples questions, the answers will help you learn.

1> your useage of the glutPostRedisplay, it should only be called from one place.

2> do not use a for/while/etc loop for movement, example is you bullet. Tank movement should be done the same way.

3> I think you should start thinking about the non-opengl stuff, like variables to map out your world, keep track of you tanks location, other objects.


Your tank routine maybe rework to look something like this:

if (tank == TRUE)
{
glPushMatrix()
glTranslatef( tank_x, tank_y, 0); // move tank
glRotatef( tank_direction, 0,0,1); // rotate tank
drawtank stuff here.
glpush
}


void spinleft(void)
{
Tank_direction = Tank_direction + 22.5;
}


void moveright(void)
{

for(int b = 0; b<=1; b++) // Strange usage
{
glTranslatef(b, 0.0, 0.0);
}

rework like this
void moveright(void)
{
tank_x++; move right;
}

repeat for left, up, down....



Originally posted by Cape:
Yes i understand it completely now. What are some general thing that you would suggest i change??

04-05-2002, 10:38 AM
Sounds good. I'll work on it. Thanks a lot for all your help.