Advertisement

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

Started by July 10, 2001 04:52 PM
10 comments, last by whereiswez 23 years, 5 months ago
k i relly need help w this .. have been asking for quite sum time and mentioning the same thing .. it seems nowun goes back tot eh post after i write in there my problem concerning 2 players in dos .. i need it so that 2 players can hold down keys and the program picks up that both players are playing and not to cut off the other players access to movement .. in dos, command line, no extended #includes, no windows programming or commands. i think its sumthing like creating some line and keyin buffer, im not sure of it and thus not sure of what to search for ont he net . .most of the source i come across is either beyond dos or beyond basic c++ command line #includes. please help me even find example code of what i might be looking for or atleast tell me what im looking for, as i said in previous posts im not lazy, but i have limited resources, buying a book is limited too as this country doesnt go about making game prograaming courses, my maths aint that great, and i''v lost my previous works, so i can''t look back at those, thusly why i was thrown off it ages ago, the other thing is i dont have muny or a credit card to buy things off the net .. and thusly using a free compiler .. i dont have a 3d card, and am using a 200 mmx, so please dont tell me to take a course and get a book. ? please help me ? .. just atleast tell me what i should be searching for ont he net concerning buffering keys in so that they dont overide each other, but both players keys get read in and the prog responds to each key press & down event. i''m quite sort of begging now .. and i dont know wether to repost my code again . .so il say please refer to the other topics of mine concerning pong in ascii.
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
-deadlinegrunt

~deadlinegrunt

Advertisement
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 :| ..

thanx for replying btw :|
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).
Hello from my world
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 <conio.h>#include <iostream.h>#include <time.h>#include <stdlib.h>    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
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 &ltG&gt. 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 &ltG> key, say &ltH> 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
-deadlinegrunt

~deadlinegrunt

Advertisement
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 ..
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!
mm will do .. thanx

yeah .. so far it looks like i''ll be adding to the #include''s .. hmm .. will keep looking tho ..
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.

This topic is closed to new replies.

Advertisement