(長(zhǎng)春 石琳)
在許多游戲軟件中,我們經(jīng)常能看到這樣的場(chǎng)面:當(dāng)某一設(shè)施爆炸后,屏幕畫面會(huì)伴隨著輕微的振動(dòng),使人感到身臨其境。筆者編寫了一個(gè)函數(shù)void MoveView(int x,int y);通過(guò)CRT控制器將屏幕視角左上角坐標(biāo)移至 (x,y)處,使畫面相對(duì)移動(dòng),從而產(chǎn)生振動(dòng)效果。程序由Borland C++ 2.0編寫,采用VGA 12H模式,代碼小、速度快、運(yùn)行效果形象逼真。 // filename: SHAKE.cpp // maker: ShiLin #include #include #include #include void MoveView(int x,int y); void main(void){ int gdriver,gmode; gdriver=DETECT,gmode=0; initgraph(&gdriver,&gmode,"BORLANDCBGI"); rectangle(100,100,200,200); outtextxy(100,250,"Press Any Key to SHAKE ..."); getch(); for(int i=0;i<20;i++){ MoveView(10-random(20),5-random(10)); delay(50); } MoveView(0,0); getch(); closegraph(); } void MoveView(int x,int y){ union{ unsigned int whole; char low; }adr; unsigned char high,low; adr.whole=y*80+x/8, low=adr.low, high=(unsigned char)(adr.whole>>8); outportb(0x3D4,0X0C); outportb(0x3D5,high); outportb(0x3D4,0x0D); outportb(0x3D5,low); }
|