Home   Easy-Code    Forum  Updater 
Twitter Facebook



Ball using c graphics

Critics Rating:

Users Rating:

       /* ANIMATION */



#include <stdio.h>

#include <graphics.h>

#include <alloc.h>

main()

{

int x=25,y=25,gm,gd=DETECT,ch,area,xdirn=1,ydirn=1,maxx,maxy;

char *buff;

clrscr();

initgraph(&gd,&gm," ");

setcolor(WHITE);

setfillstyle(SOLID_FILL,RED);

circle(50,50,25);

floodfill(50,50,WHITE);

area=imagesize(25,25,75,75);

buff=malloc(area);

getimage(25,25,75,75,buff);

maxx=getmaxx();

maxy=getmaxy();

rectangle(0,20,maxx,maxy);

outtextxy(250,10,"Animation");

while(1)

{

if(kbhit())

{

ch=getch();

if (ch=="\r")

{

    xdirn*=-1;

    ydirn*=-1;

}

else

{

    if (ch==27)

    break;

}

}

putimage(x,y,buff,XOR_PUT);

delay(0);

x=x+(xdirn*5);

y=y+(ydirn*2);

putimage(x,y,buff,XOR_PUT);

if (x>maxx-50 || x<0)

{

sound(50);

delay(5);

nosound();

xdirn*=-1;

}

if (y>maxy-50 || y<20)

{

sound(50);

delay(5);

nosound();

ydirn*=-1;

}

}

getch();

closegraph();

restorecrtmode();

}





Courtesy, Source, References & Regards: Kishore AVGK

While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright@2009-2011 by KuGuNi.com. All Rights Reserved.