outportb(0x3c9, DEPTH(63));
outportb(0x3c9, DEPTH(i));
enable();
}
/*
int RandPixel(int x,int y,int x1,int y1,int x2,int y2)
{
int col;
col = (GetRand()%200 - 100) * (abs(x-x1)+abs(y-y1)) / (GRIDSIZE/6)
+((_GetGrid(x1,y1)+_GetGrid(x2,y2)) >> 1);
if (col < 1) col = 1;
if (col > 255) col = 255;
_PutGrid(x,y,col);
return col;
*/
void DoPlasma(int x1, int y1, int x2, int y2)
int x,y,s,p;
if (x2-x1 <= 1 && y2-y1 <= 1)
return;
x = (x1+x2) >> 1;
y = (y1+y2) >> 1;
if ((p = _GetGrid(x, y1)) == 0)
p = RandPixel(x,y1,x1,y1,x2,y1);
s = p;
if ((p = _GetGrid(x2,y)) == 0)
p = RandPixel(x2,y,x2,y1,x2,y2);
s += p;
if ((p = _GetGrid(x,y2)) == 0)
p = RandPixel(x,y2,x1,y2,x2,y2);
if ((p = _GetGrid(x1,y)) == 0)
p = RandPixel(x1,y,x1,y1,x1,y2);
if (_GetGrid(x,y) == 0)
_PutGrid(x,y,s >> 2);
DoPlasma(x1,y1,x,y);
DoPlasma(x,y1,x2,y);
DoPlasma(x1,y,x,y2);
DoPlasma(x,y,x2,y2);
void BlankGrid(int x1,int y1,int x2,int y2)
register int x,y;
for (y = y1; y <= y2; y++)
for (x = x1; x <= x2; x++)
_PutGrid(x,y,0);
void NewLand(int x1,int y1,int x2,int y2)
unsigned av = 0;
int val;
int num = 0;
if ((val = _GetGrid(x1,y1)) > 0)
av += val;
num++;
if ((val = _GetGrid(x2,y1)) > 0)
if ((val = _GetGrid(x2,y2)) > 0)
if ((val = _GetGrid(x1,y2)) > 0)
if (!av || GetRand() % 32 == 0)
av = GetRand() % 256;
else
av /= num;
if (_GetGrid(x1,y1) == 0)
_PutGrid(x1,y1, av + (GetRand() % 80 -40));
if (_GetGrid(x2,y1) == 0)
_PutGrid(x2,y1, av + (GetRand() % 80 -40));
if (_GetGrid(x2,y2) == 0)
_PutGrid(x2,y2, av + (GetRand() % 80 -40));
if (_GetGrid(x1,y2) == 0)
_PutGrid(x1,y2, av + (GetRand() % 80 -40));
DoPlasma(x1,y1,x2,y2);
void Test(void)
register int p;
register int x;
int y;
for (y = 0,p = idx; y < GRIDSIZE; y++)
for (x = 0; x < GRIDSIZE; x++, p = (p+1) % MASK)
C_Plot(x,y,max(grid[p],63) >> 2);
for (x = 0; x < VIEWSIZE; x++)
C_Plot(gx+x, gy, 0);
C_Plot(gx+x, gy+VIEWSIZE, 0);
C_Plot(gx, gy+x, 0);
C_Plot(gx+VIEWSIZE, gy+x, 0);
for (y = 0, p = gp; y < VIEWSIZE; y++, p += DIFF)
for (x = 0; x < VIEWSIZE; x++,p++)
C_Plot(gx+x,gy+y,*p >> 3);
void ClearScr(void)
register unsigned i;
for (i = 0; i < (320U*150); i++)
pokeb(0xa000,i,0);
void check_gx(void)
if (gx < 0)
idx = (idx-DIFF/2 + MASK) % MASK;
gx = START-1;
BlankGrid(0,0, DIFF/2-1, GRIDSIZE-1);
NewLand(0,0,DIFF/2,GRIDSIZE/4);
NewLand(0,GRIDSIZE/4,DIFF/2,2*GRIDSIZE/4);
NewLand(0,2*GRIDSIZE/4,DIFF/2,3*GRIDSIZE/4);
NewLand(0,3*GRIDSIZE/4,DIFF/2,GRIDSIZE-1);
else if (gx >= DIFF)
idx = (idx+DIFF/2) % MASK;
gx = START+1;
BlankGrid(GRIDSIZE-DIFF/2,0, GRIDSIZE-1, GRIDSIZE-1);
NewLand(GRIDSIZE-DIFF/2-1,0,GRIDSIZE-1,GRIDSIZE/4);
NewLand(GRIDSIZE-DIFF/2-1,GRIDSIZE/4,GRIDSIZE-1,
2*GRIDSIZE/4);
NewLand(GRIDSIZE-DIFF/2-1,2*GRIDSIZE/4,GRIDSIZE-1,
3*GRIDSIZE/4);
NewLand(GRIDSIZE-DIFF/2-1,3*GRIDSIZE/4,GRIDSIZE-1,
GRIDSIZE-1);
void check_gy(void)
if (gy < 0)
idx = (idx-DIFF/2*GRIDSIZE + MASK) % MASK;
gy = START-1;
BlankGrid(0,0, GRIDSIZE-1, DIFF/2-1);
NewLand(0,0,GRIDSIZE/4,DIFF/2);
NewLand(GRIDSIZE/4,0,2*GRIDSIZE/4,DIFF/2);
NewLand(2*GRIDSIZE/4,0,3*GRIDSIZE/4,DIFF/2);
NewLand(3*GRIDSIZE/4,0,GRIDSIZE-1,DIFF/2);
else if (gy >= DIFF)
idx = (idx+DIFF/2*GRIDSIZE) % MASK;
gy = START+1;
BlankGrid(0,GRIDSIZE-DIFF/2,GRIDSIZE-1, GRIDSIZE-1);
NewLand(0,GRIDSIZE-DIFF/2-1,GRIDSIZE/4,GRIDSIZE-1);
NewLand(GRIDSIZE/4,GRIDSIZE-DIFF/2-1,
2*GRIDSIZE/4,GRIDSIZE-1);
NewLand(2*GRIDSIZE/4,GRIDSIZE-DIFF/2-1,
3*GRIDSIZE/4, GRIDSIZE-1);
NewLand(3*GRIDSIZE/4,GRIDSIZE-DIFF/2-1,
GRIDSIZE-1,GRIDSIZE-1);
void main(void)
int rollspeed = 0;
int xspeed = 0, yspeed = 0;
int i;
rand_seed = (unsigned) time(NULL);
/* rand_seed = 2; */
for (i = 0; i<(360+90); i++)
sn_tbl[i]=(int)(sin((double)i / 180.0*3.14159265) * (double)(1<<SHIFT));
NewLand(0,0,GRIDSIZE-1,GRIDSIZE-1);
SetMode();
SetPalette();
// goto skip;
for (;;)
Test();
switch(getch())
case 27:
SetTextMode();
exit(0);
case 'e':
gx--;
check_gx();
break;
case 'r':
gx++;
case 'w':
gy--;
check_gy();
case 's':
gy++;
case ' ':
goto skip;
gp = CalcAddress(gx,gy);
while (kbhit())
getch();
skip:
;
SetMyMode();
// yspeed = -1;
// rollspeed = (rollspeed+358) % 360;
if (kbhit())
case 'q':
cz += 50;
case 'a':
cz -= 50;
case 'u':
cy -= 50;
case 'j':
cy += 50;
case 'Q':
cpitch = (cpitch+1) % 360;
case 'A':
cpitch = (cpitch+359) % 360;
case 'E':
if (xspeed > -1) xspeed--;
case 'R':
if (xspeed < 1) xspeed++;
case 'W':
if (yspeed > -1) yspeed--;
case 'S':
if (yspeed < 1) yspeed++;
case 'i':
roll = (roll+1) % 360;
case 'o':
roll = (roll+359) % 360;
case 'I':
rollspeed = (rollspeed+1) % 360;
case 'O':
rollspeed = (rollspeed+359) % 360;
rollspeed = 0;
xspeed = yspeed = 0;
cz = DEF_DIST;
cy = DEF_HEIGHT;
roll = DEF_ROLL;
cpitch = DEF_PITCH;
gy += yspeed;
gx += xspeed;
roll = (roll+rollspeed) % 360;
roll_sine = sine(roll);
roll_cosine = cosine(roll);
pitch_sine = sine(cpitch);
pitch_cosine = cosine(cpitch);
ClearMyScreen();
Project();
SwapScreens();
Робота з програмою
Далі наведено три скріншоти, які описують процес удару по м”ячику.
Висновки
Була розроблена комп'ютерна гра “Гольф 3D” з елементами трьохвимірної графіки на основі функцій прямого доступу до відеопам'яті в системі MS DOS. При розробці програми використовувався пакет BORLAND C++ 3.0 та бібліотека BGI.
Література.
Касаткин А.И., Вальвачев А.Н. Профессиональное прогрпммирование на языке Си. Мн., 1992. 240 С.
Нейбауэр А. Моя первая программа на С/С++. П., 1995. 368 С.
Бруно Бабэ. Просто и ясно о Borland C++. М., 1996. 400 С.
Шамас Н.К. Основы С++ и обьектно-ориентированного программирования. К., 1996. 448 С.
Справочник по классам Borland C++ 4.0. К., 1994. 256 С.
ObjectWindows для C++. К., 1993., 208 С.
Том Сван. Программирование для Windows в Borland C++. М., 480 С.
Н. Барканати. Программирование игр для Windows на Borland C++. М., 1994. 512 С.
Страницы: 1, 2, 3, 4