Archived

This topic is now archived and is closed to further replies.

Help Please!

This topic is 5129 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have noticed that other posts have been made on this topic but i am not able to understand how to implement it. I am trying to make a simple 2d game with a flying jet; at the moment it is just a square block. The problem is I would like to be able to able to press multiple keys at once. Below is the code, i would graetly appreciate if anyone could give any ideas, advice or anything which would start the ball rolling. Many Thanks in advance #include <windows.h> #include <GL/gl.h> #include <GL/glut.h> #include <gl/glaux.h> #include <stdio.h> #include <conio.h> #include <math.h> static int room = 0, rotb = 0, rota = 0; int rotc = 0; static float scale = 1.0, test = 0; float currentx,x,currenty,y; void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); } void plane(void) { if (rotc>360) rotc=1; if (rotc<1) rotc=360; x=(cos(rotc/57.2957795)); y=(sin(rotc/57.2957795)); printf("%d %f %f\n",rotc,x,y); glColor3f(1.0f, 1.0f, 0.0f); glRotatef(rotc, 0.0, 0.0, 0.1); glutSolidCube(0.1); } void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0f, 1.0f, 1.0f); glPushMatrix(); glScalef(3.0, 2.0, 1.0); plane(); glPopMatrix(); glutSwapBuffers(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(65.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -5.0); gluLookAt(0.0, -0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); } void keyboard(unsigned char key, int u, int v) { switch (key) { case ''y'': glTranslatef(x/25,y/25, 0.0); glutPostRedisplay(); break; case ''u'': rotc = (rotc -3); glutPostRedisplay(); break; case ''t'': rotc = (rotc +3); glutPostRedisplay(); break; default: break; } } int main(int argc, char**argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(800, 600); glutInitWindowPosition(0, 0); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0(); }

Share this post


Link to post
Share on other sites
quote:
Original post by Deadweight
The problem is I would like to be able to able to press multiple keys at once.


No need for DirectInput, just do something like the following:

// declare a global array

bool keyState[256]; // initialize these to all false

...
// in your windows message processing routine:

case WM_KEYDOWN:
keyState[wparam] = true;
break;
case WM_KEYUP:
keyState[wparam] = false;
break;


There are still limits on how many keys can be pressed at once imposed by the quality of the user''s keyboard, but you can''t do anything about those.

"Baby-killer is a bad word though. Notice how as soon as you say it, you think negative things." - Peon

Share this post


Link to post
Share on other sites
Thanks for your help guys, the keyboard input is getting there just struggling with translating the object at the moment; it keeps jumping back to the origin.
I''m sure i will be asking for more help soon!

Share this post


Link to post
Share on other sites