Sunday 1 July 2012

Show movement of Ball using c++.


#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
#include <dos.h>
#include <stdlib.h>


int tx=0,ty=0;

void getx(int &p)
{
    if (p==50)
    {
        tx = 0;
        p = p+1;
    }
    else if (p==getmaxx()-50)
    {
        tx = -1;
        p = p-1;
    }
    else if(tx==0)
        p = p + 1;
    else  if(tx==-1)
        p = p - 1;
}



void gety(int &q)
{
    if (q==50)
    {
        ty = 0;
        q = q+1;
    }
    else if (q==getmaxy()-50)
    {
        ty = -1;
        q = q - 1;
    }
    else if(ty==0)
        q = q + 1;
    else if(ty==-1)
        q = q - 1;
}

void main()
{
    int i,j;
    int gd = DETECT, gm, errorcode;

    initgraph(&gd, &gm, "..\\bgi");
    int x,y;
    x = 400;
    y = 200;

    a:
    cleardevice();

    getx(x);
    gety(y);

    circle(x,y,50);

    while(!kbhit())
    {
        delay(20);
        goto a;
    }
    exit(1);
}

No comments:

Post a Comment