• Advertisement
Sign in to follow this  

Tetris clone input

This topic is 4613 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

Hi guys, I'm currently working on a Console based Tetris clone using ANSI C++. I'm using cout for display. The problem is this: How can I implement an input system for this? I want to input 1 char per update either for rotation of block or movement. I can't use cin because input has to be entered & then enter pressed, which is no good because I want the game to play fluently. I'll need some kind of stream, one that just accepts 1 char at a time. Any1 got any ideas? Thanks for any help!

Share this post


Link to post
Share on other sites
Advertisement
I don't believe ANSI C++ has anything that immediate as far as input goes. You'd probably have to (1) get into the assembly yourself for any/every system you wanted to support, OR (2) use a game/input library for every platform you which to support.

Also, this is a game for a console? Like, a Gameboy, XBox, PS2, or other such device? If that's the case, using true ANSI C++ (in other words no extra libraries) would be a horrible undertaking. Or am I misreading that?

Share this post


Link to post
Share on other sites
Would using peek() work? If it's EOF, don't try to get a character. I've never tried. I never use cin except in trivial little ways.

Share this post


Link to post
Share on other sites
I think, but I maybe wrong, that there is a function (cin.get() or cin.getline()) that doesnt need you to hit enter, I might be wrong, but its something to look into.

Share this post


Link to post
Share on other sites
Lol Nychold, when I said console I meant a DOS box. Still not sure how to do this. I've tried cin.get(), think getLine() gets a word at a time not a char. Its a pain having to press return everytime I want to enter a move. Any1 else any ideas?

Share this post


Link to post
Share on other sites
Heh, I made tetris in a console once too. Try including conio.h, then use the function kbhit() to see if a key is being pressed. Then use getch() to see what key it is. Like this:

if(kbhit())
{
char keypress = getch();
if(keypress == 'x')
//User pressed lowercase x
}


conio isnt technically a standard library though, but it comes with Visual C++ and Dev-C++, and probably most other compilers. You should definitly try learning SDL or something :)

Share this post


Link to post
Share on other sites
Thanks Adamb!, that worked great! Its all working now basically! A few minor bugs but shaping up nicely. Next: To add an OpenGL Renderer! Thats gona take a long time, will be fun though!

How did you go about creating your Tetris? I made the playing board a matrix of booleans. If a brick existed on the board the boolean for that position equaled true. And the bricks were made of boolean matrices too. Any better ways to go about it?

Also, in the future i'd like to make my own input. I suppose I would need to create something like the 'MainWindowProc' like in Win32 apps? Is this what one would call a messaging system? I've nothing against SDL but I don't really like using alternative libraries, I don't like not knowing how the code works, silly I know LOL

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Cacks
Any better ways to go about it?

http://www.gamedev.net/community/forums/topic.asp?topic_id=325279

Share this post


Link to post
Share on other sites
Quote:
Original post by Cacks
How did you go about creating your Tetris? I made the playing board a matrix of booleans. If a brick existed on the board the boolean for that position equaled true. And the bricks were made of boolean matrices too. Any better ways to go about it?

Also, in the future i'd like to make my own input. I suppose I would need to create something like the 'MainWindowProc' like in Win32 apps? Is this what one would call a messaging system? I've nothing against SDL but I don't really like using alternative libraries, I don't like not knowing how the code works, silly I know LOL


Yeah, that's pretty much how I did it, except instead of bools, it was ints, and the ints stood for what color to draw the pieces. Then there was a struct for the current block, like struct block { x[4], y[4] }; or some such thing. There's probably a better way to do it, but I was a complete noob when I made it, so... :)

About making your own input: SDL is definitly easier, but it's not too difficult to do everything with the windows API, tho it won't be portable. There's a good tutorial here: http://www.winprog.org/tutorial/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement