Аркадна гра "гольф" з елементами трьохвимірної поверхні
{
av += val;
num++;
}
if ((val = _GetGrid(x2,y2)) > 0)
{
av += val;
num++;
}
if ((val = _GetGrid(x1,y2)) > 0)
{
av += val;
num++;
}
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++;
check_gx();
break;
case 'w':
gy--;
check_gy();
break;
case 's':
gy++;
check_gy();
break;
case ' ':
goto skip;
}
gp = CalcAddress(gx,gy);
while (kbhit())
getch();
}
skip:
;
SetMyMode();
SetPalette();
gp = CalcAddress(gx,gy);
// yspeed = -1;
// rollspeed = (rollspeed+358) % 360;
for (;;)
{
if (kbhit())
{
switch(getch())
{
case 27:
SetTextMode();
exit(0);
case 'q':
cz += 50;
break;
case 'a':
cz -= 50;
break;
case 'u':
cy -= 50;
break;
case 'j':
cy += 50;
break;
case 'Q':
cpitch = (cpitch+1) % 360;
break;
case 'A':
cpitch = (cpitch+359) % 360;
break;
case 'E':
if (xspeed > -1) xspeed--;
break;
case 'R':
if (xspeed < 1) xspeed++;
break;
case 'e':
gx--;
break;
case 'r':
gx++;
break;
case 'W':
if (yspeed > -1) yspeed--;
break;
case 'S':
if (yspeed < 1) yspeed++;
break;
case 'w':
gy--;
break;
case 's':
gy++;
break;
case 'i':
roll = (roll+1) % 360;
break;
case 'o':
roll = (roll+359) % 360;
break;
case 'I':
rollspeed = (rollspeed+1) % 360;
break;
case 'O':
rollspeed = (rollspeed+359) % 360;
break;
case ' ':
rollspeed = 0;
xspeed = yspeed = 0;
cz = DEF_DIST;
cy = DEF_HEIGHT;
roll = DEF_ROLL;
cpitch = DEF_PITCH;
break;
}
while (kbhit())
getch();
}
gy += yspeed;
gx += xspeed;
check_gx();
check_gy();
gp = CalcAddress(gx,gy);
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 С.