Need some help in BorlandC++ 3.1 (just basic stuff)

This is a discussion on Need some help in BorlandC++ 3.1 (just basic stuff) within the C++ Programming forums, part of the General Programming Boards category; I am supposed to create this primitive game for this Saturday as part of my final grade but i just ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    5

    Question Need some help in BorlandC++ 3.1 (just basic stuff)

    I am supposed to create this primitive game for this Saturday as part of my final grade but i just can't figure out how to move a pixel using the keyboard in graphics mode.

    I am doing my own version of the classic pong and i created these two bars that are supposed to be manouverable using the keyboard in order to kick back the "ball". However i just can't find out how i am supposed to do this.

    I know about the "code" for every button and i know i somehow have to use that code (for example 119 for w to move up and 115 for s to move down) but i can't figure it out how, what command i need to use.

    Please help,
    if not a "direct" help at least give me some hints. Please be quick though as i have to get it done by Saturday morning.

  2. #2
    Griz803 Griz803's Avatar
    Join Date
    Jun 2004
    Posts
    5
    Well, at a primitive level, you need to loop through reading the key, redrawing the rectangle and testing for ball contact. That is probably a VERY oversimplified answer, but maybe it will get you going. I hope it helps. Try using getch.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    5
    Yes but i can't get the loop through reading the key to work. I don't know what command to use. I'm thinking i need to use a "while" but i can't figure it out how to get the key to work.
    So far the ball is in move by redrawing it and it just bounces around for now since i can't get the bars to move

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    5
    Code:
    #include<graphics.h>
    #include<conio.h>
    #include<dos.h>
    int i,j,k=240,l=265,gm,gd=DETECT,scor1=0,scor2=0;
    int y1=61,y=61,y2=439,x=100,x1=50,x2=630;
    void main()
    {clrscr();
     initgraph(&gd,&gm,"c:\\borlandc\\bgi");
     line(0,50,640,50);
     line(0,450,640,450);
     bar(10,240,15,265);
     bar(625,240,630,265);
     x=x1;
     y=y1;
     while(scor1!=2)
     {scor1=0;
      setcolor(0);
      circle(x,y,10);
      x=x+j;
      y=y+i;
      setcolor(15);
      circle(x,y,10);
      delay(10);
      if (y==y1)
      i=1;
      if (y==y2)
      i=-1;
      if (x==x1)
      j=1;
      if (x==x2)
      j=-1;
     }
     getch();
    closegraph();
    }

    So far i have this. I know that by what i have done the ball just moves around on the monitor but i plan to work on that after i am able to move the bars.

    Oh and the parameters for while are useless. I was just toying around.

  5. #5
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    If you're allowed to use Direct3D then include d3d8.h and call GetAsyncKeyState( VK_DOWN )
    That will return TRUE if the down arrow key is currently being pressed but FALSE otherwise.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    5
    No, no Direct 3D and nothing from the "outside". I must only use what is included in borlandc and only basic stuff (just look at my code for what i mean).

    I remember her saying that we need to use the ASCII codes that each key has in order to get the bars to move (or whatever we want to move) but darn if i can remember anything else.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    5
    Ok, new question (exploring some ideas).

    When i use cin>>bla, can i do it in such a way that hitting "return" is not necessary? So that when tyiping something (a single letter or number) it gets automatically registered.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic Graphics programming in C, please help
    By AdRock in forum Game Programming
    Replies: 3
    Last Post: 03-24-2004, 10:38 PM
  2. string into 2 dimensional array - basic stuff
    By mellisa in forum C++ Programming
    Replies: 11
    Last Post: 01-18-2003, 02:08 AM
  3. Basic httpd server
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 07-28-2002, 06:14 PM
  4. Your stuff
    By smog890 in forum C Programming
    Replies: 6
    Last Post: 06-13-2002, 11:50 PM
  5. arrays and validation (basic stuff)
    By Fountain in forum C++ Programming
    Replies: 2
    Last Post: 12-21-2001, 03:25 PM

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