/* C PROGRAM TO DEMONSTRATE GRAPHICS GAME PRESS ME BUTTON */
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR */
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include<stdlib.h>
union REGS i, o;
int left = 265, top = 250;
void initialize_graphics_mode() {
int gd = DETECT, gm, error;
initgraph( & gd, & gm, "C:/TC/BGI");
error = graphresult();
if (error != grOk) {
perror("Error ");
printf("Press any key to exit...\n");
getch();
exit(EXIT_FAILURE);
}
}
void showmouseptr() {
i.x.ax = 1;
int86(0x33, & i, & o);
}
void hidemouseptr() {
i.x.ax = 2;
int86(0x33, & i, & o);
}
void getmousepos(int * x, int * y) {
i.x.ax = 3;
int86(0x33, & i, & o);
* x = o.x.cx;
* y = o.x.dx;
}
void draw_bar() {
hidemouseptr();
setfillstyle(SOLID_FILL, CYAN);
bar(190, 180, 450, 350);
showmouseptr();
}
void draw_button(int x, int y) {
hidemouseptr();
setfillstyle(SOLID_FILL, MAGENTA);
bar(x, y, x + 100, y + 30);
moveto(x + 5, y);
setcolor(YELLOW);
outtext("Press me");
showmouseptr();
}
void draw() {
settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 2);
outtextxy(155, 451, "www.programmingsimplified.com");
setcolor(BLUE);
rectangle(0, 0, 639, 450);
setcolor(RED);
outtextxy(160, 25, "Try to press the \"Press me\" button");
outtextxy(210, 50, "Press escape key to exit");
setfillstyle(XHATCH_FILL, GREEN);
setcolor(BLUE);
bar(1, 1, 75, 449);
bar(565, 1, 638, 449);
showmouseptr();
draw_bar();
draw_button(left, top);
}
void initialize() {
initialize_graphics_mode();
if (!initmouse()) {
closegraph();
printf("Unable to initialize the mouse");
printf("Press any key to exit...\n");
getch();
exit(EXIT_SUCCESS);
}
draw();
}
int initmouse() {
i.x.ax = 0;
int86(0x33, & i, & o);
return (o.x.ax);
}
void get_input() {
int x, y;
while (1) {
getmousepos( & x, & y);
/* mouse pointer in left of button */
if (x >= (left - 3) && y >= (top - 3) && y <= (top + 30 + 3) && x < left) {
draw_bar();
left = left + 4;
if (left > 350)
left = 190;
draw_button(left, top);
}
/* mouse pointer in right of button */
else if (x <= (left + 100 + 3) && y >= (top - 3) && y <= (top + 30 + 3) && x > (left + 100)) {
draw_bar();
left = left - 4;
if (left < 190)
left = 350;
draw_button(left, top);
}
/* mouse pointer above button */
else if (x > (left - 3) && y >= (top - 3) && y < (top) && x <= (left + 100 + 3)) {
draw_bar();
top = top + 4;
if (top > 320)
top = 180;
draw_button(left, top);
}
/* mouse pointer below button */
else if (x > (left - 3) && y > (top + 30) && y <= (top + 30 + 3) && x <= (left + 100 + 3)) {
draw_bar();
top = top - 4;
if (top < 180)
top = 320;
draw_button(left, top);
}
if (kbhit()) {
if (getkey() == 1)
exit(EXIT_SUCCESS);
}
}
}
int getkey() {
i.h.ah = 0;
int86(22, & i, & o);
return (o.h.ah);
}
main() {
initialize();
get_input();
return 0;
}
Amazon banner
Showing posts with label graphics game. Show all posts
Showing posts with label graphics game. Show all posts
Thursday, 30 August 2012
C PROGRAM TO DEMONSTRATE GRAPHICS GAME PRESS ME BUTTON
C PROGRAM TO DEMONSTRATE TRAFFIC SIGNALS
/* C PROGRAM TO DEMONSTRATE TRAFFIC SIGNALS */
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR */
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
main() {
int gd = DETECT, gm, midx, midy;
initgraph( & gd, & gm, "C:/TC/BGI");
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(RED);
settextstyle(SCRIPT_FONT, HORIZ_DIR, 3);
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(midx, midy - 10, "Traffic Light Simulation");
outtextxy(midx, midy + 10, "Press any key to start");
getch();
cleardevice();
setcolor(WHITE);
settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
rectangle(midx - 30, midy - 80, midx + 30, midy + 80);
circle(midx, midy - 50, 22);
setfillstyle(SOLID_FILL, RED);
floodfill(midx, midy - 50, WHITE);
setcolor(BLUE);
outtextxy(midx, midy - 50, "STOP");
delay(2000);
graphdefaults();
cleardevice();
setcolor(WHITE);
rectangle(midx - 30, midy - 80, midx + 30, midy + 80);
circle(midx, midy, 20);
setfillstyle(SOLID_FILL, YELLOW);
floodfill(midx, midy, WHITE);
setcolor(BLUE);
outtextxy(midx - 18, midy - 3, "READY");
delay(2000);
cleardevice();
setcolor(WHITE);
rectangle(midx - 30, midy - 80, midx + 30, midy + 80);
circle(midx, midy + 50, 22);
setfillstyle(SOLID_FILL, GREEN);
floodfill(midx, midy + 50, WHITE);
setcolor(BLUE);
outtextxy(midx - 7, midy + 48, "GO");
setcolor(RED);
settextstyle(SCRIPT_FONT, HORIZ_DIR, 4);
outtextxy(midx - 150, midy + 100, "Press any key to exit...");
getch();
closegraph();
return 0;
}
C PROGRAM TO DESIGN A MOVING WHEEL
/* C PROGRAM TO DESIGN A MOVING WHEEL */
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR */
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<dos.h>
int xc = 50, yc = 200, r = 35;
int x[15], y[15];
void drawcircles() {
setcolor(YELLOW);
circle(xc, yc, r);
circle(xc, yc, r + 5);
}
void main() {
double angle = 0, theta;
int i, a;
int gd = DETECT, gm;
initgraph( & gd, & gm, "C:\TC\BGI");
a = xc + r;
while (!kbhit()) {
while (a <= 630) {
theta = M_PI * angle / 180;
cleardevice();
drawcircles();
for (i = 0; i < 18; i++) {
theta = M_PI * angle / 180;
x[i] = xc + r * cos(theta);
y[i] = yc + r * sin(theta);
angle += 20;
line(xc, yc, x[i], y[i]);
}
angle += 2;
xc += 2;
a = xc + r;
delay(50);
}
xc = 50;
r = 35;
a = xc + r;
}
getch();
closegraph();
}
C PROGRAM TO DRAW SPIRAL DESIGN
/* C PROGRAM TO DRAW SPIRAL DESIGN *//* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int r=5,n,i,x,y;
int graphdriver = DETECT, graphmode;
initgraph(&graphdriver, &graphmode, "C:/TC/BGI");
setcolor(YELLOW);
printf("ENTER THE NUMBER OF RINGS IN THE SPIRAL MODEL\n");
scanf("%d",&n);
printf("Enter the origin point of the spiral");
scanf("%d%d",&x,&y);
clrscr();
for(i=0;i<n;i++)
{ delay(50);
arc(x,y,0,180,r=r+2);
arc(x+2,y,180,360,r=r+2);
}
getch();
closegraph();
}
C PROGRAM CREATE CIRCLES DESIGN
/* C PROGRAM CREATE CIRCLES DESIGN */
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<graphics.h>
#include<conio.h>
#include<dos.h>
main()
{
int gd = DETECT, gm, x, y, color, angle = 0;
struct arccoordstype a, b;
initgraph(&gd, &gm, "C:/TC/BGI");
delay(2000);
while(angle<=360)
{
setcolor(BLACK);
arc(getmaxx()/2,getmaxy()/2,angle,angle+2,100);
setcolor(RED);
getarccoords(&a);
circle(a.xstart,a.ystart,25);
setcolor(BLACK);
arc(getmaxx()/2,getmaxy()/2,angle,angle+2,150);
getarccoords(&a);
setcolor(GREEN);
circle(a.xstart,a.ystart,25);
angle = angle+5;
delay(50);
}
getch();
closegraph();
return 0;
}
C PROGRAM TO DEMONSTRATE BRICK GAME
/* C PROGRAM TO DEMONSTRATE BRICK GAME *//* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<stdio.h>#include<graphics.h>
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
int getkey();
void main()
{
int gd,gm;
gd=DETECT;
initgraph(&gd,&gm,"C:/TC/BGI");
cleardevice();
int ar,xc,yc,xr=0,yr=195,a=1,b=1,c=0,are;
void *bu,*buf;
int X=0,Y=0,s,area1;
void *buff1;
rectangle(0,0,50,25);
setfillstyle(6,6);
floodfill(2,2,15);
ar=imagesize(0,0,50,25);
bu=malloc(ar);
getimage(0,0,50,25,bu);
putimage(0,0,bu,XOR_PUT);
rectangle(0,0,50,25);
setfillstyle(6,8);
floodfill(2,2,15);
are=imagesize(0,0,50,25);
buf=malloc(are);
getimage(0,0,50,25,buf);
putimage(0,0,buf,XOR_PUT);
for(int j=0;j<180;j+=27)
for(int i=0;i<600;i+=52)
putimage(0+i,27+j,bu,XOR_PUT);
putimage(0,27,bu,XOR_PUT);
putimage(572,27,bu,XOR_PUT);
putimage(0,27,buf,XOR_PUT);
putimage(572,27,buf,XOR_PUT);
setcolor(3);
rectangle(80,445,159,452);
setfillstyle(1,1);
floodfill(82,447,3);
area1=imagesize(80,445,159,452);
buff1=malloc(area1);
getimage(80,445,159,452,buff1);
setcolor(4);
line(0,479,640,479);
int area,x=325,y=325,ch,xdirn=-1,ydirn=-1,step;
int maxx,maxy;
void *buff;
setcolor(WHITE);
setfillstyle(SOLID_FILL,RED);
circle(350,350,5);
floodfill(350,350,WHITE);
area=imagesize(345,345,355,355);
buff=malloc(area);
getimage(345,345,355,355,buff);
putimage(345,345,buff,XOR_PUT);
while (1)
{
putimage(x, y, buff, XOR_PUT);
delay(15);
putimage(x, y, buff, XOR_PUT);
x=x+(xdirn*2);
y=y+(ydirn*3);
if ( x + 10 - 1 > 640 )
{
xdirn*=-1;
x = 640 - 10 + 1;
}
if (x < 0)
{
xdirn*=-1;
x = 0;
}
if ( y + 10 - 1 > 470 )
{
cleardevice();
outtextxy(200,200,"Sorry! You loose the game.");
outtextxy(250,240,"Try Again!!!");
gotoxy(30,8);
cout<<"Total Score : ";
delay(5000);
getch();
goto tt;
}
if(c==1020)
{
outtextxy(180,200,"Congrats! You have finished the game.");
gotoxy(30,8);
cout<<"Total Score : ";
delay(5000);
getch();
goto tt;
}
if ( getpixel(x,y)==1 )
{
sound(500);
delay(15);
nosound();
ydirn*=-1;
}
if (getpixel(x,y)==6)
{
sound(100);
delay(50);
nosound();
ydirn*=-1;
xc=x;
yc=y;
a=xc/52;
b=(yc/27);
xr=a*52;
yr=b*27;
putimage(xr,yr,bu,XOR_PUT);
c+=10;
}
if (getpixel(x,y)==8)
{
sound(800);
delay(200);
nosound();
ydirn*=-1;
xc=x;
yc=y;
a=xc/52;
b=(yc/27);
xr=a*52;
yr=b*27;
putimage(xr,yr,buf,XOR_PUT);
c+=100;
}
if( y < 0 )
{
ydirn*=-1;
y=0;
}
gotoxy(65,1);
cout<<"SCORE : ";
if(kbhit())
{
s=getkey();
if(s!=1)
{
if(X>480)
{
X=480;
putimage(160+X,445+Y,buff1,XOR_PUT);
}
if(X<-80)
{
X=-80;
putimage(80+X,445+Y,buff1,XOR_PUT);
}
putimage(80+X,445+Y,buff1,XOR_PUT);
if(s==75)
X+=-40;
if(s==77)
X+=40;
putimage(80+X,445+Y,buff1,XOR_PUT);
}
if(s==1)
{
tt: free(bu);
free(buff);
free(buff1);
closegraph();
exit(0);
}
}
}
free(bu);
free(buff);
free(buff1);
closegraph();
}
int getkey()
{
union REGS j,o;
j.h.ah=0;
int86(22,&j,&o);
return(o.h.ah);
}
Subscribe to:
Posts (Atom)


