[SDL] Re: key handling
micah at mindgrasp.com
Sat Dec 14 11:49:01 PST 2002
Ahh, this seems to work well. Thanks.
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Sent: Friday, December 13, 2002 5:23 AM
To: sdl at libsdl.org
Subject: [SDL] Re: key handling
This is exactly the key-handling routine I'm using in
my pac-man clone. In the main game loop, I update a
boolean array of keys, then branch to another part of
the loop depending on the game state, e.g. intro,
menu, maingame, etc.
In a tetris clone, I'm assuming that you'll only want
to move a block to the right once for each time you
press the right arrow key. This quick fix will do it:
keys[SDLK_RIGHT] = false; //or 0 or whatever
I don't know if it makes any difference, but my event
loop is a while(SDL_PollEvent(&event)) loop.
If you do want to be able to move the block to the
right more than once by holding the key down
(something which I never do in Tetris) then you'll
have to be a bit smarter, perhaps give each block a
velocity, so intead of x++ in the code block above,
have xv=1, and vary this speed to fit.
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
SDL mailing list
SDL at libsdl.org
More information about the SDL