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:

if(keys[SDLK_RIGHT])
{
x++;
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.

Paul__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

Ahh, this seems to work well. Thanks.

  • Micah> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Paul Smith
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:

if(keys[SDLK_RIGHT])
{
x++;
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.

Paul


Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl