Thread: 2 player RTS

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    129

    2 player RTS

    0) Is there any easy way to do a two player RTS game with DJGPP-Allegro -combo? I know, I know that similar topics like this have been up before, but I'm thinking of a way like this:
    Code:
    loop
      if player 1 is pressing x  (like if(key[KEY_UP]))
        do_something(player1);
      if player 2 is pressing y
        do_something(player2);
      rest for some time
    /loop
    The problem is that when I pass the control to do_something() I don't get input from player 2 anymore. I could do this by making a gigantic function with all kinds of hacky bubblegum thingies and gotos...

    1) After you say no, please point me to some information about the very essential stuff on how to do this in a Windows environment (while remembering that I don't know nothing about Windows-depented coding).

  2. #2
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    I have the exact same problem!!! someone help!

  3. #3
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    ah yes

    I've run across this type of problem before. Now, as to why you don't get input from player 2 anymore. Well for starters, you are trying to do it the wrong way. You need to not pass player2 but pass the symbiotic information that assembles player's keypress. Because how you are trying to do it, the computer gets sucked into player 1. You know, player 1 this, player 1 that, blah blah blah. Player1, player1, player1! After all this time it forgets about player 2, thus ingnoring it. Now, when you pass the symbiotic info., the computer reads the info and processes it according the the SSPC (standard symbiotic processing code). Now it will try the left buffer, thus getting mixed results for now. when it is passed back, the information is re-assembled according to the CRP (code re-assembling procedure) and change it back to c/c++. For awhile it is changed to html (sounds crazy, but true) and assembled symbiotically. So, to do it symbiotically, you must use this:

    aa((LP_doNOW)*gh(34))&&_%_(player2);

    Ok, this is all very general. If you would like me to explain further, just ask. Also make sure you are using a GTOP (Gradual toned operation program) certified compiler.

  4. #4
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    it should be like this:

    loop
    get input from player 1
    get input from player 2
    do_something(player1);
    do_something(player2);
    do_other_stuff();
    rest for some time
    /loop
    My Website

    "Circular logic is good because it is."

  5. #5
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    ok, so say I was doing this in DOS:
    I would say
    Code:
    while(player1 != 12 && player2 != 12){
    player1=getch();
    player2=getch();
    if(player1=="somtin")
    {
              //do some stuff
    }
    if(player2=="somtin");
    {
              //do some stuff
    }
    }//end loop
    your saying they would process //do some stuff
    all at the same time? thats my problem.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    it should be like this:

    loop
    get input from player 1
    get input from player 2
    do_something(player1);
    do_something(player2);
    do_other_stuff();
    rest for some time
    /loop
    And then my do_something(Player &p, p1_input) would have a tremendous amount of statics and all kinds of spagetti-like switches...? (Example: I go to menu to balance the budget. Every time I press '+' it adds 1 to x. In the meanwhile, I would still have to get input from player 2 and do all the things that he wants. So, the only case I'm going to receive input from user(s) is in that main loop, right? Now I would have to remember the state of both players in my do_something -> statics?)

    Now when I think about it, I can't see how a real multithread system would help me out on this... Is this the only way?



    Xterria: That's really a turn-based... I use Allegro and check the state of keys and proceed when needed to: if(key[KEY_A]) is true if 'a' is being hold down (not just a one single click).

  7. #7
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    so how do i not make it turn-based? i want two at once!

  8. #8
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210

    Question

    Leeman, you're speaking in greek. You're post is very vague, and I'm not absolutely certain anything you wrote isn't utter bs. For starters, when I look up SSPC on the web all I find is The Society for Protective Coating. I don't think they have anything to do with coding video games. A search on GTOP results in Genomes to Protein. Admittly, I got some stuff on Gnome too. So, could you please clarify your post.
    "The mind, like a parachute, only functions when open."

  9. #9
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    it should be like this:

    loop
    get input from player 1
    get input from player 2
    do_something(player1);
    do_something(player2);
    do_other_stuff();
    rest for some time
    /loop
    Its like that because you want to get all the input and then do stuff...otherwise you could get stuck somewhere. If you got input from player 1 and then did player 1's things...what would player 2 be doing all that time? Your swordsman would be moving 5 steps to the right while player 2's swordsman just sat there until it was player 2's turn to input. Thats called turn based. In a RTS, you get all the input first, THEN do the stuff.
    My Website

    "Circular logic is good because it is."

  10. #10
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    Invincible: i think you'll find that you've been had. Leeman isn't being serious. It's just BS that he's talking to try and confuse people.

    It's obviously worked
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  11. #11
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    Leeman isn't being serious. It's just BS that he's talking to try and confuse people
    exactly what I thought...
    anyway, how do I make my game not turn based with getch();

  12. #12
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    As far as I know getch just waits for an input, you need a function that can check to see if any keys are being pressed at the moment. The run your program as a constant loop.

    you could use GetAsyncKeyState to do this.

    while(running) {
    if(GetAsyncKeyState(VK_ESCAPE) running = false;
    if(GetAsyncKeyState('w') move_player_1_up();
    if(GetAsyncKeyState('o') move_player_2_up();

    Update_all_game_variables();

    Draw_the_frame();
    }

    You should get the idea.

    You should also do timeing to make the animations the same on all systems.

  13. #13
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210

    Cool

    Originally posted by Uraldor
    It's obviously worked
    I think not Well, maybe if you say because I searched for it online. I was only giving him the benefit of the doubt. But I said in my post I thought it was BS

    Anyway, here's my thought on this question. If you're using the keyboard as input, who on earth would play a two player game on the keyboard? Unless of course the players switched off. 2 player simultaneous isn't normally done on the keyboard. As a matter of fact, I've never seen it done, excluding online multiplayer and that's a whole other ballgame.

    If you were using control pads, then that's different. You would access the input through 2 different ports :

    getInput(controlPad1);
    getInput(controlPad2);

    I don't know how communications with control pads are handled in DOS, but I do know that some of the DirectX libraries support functions for control pad input (including vibration).

    Sounds better than some stuff about symbiosis
    "The mind, like a parachute, only functions when open."

  14. #14
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169
    I have the same problem that everyone had so far with getch. I was at one point in time attempting to make a text based snake game using getch in DOS. This code will continue on if nothing is pressed and will not make the system pause.
    Code:
    while(loop does not equal some exit condition here)
    {
    while(_kbhit())
    {	
    	intinput = _getch();
    	intinput = toupper(intinput);
    }
    //the rest of the game here
    }
    the only (and biggest) problem with this code is if the user presses a key in the rest of the game part, the computer won't getch. Unfortunetly, you must be "getching" at the exact right moment. The easiest way i've found to fix this problem is copy paste the while(_kebhit()) part all over the game. I know it's messy but it works (sorta)

  15. #15
    Registered User minime6696's Avatar
    Join Date
    Aug 2001
    Posts
    267

    Exclamation Game Engine!

    Why are all of you sticking with that old method? You need to write a Game Engine! Okay, first you'll need to set up Key Tables:

    if(kbhit())key[getch()]=true;

    ect.

    THEN You'll need to set up GUI, and the game layout and such, consider using mouse drivers!

    Im just saying here that a "Crazy Linear System Thing" is a common mistake, and should be avoided!

    SPH

    P.S. Need more extensive help? AIM: aGaBoOgAmOnGeR
    EMAIL/MSNIM: [email protected], ALLWAYS HAPPY 2 HELP!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 11-03-2008, 09:48 PM
  2. My first python project =)
    By Desolation in forum Tech Board
    Replies: 14
    Last Post: 06-26-2007, 10:52 PM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  4. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  5. Trying To Implement A 'Player' Class
    By adc85 in forum C++ Programming
    Replies: 2
    Last Post: 04-02-2003, 03:51 PM