i'm trying to make a geme with c++ but i can finish it because i have trouble with the code :( .....this is the code of the game that i want to make....

#include<iostream.h>
#include<conio.h>
#include<graphics.h>

//using namespace std;

int main(void)
{
    
    double pos_x,i_pos_x,pos_y,i_pos_y,vel_x,vel_y;
    double time,gravity ; //t=time,g=gravity
    int x_position,y_position;
    
    initwindow(640,480);
    
    //stick person
    setcolor(CYAN);
    circle(50,200,30);   
    setfillstyle(1,3);
    floodfill(50,200,3);
    
    setcolor(CYAN);
    line(50,230,50,300);//badan
    line(20,250,80,250);//tangan
    line(50,300,90,340);//kaki kanan
    line(50,300,10,340);//kaki kiri
    
   
    
    
    //stand
    setcolor(3);
    line(0,340,110,340);//2
    line(110,340,110,450);//3
    line(0,450,110,450);//4
    line(0,340,0,450);//1
    setfillstyle(1,3);
    floodfill(100,440,3);
    

    line(0,450,640,450);//platform
    
    //box
    line(400,380,400,450);//1
    line(400,450,500,450);//2
    line(500,380,500,450);//3
    
    
     //ball
    setcolor(RED);
    circle(90,250,10);
    setfillstyle(1,4);
    floodfill(90,250,4);
    
    pos_x=90;
    i_pos_x=90;
    pos_y=250;
    i_pos_y=250;
    vel_x=60;
    vel_y=60;
    gravity=9.81;
    time=6.2;
    
    moveto((int)pos_x,(int)pos_y);
    for(pos_x=i_pos_x;pos_x<450;pos_x++)
    {
                                    time=(pos_x-i_pos_x)/vel_x;
                                    pos_y=i_pos_y-(vel_y*time)+(9.81*time*time);
                                    lineto((int)pos_x,(int)pos_y);
                                    delay(7);
                                    }
    
    
    
    getch ();
    closegraph();
    return 0;
}

i'm trying to make the ball move but there is only the line that move not the ball at the stick person hand:-/ ...can somebody help me to solve this problem...:?:

int main()

to begin... more to follow...

Does your compiler fuss at you for not having header files or anything?


Ahh I see what the problem is.. the arch is stopping or getting too slow. Let me see if I can track it down.

and the int main(void) still works fine anyhow

Alright so I got the line to go further with this here:

for(pos_x=i_pos_x;pos_x<555;pos_x++)

my suggestion is something along the line of instead of having pos_x < XXX have it say something like pos_y > 0 (If its the ground you're trying to strike)


ROFL.. I just re-read your post. I'm not even looking at it right. I'll try something with the ball now

My fault

for(pos_x=i_pos_x;pos_y>0;pos_x++)
{
    time=(pos_x-i_pos_x)/vel_x;
    pos_y=i_pos_y-(vel_y*time)+(9.81*time*time);
    // lineto((int)pos_x,(int)pos_y);
    circle(pos_x,pos_y,10);
    setfillstyle(1,4);
    floodfill(90,250,4);
    delay(1);
}

Is where I'm at now. All we need is something to destroy the previous circle and we're golden.

#include <iostream>
#include <conio.h>
#include <graphics.h>

// using namespace std;


void drawSetting(); // Function to redraw everything

int main(void)
{

double pos_x,i_pos_x,pos_y,i_pos_y,vel_x,vel_y;
double time,gravity ; //t=time,g=gravity
int x_position,y_position;

initwindow(640,480);




//ball
//setcolor(RED);
//circle(90,250,10);
//setfillstyle(1,4);
//floodfill(90,250,4);




pos_x=90;
i_pos_x=90;
pos_y=250;
i_pos_y=250;
vel_x=60;
vel_y=60;
gravity=9.81;
time=6.2;

moveto((int)pos_x,(int)pos_y);
for(pos_x=i_pos_x;pos_y>0;pos_x++)
{
    time=(pos_x-i_pos_x)/vel_x;
    pos_y=i_pos_y-(vel_y*time)+(9.81*time*time);
    //lineto((int)pos_x,(int)pos_y);
    cleardevice();
    drawSetting();
    setcolor(RED);
    circle(pos_x,pos_y,10);
    setfillstyle(1,4);
    floodfill(pos_x,pos_y,4);
    delay(7);
}



getch ();
closegraph();
return 0;
}

void drawSetting()
{
    //stick person
    setcolor(CYAN);
    circle(50,200,30);
    setfillstyle(1,3);
    floodfill(50,200,3);

    setcolor(CYAN);
    line(50,230,50,300);//badan
    line(20,250,80,250);//tangan
    line(50,300,90,340);//kaki kanan
    line(50,300,10,340);//kaki kiri




    //stand
    setcolor(3);
    line(0,340,110,340);//2
    line(110,340,110,450);//3
    line(0,450,110,450);//4
    line(0,340,0,450);//1
    setfillstyle(1,3);
    floodfill(100,440,3);


    line(0,450,640,450);//platform

    //box
    line(400,380,400,450);//1
    line(400,450,500,450);//2
    line(500,380,500,450);//3
}

This works somewhat... I do NOT like the way it looks. :<

#include <iostream>
#include <conio.h>
#include <graphics.h>

// using namespace std;


void drawSetting(); // Function to redraw everything

int main(void)
{

double pos_x,i_pos_x,pos_y,i_pos_y,vel_x,vel_y;
double time,gravity ; //t=time,g=gravity
int x_position,y_position;

initwindow(640,480);




//ball
//setcolor(RED);
//circle(90,250,10);
//setfillstyle(1,4);
//floodfill(90,250,4);




pos_x=90;
i_pos_x=90;
pos_y=250;
i_pos_y=250;
vel_x=60;
vel_y=60;
gravity=9.81;
time=6.2;

moveto((int)pos_x,(int)pos_y);
for(pos_x=i_pos_x;pos_y>0;pos_x++)
{
    time=(pos_x-i_pos_x)/vel_x;
    pos_y=i_pos_y-(vel_y*time)+(9.81*time*time);
    //lineto((int)pos_x,(int)pos_y);
    cleardevice();
    drawSetting();
    setcolor(RED);
    circle(pos_x,pos_y,10);
    setfillstyle(1,4);
    floodfill(pos_x,pos_y,4);
    delay(7);
}



getch ();
closegraph();
return 0;
}

void drawSetting()
{
    //stick person
    setcolor(CYAN);
    circle(50,200,30);
    setfillstyle(1,3);
    floodfill(50,200,3);

    setcolor(CYAN);
    line(50,230,50,300);//badan
    line(20,250,80,250);//tangan
    line(50,300,90,340);//kaki kanan
    line(50,300,10,340);//kaki kiri




    //stand
    setcolor(3);
    line(0,340,110,340);//2
    line(110,340,110,450);//3
    line(0,450,110,450);//4
    line(0,340,0,450);//1
    setfillstyle(1,3);
    floodfill(100,440,3);


    line(0,450,640,450);//platform

    //box
    line(400,380,400,450);//1
    line(400,450,500,450);//2
    line(500,380,500,450);//3
}

This works somewhat... I do NOT like the way it looks. :<

Thanks...for the code...but can you explain a little bit more about the code that you have used to make the ball move...i want to understand more about the code because i still new in this language....

Well, what I ended up doing is making a function to draw the whole setting (drawSetting) - the stick person, the box, the platform, etc etc.

The cleardevice() function clears the whole screen (no setting, no circle). Then the setting is redrawn, and the circle is redrawn in the new position (pos_x, pos_y)

Basically this is the only way I could figure out how to do it. It would look a lot smoother if we could erase or delete the circle we've drawn, but I do not know a way to do that other than clearing the whole canvas.

Is it clearer now?

This question has already been answered. Start a new discussion instead.