From 83f3ced6b085c457a7c569a0fd1afb9ee5c49fca Mon Sep 17 00:00:00 2001 From: Satyam Pandey <72267824+Satyam-pandey-1@users.noreply.github.com> Date: Fri, 2 Oct 2020 21:17:57 +0530 Subject: [PATCH] Bouncing Ball game --- Bouncing Ball game | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Bouncing Ball game diff --git a/Bouncing Ball game b/Bouncing Ball game new file mode 100644 index 0000000..1906770 --- /dev/null +++ b/Bouncing Ball game @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +void *ball; +void image() +{ +//ball +setcolor(RED); +setfillstyle(SOLID_FILL,RED); +fillellipse(10,10,10,10); +ball=malloc(imagesize(0,0,20,20)); +getimage(0,0,20,20,ball); +cleardevice(); +} +void main() +{ +int gm,gd=DETECT; +initgraph(&gd,&gm,""); +int l=getmaxx()/2,r=0,t=0,b=0; +int x=1,y=1; +int s=0,key=0; +int xstep=1,ystep=1; +image(); +setbkcolor(GREEN); +while(key!=27) +{ +while(!kbhit()){ +putimage(l,t,ball,XOR_PUT); +delay(5); +putimage(l,t,ball,XOR_PUT); +if(l>=getmaxx()||l<=0){x*=-1;sound(1000);s=0;xstep=x*(random(4)+1);ystep=y +*(random(3)+1);if(l<=0)l=0;else l=getmaxx();} +if(t>=getmaxy()||t<=0){y*=-1;sound(1000);s=0;ystep=y*(random(4)+1);xstep=x +*(random(3)+1);if(t<=0)t=0;else t=getmaxy();} +l+=x+xstep; +t+=y+ystep; +s++; +if(s==5) +{nosound();} +} +key=getch(); +} +closegraph(); +}