• Create Account

# pong for ascii in dos, by comm line, no 3d, no directx, no winapi, no asm

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

11 replies to this topic

### #1whereiswez  Members   -  Reputation: 122

Like
Likes
Like

Posted 10 July 2001 - 10:52 AM

### #2deadlinegrunt  Members   -  Reputation: 122

Like
Likes
Like

Posted 10 July 2001 - 02:03 PM

Is this a "true" dos or a console app? The reason being that if it''s a true dos application then you are probably going to have to look in the area of a TSR type routine or your own scheduler using BIOS calls to scan the actual keyboard itself.

Any experts around who know a quick hack for this? That''s the only way I can think of at the moment...

YAP-YFIO

### #3whereiswez  Members   -  Reputation: 122

Like
Likes
Like

Posted 10 July 2001 - 03:05 PM

hmm .. i''d say its possibly a true dos game .. if you look at the #include''s & the code i''ll be using that should give an idea ..

i do recall having to do some kind of buffer thing from the old days .. i just cant remem if it had a name or something like that. like i said all my previous stuff is gone and its been literal years since ive even coded.

um yes .. i''d probably say it''s a true dos game.

how else can i explain it to define it ? ..

also ..in my other posts, i''ve posted the source twice, and both of those posts seem abandoned :| ..

### #4flame_warrior  Members   -  Reputation: 122

Like
Likes
Like

Posted 10 July 2001 - 03:11 PM

Hi,
kbhit is one good way of doing it. getch() is another way but its slow(in fact very slow). Assembly is a good idea for a true dos app.

Not pertaining to any particular game :-

Second from what I understand is you want to know how to do is if player 1 moves say some x distance pressing D key, and if player 2 pressed f key, you want to move some distance.

Ok, considering the fact that what I assume is what you want, you can do this in many ways. I don''t remember TSR''s but this was the best way to do it. Second is for every 18.2 ms(or greater) you could check if any key is pressed and do suitable movements and update your screen(will take up a little memory I guess).

### #5whereiswez  Members   -  Reputation: 122

Like
Likes
Like

Posted 10 July 2001 - 03:50 PM

k this se trickier than i first thought then ..

hmm .. what i am looking for .. is a way to make a 2 player game in DOS .. no asm .. no directx .. no SPECIALY made #includes, no 3d card .. just c++ by command line, no TASM.

um ..

let's say in Pong, player one moves by pressing 's', the left pad starts moving up and carries on moving up as long as player one holds down the 's' key. but then player also wants to move .. so player two presses (whatever, because it'll giv ethe same response) .. let's say '5' .. on the keypad to go up ..

now ..
player 1 has to let go of the 's' key and press it again .. if player \2 has pressed a key .

both players cannot hold down their keys .. AND have the paddles move at the same time .. the last person to press a key gets their key reading into the NORMAL NOT SPECIALLY MAD buffer of C++ ..

heres the code again .. with the kbhit() and switch statement .. if u compile this ( minus the [ " source " ] tags ) you'll see what i mean if TWO people try and play this game at the same time .. it becomes a kinda of button bashing game, trying to get your paddle to move once your opponent has pressed and is holding down a key.

> please try it out so you can see what i mean .. ? ..

  #include #include #include #include if (kbhit()) { ch = getch(); switch (ch) { case '\x1b' : { endgame = 1; }; break; case '+' : { if (gamespeed > 0) gamespeed = gamespeed -1; }; break; case '-' : { if (gamespeed < 50) gamespeed = gamespeed +1; }; break; case 's' : { if (lpad.y-lpad.ex > 1) { drawpad(lpad.x, lpad.y, lpad.ex, 0); lpad.y = lpad.y-1; drawpad(lpad.x, lpad.y, lpad.ex, 1); }; }; break; case 'x' : { if (lpad.y+lpad.ex < 24) { drawpad(lpad.x, lpad.y, lpad.ex, 0); lpad.y = lpad.y+1; drawpad(lpad.x, lpad.y, lpad.ex, 1); }; }; break; case '5' : { if (rpad.y-rpad.ex > 1) { drawpad(rpad.x, rpad.y, rpad.ex, 0); rpad.y = rpad.y-1; drawpad(rpad.x, rpad.y, rpad.ex, 1); }; }; break; case '2' : { if (rpad.y+rpad.ex < 24) { drawpad(rpad.x, rpad.y, rpad.ex, 0); rpad.y = rpad.y+1; drawpad(rpad.x, rpad.y, rpad.ex, 1); }; }; break; }; };

- kay edited out the rest of the code ..

Edited by - whereiswez on July 11, 2001 3:04:28 PM

Edited by - whereiswez on July 11, 2001 3:14:31 PM

### #6deadlinegrunt  Members   -  Reputation: 122

Like
Likes
Like

Posted 10 July 2001 - 06:13 PM

Better judgement tells me I should *edit* your post and trim down some on it but I won''t, at least not right now. For future reference the best thing to do is get a site, most ISP''s provide this ability and some portals, and post your code there with a link on how to find it. I''m not slapping your hand, just letting you know.

Now with your actual problem. Again, think of the scenario when you are at the DOS prompt and you hold down the <G>. It should type G''s for as long as you hold the key down. Now press any other key while you continue to hold down the <G> key, say <H> key for example. You notice how it doesn''t alternate between the keys. It will display one or the other but not both. This is why I stated you will need a TSR (Terminate and Stay Resident) or you will have to manually perform some low level keyboard scans or BIOS routines to scan the keyboard itself (the latter two being the better way to go in my opinion)

I understand that you want to KISS, however given the circumstances of what you are tying to do and how you are doing it, that''s the best solution your going to have. I haven''t "tricked" out the entire conio or stdlib so there may be something you need lurking in there, but I don''t believe there is. (magic function that is...)

YAP-YFIO

### #7whereiswez  Members   -  Reputation: 122

Like
Likes
Like

Posted 11 July 2001 - 08:10 AM

kay reason why i put all the cod ein .. is so that ppl can SEE .. what i''m trying to do and thusly help .. and yes your comments did help .. i did go looking up tsr stuf and came across quite a few things .. not 100% but atleast i''ve got a lead on things again !

one of the tsr''s i came across worked .. but only if both keys were pressed EXACTLY the same time ! hehehe weerd ..

anyways .. also i have looked around at other 2 player dos pong games, and they all do the key event thing .. so it seems unless i can find the right tsr im kinda stuck and forced to just move on ..

i was hoping to complete this game 100% so that i can feel i''m good enough to move onto the next stage ..

if you or anybody knows of any tsrs that could possibly help, please let me know .. i''d be very grateful as it will help me actually complete my game instead of doing off with it at 90% ..

sorry about the whole long code thing again ..

and thanks for your help ..

hmm .. i''m curious enough to ask why nobody goes back to an updated forum thread though ? .. as my previous threads like i said have been abondoned yet i add my question of multiplayer multiple times and waited and waited then re-asked again ..

### #8Tassadar  Members   -  Reputation: 122

Like
Likes
Like

Posted 11 July 2001 - 08:36 AM

I know you want to keep includes to a minimum, but I do recommend you go check out some game libraries. They are especially made for this kind of stuff.

Standard C just looks at input devices as files, from which you can read or write characters in streams of different lengths. To read exactly what a keyboard sends, you need to read the interrupt for input. I have no idea of how to do this in C, so do a search on DOS programming and interrupt reading. I thought there was a function called inp(int address) or something, look for it in the docs!

### #9whereiswez  Members   -  Reputation: 122

Like
Likes
Like

Posted 11 July 2001 - 11:29 AM

mm will do .. thanx

yeah .. so far it looks like i''ll be adding to the #include''s .. hmm .. will keep looking tho ..

### #10Beer Hunter  Members   -  Reputation: 712

Like
Likes
Like

Posted 11 July 2001 - 11:48 AM

I once made a crappy game in dos, supporting up to four players on one keyboard, where I had a similar problem with input and no magical libraries at my disposal.

But the hardest part wasn''t the programming - is was just fitting four people at one keyboard.

What you can do is just give each player three keys; one which starts moving their paddle in one direction (and keeps going without further input), another key which starts the paddle moving in the other direction (and keeps going), and a third key which stops that movement. It''s not brilliant for pong, but it''s very easy to program and doesn''t require any special libraries.

### #11whereiswez  Members   -  Reputation: 122

Like
Likes
Like

Posted 11 July 2001 - 06:30 PM

aha ! ... that''s brilliant thinking .. avoid the code and use smarts !!!!!!!!!!

BRILLIANT !!!!! will try it soon ! :D .. well as soon as i get home eheheh ... thanx

brilliant .. dang .. simple .. and even sounds like it''ll work in a few minutes ! :D ...

### #12whereiswez  Members   -  Reputation: 122

Like
Likes
Like

Posted 12 July 2001 - 11:44 AM

Thanks BeerHunter ! it worked great !

I think once i''ve completed all my ideas for the ASCII Pong Game, I''ll try getting it to work with the TSRs too ! .. might be a mission ..

Thanx all ! :D

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS