diff options
Diffstat (limited to 'src/zoom.cpp')
-rw-r--r-- | src/zoom.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/zoom.cpp b/src/zoom.cpp index 6fab527..d9df6d4 100644 --- a/src/zoom.cpp +++ b/src/zoom.cpp @@ -272,7 +272,7 @@ bool GLXinit(Display *disp, Atom windele, Window *wnd, GLXContext *gc, bool *mul XSetWindowAttributes swa; swa.colormap = cmap; swa.border_pixel = 0; - swa.event_mask = StructureNotifyMask/* | PointerMotionMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask*/; + swa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask/* | PointerMotionMask | ButtonPressMask | ButtonReleaseMask*/; *wnd = XCreateWindow(disp, RootWindow(disp, vi->screen), 0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel|CWColormap|CWEventMask, &swa); @@ -336,6 +336,7 @@ int main() { unsigned long delta = 0; unsigned long frames = 0, tocks = 0; + unsigned input = 0; struct timeval tv; gettimeofday(&tv, NULL); @@ -353,11 +354,31 @@ int main() { case ClientMessage: if(static_cast<Atom>(event.xclient.data.l[0]) == windele) running = false; + break; + + case KeyPress: + switch(XKeycodeToKeysym(disp, event.xkey.keycode, 0)) { + case XK_Up: case XK_w: input |= Zoom::Game::FORWARD; break; + case XK_Down: case XK_s: input |= Zoom::Game::BACKWARD; break; + case XK_Left: case XK_a: input |= Zoom::Game::LEFT; break; + case XK_Right: case XK_d: input |= Zoom::Game::RIGHT; break; + case XK_Escape: running = false; break; + } + break; + + case KeyRelease: + switch(XKeycodeToKeysym(disp, event.xkey.keycode, 0)) { + case XK_Up: case XK_w: input &= ~Zoom::Game::FORWARD; break; + case XK_Down: case XK_s: input &= ~Zoom::Game::BACKWARD; break; + case XK_Left: case XK_a: input &= ~Zoom::Game::LEFT; break; + case XK_Right: case XK_d: input &= ~Zoom::Game::RIGHT; break; + } } } if(!running) break; + game.setInput(input); game.run(delta); game.render(); |