PingPong But how to make 2 thing at the same time..

This is a discussion on PingPong But how to make 2 thing at the same time.. within the C Programming forums, part of the General Programming Boards category; Hi I'm trying to make a little pingpong game..(just for fun), But how do I make the two bats, run ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    64

    PingPong But how to make 2 thing at the same time..

    Hi I'm trying to make a little pingpong game..(just for fun),
    But how do I make the two bats, run seperatly from eachother.
    You can go up and down, but only with one at a time.

    And another thing, how do i get the game to go faster??, I'm thinking of when I move the bats up and down.
    Can it be made an easier way...
    tx


    my code so far:--------------------------

    int delay(int);
    void startgrafiksystem(void); /* Graphics Start */
    void slutgrafiksystem(void); /* Graphics Ends */
    void g_rectangle(int xstart, int ystart, int xtil, int ytil);
    /* my retangle function*/

    void bane(void) /* makes the box for playing */
    {

    setcolor(WHITE);
    g_rectangle(50, 30, getmaxx()-50, getmaxy()-30);
    /* (50,30),(589,449) */
    }

    int main()
    {
    int a,b,c,d,*pa,*pb,*pc,*pd, ch; /* [350,320,610,470] */
    int e,f,g,h,*pe,*pf,*pg,*ph;
    int count = 0;
    char c1[6];
    pa = &a; pb = &b; pc = &c; pd = &d;
    pe = &e; pf = &f; pg = &g; ph = &h;
    *pa=569; *pb = 200; *pc=579; *pd=250;
    *pe=60; *pf = 200; *pg=70; *ph=250;
    startgrafiksystem(); /* Opens the Graphic */
    bane(); /* makes the box for the field */
    do
    {
    if(!kbhit())
    {
    sprintf(c1, "%d", count++);
    gotoxy(1,1);
    printf("%s", c1);
    g_rectangle(a,b,c,d);
    g_rectangle(e,f,g,h);
    switch(bioskey(0))
    {
    case 0x5000: /* ARROW DOWN */
    setcolor(BLACK);
    g_rectangle(a,b,c,d);
    setcolor(WHITE);
    b-=1; d-=1;
    g_rectangle(a,b,c,d);
    break;

    case 0x4800: /* ARROW UP */
    setcolor(BLACK);
    g_rectangle(a,b,c,d);
    setcolor(WHITE);
    b+=1; d+=1;
    g_rectangle(a,b,c,d);
    break;

    case 0x1e61: /* a */
    setcolor(BLACK);
    g_rectangle(e,f,g,h);
    setcolor(WHITE);
    f+=1; h+=1;
    g_rectangle(e,f,g,h);
    break;

    case 0x2c7a: /* z */
    setcolor(BLACK);
    g_rectangle(e,f,g,h);
    setcolor(WHITE);
    f-=1; h-=1;
    g_rectangle(e,f,g,h);
    break;

    case 0x5300: /* DEL key */
    clrscr();
    gotoxy(300,220);
    printf("System is shuting down!!");
    delay(1200);
    slutgrafiksystem();
    return 0;

    default:
    break;
    }
    }
    }while(ch !='q');


    getch();
    slutgrafiksystem();
    return 0;
    }
    Last edited by Gugge; 04-01-2002 at 07:17 AM.
    !G!

  2. #2
    Dave!!
    Guest
    Once I saw something about a fork funktion, but i don't know if this can be used in this kode....

  3. #3
    Im a Capricorn vsriharsha's Avatar
    Join Date
    Feb 2002
    Posts
    192
    fork is available in UXix (and the like). Which OS are u trying to develop the game on?? If it is windows, then u can use direct x etc for the purpose.

    Regards,
    Sriharsha.
    Help everyone you can

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    64
    I'm just trying to make it work in Dos.

  5. #5
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Originally posted by Dave!!
    Once I saw something about a fork funktion, but i don't know if this can be used in this kode....
    FORK IZ LUNIX BIZACH
    YAH U need to uze THA threadINK BIZACH

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    You don't need co-routines for this to work. Simply call the update function() for all active objects on the screen and update each one. Place this in your main game loop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 11:42 AM
  3. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 04:41 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  5. relating date....
    By Prakash in forum C Programming
    Replies: 3
    Last Post: 09-19-2001, 10:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21