Code:
//right click and set Target expert , platform = DOS(Standard), Libraries = BGI
#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
void double_h_line(int x1,int x2,int y);
void double_v_line(int x1,int y1,int y2);
void doublewindow(int x1,int y1,int x2, int y2);
void new_doublewindow(int x1, int y1, int x2, int y2);
void single_h_line(int x1,int x2,int y);
void single_v_line(int x,int y1,int y2);
void singlewindow(int x1,int y1,int x2,int y2,int ul,int ur);
void mouse_call(int regax,int regbx,int regcx,int regdx);
void first(void);
void second(void);
void third(void);
void initialize(void);
int globax, globbx, globcx, globdx;
int in_int;
void main(void)
{
do{
//set the background then clear the screen
textbackground(BLUE);
clrscr();
highvideo();
textcolor(WHITE);
doublewindow(2,2,79,24);
//Editor title
gotoxy(35,2);
cprintf("ALL IN ONE (Graphics in BGI)");
textbackground(LIGHTGRAY);
textbackground(BLUE);
gotoxy(30,5);
cprintf("1.Move Object");
gotoxy(30,10);
cprintf("2.The eyes");
gotoxy(30,15);
cprintf("3.Digital Clock");
gotoxy(30,20);
cprintf("4. EXIT");
in_int = getch();
switch (in_int)
{
case 49:
first();
break;
case 50:
second();
break;
case 51:
third();
break;
case 52:
exit(0);
}
}while(1);
}
void first(void)
{
initialize();
int gdriver = DETECT, gmode ,x ,y;
char num;
void *image;
unsigned int imsize;
initgraph(&gdriver, &gmode, "c:\\bc5\\bgi");
setcolor(15);
rectangle(0,0,639,479);
setcolor(15);
rectangle(4,4,635,474);
// My image
setcolor(BLUE);
rectangle(50,35,100,200);
setfillstyle(1,YELLOW);
floodfill(99,68,BLUE);
arc(51,34,270,360,48);
arc(101,199,90,180,48);
imsize = imagesize(48,34,101,201);
image = malloc(imsize);
getimage(48,34,101,201,image);
settextjustify(CENTER_TEXT, CENTER_TEXT);
setcolor(LIGHTRED);
outtextxy(320,320, "Please press a key to continue. . .");
getch();
clearviewport();
setcolor(15);
rectangle(0,0,639,479);
setcolor(15);
rectangle(4,4,635,474);
x=270;
y=125;
putimage(x,y,image, XOR_PUT);
do{
num=getch();
// Move up
if(num=='8')
{
setfillstyle(SOLID_FILL,BLACK);
bar(x,y,x+53,y+167);
putimage(x,y-=5,image,XOR_PUT);
cprintf("ALL IN ONE BGI");
}
// Move Left
if(num=='4')
{
setfillstyle(SOLID_FILL,BLACK);
bar(x,y,x+53,y+167);
putimage(x-=5,y,image,XOR_PUT);
}
// Move Right
if(num=='6')
{
setfillstyle(SOLID_FILL,BLACK);
bar(x,y,x+53,y+167);
putimage(x+=5,y,image,XOR_PUT);
}
// Move Down
if(num=='2')
{
setfillstyle(SOLID_FILL,BLACK);
bar(x,y,x+53,y+167);
putimage(x,y+=5,image,XOR_PUT);
}
// Move Down left
else
{
setfillstyle(SOLID_FILL,BLACK);
bar(x,y,x+53,y+167);
putimage(x+1,y+1,image,XOR_PUT);
}
}while(num!=27);
getch();
closegraph();
}
void second(void)
{
char ch='a';
initialize();
setbkcolor(LIGHTGRAY);
mouse_call(1,0,0,0);
do{
delay(1000);
//left eye
mouse_call(3,0,0,0);
setfillstyle(1,RED);
fillellipse(140, 250, 90, 50);
setfillstyle(1,GREEN);
fillellipse(140, 250, 50, 50);
mouse_call(3,0,0,0);
mouse_call(19,0,0,0);
getpixel(globcx,globdx);
if (RED == getpixel(globcx, globdx))
{
setfillstyle(1,random(15)+4);
fillellipse(140, 250, 25, 50);
}
//right eye
setfillstyle(1,RED);
fillellipse(480, 250, 90, 50);
setfillstyle(1,GREEN);
fillellipse(480, 250, 50, 50);
mouse_call(3,0,0,0);
getpixel(globcx,globdx);
if (RED == getpixel(globcx, globdx))
{
setfillstyle(1,random(15)+4);
fillellipse(480, 250, 25, 25);
fillellipse(140, 250, 25, 25);
}
mouse_call(1,0,0,0);
if(kbhit())
ch = getch();
}while(ch!=27);
closegraph();
return;
}
void third(void)
{
initialize();
char buffer[80];
char c;
struct time t;
do{
delay(200);
clearviewport();
setcolor(WHITE);
gettime(&t);
sprintf(buffer, "%02d:%02d:%02d", t.ti_hour,t.ti_min,t.ti_sec);
settextstyle(GOTHIC_FONT, HORIZ_DIR, 5);
outtextxy(250,200,buffer);
}while(!kbhit());
getch();
closegraph();
}
void initialize(void)
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\bc5\\bgi");
}
void mouse_call(int regax,int regbx,int regcx,int regdx)
{
union REGS inregs, outregs;
inregs.x.ax=regax;
inregs.x.bx=regbx;
inregs.x.cx=regcx;
inregs.x.dx=regdx;
int86(0x33, &inregs, &outregs);
globax=outregs.x.ax;
globbx=outregs.x.bx;
globcx=outregs.x.cx;
globdx=outregs.x.dx;
}
void double_h_line(int x1,int x2,int y)
{
gotoxy(x1,y);
for(int col=x1;col<=x2;col++)
{
gotoxy(col,y);
cprintf("%c",205);
}
}
void double_v_line(int x,int y1,int y2)
{
gotoxy(x,y1);
for(int row=y1;row<=y2;row++)
{
gotoxy(x,row);
cprintf("%c",186);
}
}
void doublewindow(int x1,int y1,int x2,int y2)
{
//draws a double line window
//upper line
gotoxy(x1,y1);
cprintf("%c",201);
double_h_line(x1+1,x2-1,y1);
//right line
gotoxy(x2,y1);
cprintf("%c",187);
double_v_line(x2,y1+1,y2-1);
//bottom line
gotoxy(x2,y2);
cprintf("%c",188);
double_h_line(x1+1,x2-1,y2);
//left line
gotoxy(x1,y2);
cprintf("%c",200);
double_v_line(x1,y1+1,y2-1);
gotoxy(x1+1,y1+1);
}
Here's a program that I compiled in Borland 5 with out a problem except that when I run it it has the pixalation problem that I've been explaining in one part. The initial menu that pops up is fine all the text is readable and looks normal. However if I choose option one, when the text "Please press a key to continue." appears in between each word is the "pixaltion" I've been talking about It's just really annoying and I was wondering if there was a way to get rid of it.