getch();

Well , until now , this code spawns 40 random colored circles one after one and the circles are supposed to fall , so i had to increase the amount of Y repeatedly .
I wanted to check if player presses A or D so he can move the falling circles on the x axis .
but The problem is that getch(); avoids the circles to fall and i have to hold one of the keyboard's button to make it fall .
Do you have nay ideas about how can i fix this problem?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <graphics.h>
#include <time.h>

using namespace std;

int main()
{

    int rcolor,y=0 ;

    srand(time(NULL));
    initwindow(500 , 700 , "");
    int LY = 700,circle_x=250,cy,circler=45;

    //Intro
    setcolor(10);
    settextstyle(COMPLEX_FONT , HORIZ_DIR , 200);
    outtextxy(100, 285, "SRGP\n");
    setcolor(12);
    settextstyle(GOTHIC_FONT , HORIZ_DIR , 47);
    outtextxy(100 , 300 , "GAME");
    delay(2000);
    cleardevice();
    char ch;


        for(int i=1 ; i<=40 ; i++)
        {

            rcolor= rand()%(6-4+1)+4;
            y=0;

            for(  ; y!=655 ;y+=5  )
            {

                setcolor(0);
                circle(circle_x  , y , circler);

                setcolor(rcolor);
                circle(circle_x , y , circler);

                ch=getch();
                if(ch == 'A' || ch == 'a'&&circle_x!=100)
                {
                    setcolor(0);
                    circle(circle_x  , y , circler);
                    circle_x=circle_x-150;
                }
                else if(ch == 'D' || ch == 'd'&&circle_x!=400)
                {
                    setcolor(0);
                    circle(circle_x  , y , circler);
                    circle_x=circle_x+150;
                }

                setcolor(0);
                circle(circle_x  , y , circler);


            }

            if((45+y) == LY)
            {
                LY = LY - 2*circler;
            }

            setcolor(rcolor);
            circle(circle_x,y,circler);

        }



    getch();
    return 0;
}
This is non-standard, but it might be what you are looking for in this scenario:
1
2
3
4
5
if (kbhit())
{
    ch = getch();
    // etc...
}
by using Chervil's method, it accelerates the process of the falling circles and makes it not usable.
If too fast, possibly use the windows Sleep() function to introduce a delay? I've not tested this idea, it may or may not be relevant.
Thanks everyone for the replies .
Well Jason i tried chervil's method , and i noticed that . But i just decreased the speed of falling by using Sleep
What did you set the sleep to?
Topic archived. No new replies allowed.