Archived

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

Game Control

This topic is 5777 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, I just ran into a little problem ... I wanted to write a little first game (think of it as a BSD like worms clone, or a clone of a game called ''snake'' you''ll find on many handies, allowing multiplayer support) ... While I had no problems writing the algorithms and general data-structures, I don''t know how to best control the whole game. How could I organise it that the program is looking for user input via keyboard, do the data manipulation, and doing the output on the screen. Should I use threads that are designed to fullfill each one part, or should I look before each frame to be printed if the user was typing on the keyboard, and react on that action? Or is there just a simpler and a much better way to control the game? I would be glad if someone could explain me some design thoughts about this matter, though I''m pretty glad if I would know where to look to learn it for myself. I don''t know a game that''s small enough for learning for ... Thanks in advance.

Share this post


Link to post
Share on other sites
Guess "handy" is supposed to be a cell phone =)

well you could do the following if you'r using c:

    
#include <conio.h> //contains kbhit()


if(kbhit())
{
c=getch();
switch(c)
{
case 'W': //move up

case 'S': //move down

case 'D': //move right

case 'A': //move left

}
}


of course this is not perfect, just tryin to point you in the right direction. For example, if your snake is movin to the right and you press left, you have to prevent it, because it would move back "into" your snake.

PredeX

Edited by - PredeX on February 19, 2002 3:21:56 PM

Share this post


Link to post
Share on other sites
PredeX:
At first I wanted to thank you for answering :-) ...
Yes, I think that would be the simplest choice, whithout using threads. But then I have a little question about the input stream (are there 'streams' in C or are there only C++ 'streams'? I'm using C though...).

When the user presses down a button while kbhit() is NOT running and the other part of the program runs, maybe the graphical output routine. Is the keycode just left in the stream, so that the next time kbhit() would run, it's carrying out that button?

Or would the data be lost, so the only way is to keep kbhit() running when assuming the user to press a button?

I think it should be kept in the stream, shouldn't it?

Kylotan: It's okay moving the topic :-) I was pretty unsure where to post it, so I thought it would be 'game design' because it's about the general 'design' of the game and the program size shouldn't matter ... Do you define 'game design' designing the game in matter of -what features to implement, -what operating system and libraries to use and -what game type and game feeling it should have?



Edited by - Henning on February 19, 2002 4:19:18 PM

Share this post


Link to post
Share on other sites
I was lucky too find this thread again cuz I forgot to add it to my bookmarks =)

Yes the input is buffered, or streamed as you call it, simply say itz stored somewhere. Actually kbhit() just tells if ANY keyboard button was pressed, and doesnt tell you what key was pressed. Hence you need the getch() to identify what exact key was pressed! I think thatz pretty important, cuz i used kbhit() recently and forgot about the fact that it just buffers the input, that took me about 2(!) hours to figure out what was wrong with my proggy... =)

PredeX

Share this post


Link to post
Share on other sites
quote:
Original post by Henning
Do you define ''game design'' designing the game in matter of -what features to implement, -what operating system and libraries to use and -what game type and game feeling it should have?

Here on GameDev.net, ''Game Design'' mostly refers to making decisions about the game that aren''t about implementation. So this does include features, and to a degree the type and feeling, but not the operating system or library choice. Browse the forums and you''ll start to get a feel for what goes where.



[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

Share this post


Link to post
Share on other sites