I'm seeing if it is possible to write a pong game only using standard C with maximum portability. I've worked out everything except user input. When the game is playing, If the user has no key pressed down, the paddle does not move but the ball should keep moving. I can only think of two way's of doing this. One is to get the user to hold down an extra key at all times. The other is to shut off the buffer on stdin using setvbuf(), which will hopefully make getchar() return EOF or NULL when no key is being pressed. Would these work? Does anyone have any other idea's?
Thanks.
Hiroshe
499
Posting Whiz in Training
Recommended Answers
Jump to PostI think you would have to look at the ncurses library .. or the pdcurses library for the Window's equivalent to avoid any platform specific requirements.
Jump to PostThat would be cheating. :P I want to see what can be done with standard C alone.
Prepare to be disappointed. ;)
http://c-faq.com/osdep/cbreak.html
Jump to Postkbhit() function is in conio.h library and conio.h is not a standard library which is not what Hiroshe want
Jump to PostIs it standard behaviour for a key just pressed to outpower a key being held down? ie. The user holds down the space bar for the whole game, and the "up" key out powers the spacebar? If not, than I guess I'll have a theird key for "stay still".
As …
All 18 Replies
yellowSnow
607
Posting Whiz in Training
Hiroshe
499
Posting Whiz in Training
Dave Sinkula
2,398
long time no c
Team Colleague
deepugtm
-8
Junior Poster in Training
invisal
381
Search and Destroy
Hiroshe
499
Posting Whiz in Training
Dave Sinkula
2,398
long time no c
Team Colleague
Hiroshe
commented:
Lot's of help
+4
Hiroshe
499
Posting Whiz in Training
Hiroshe
499
Posting Whiz in Training
Duoas
1,025
Postaholic
Featured Poster
Hiroshe
499
Posting Whiz in Training
Duoas
1,025
Postaholic
Featured Poster
Hiroshe
499
Posting Whiz in Training
Dave Sinkula
2,398
long time no c
Team Colleague
Hiroshe
499
Posting Whiz in Training
Duoas
1,025
Postaholic
Featured Poster
Hiroshe
499
Posting Whiz in Training
Duoas
1,025
Postaholic
Featured Poster
iamthwee
commented:
get some R and R baby.
+22
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.