home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 31
/
CDASC_31_1996_juillet_aout.iso
/
vrac
/
gamelib.zip
/
EX1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-23
|
2KB
|
66 lines
//a simple example of how to do a vertically scrolling game
//for use with game.lib, created in Turbo C++
#include "alloc.h"
#include "grlib.h"
void main()
{
int a,x=160,y=100,dir=1;
unsigned char *bptr=(unsigned char *)malloc(37*37+2);
InitGameBuff(320,800);//make game buffer 4 screens tall
InitKeyScan();//start up key press scanning
SetVGA(); //set VGA mode 13h
//load in the pictures
if (LoadPic1("back.pcx",0)==0) Quit("Pcx not found");
if (LoadMBM("sph.mbm",1)==0) Quit("mbm not found");
//cover game buffer with backdrop image
PutPic(0,0,0);
PutPic(0,0,200);
PutPic(0,0,400);
PutPic(0,0,600);
//save backdrop area under foreground sphere
CutOut(x-18,y-18,37,37,bptr);
//put foreground sphere
PutMBM(1,x-18,y-18);
//morph viewport from small to full screen size
for(a=90; a>=0; a--) DWinBuffer(a,a,a,a,320-(2*a),200-(2*a));
a=0;
//main loop
do
{
//replace saved backdrop area over foreground sphere
PutBitmap(x-18,y-18,bptr);
//do movement left/right if relevant key pressed
if (CheckKey(77)==1&&x<300) x+=2;
if (CheckKey(75)==1&&x>18) x-=2;
//move sphere in y dimension
if (dir==1) y+=2; else y-=2;
if (y>700) {y=700; dir=0;}
else if (y<100) {y=100; dir=1;}
//save new backdrop area under foreground sphere
CutOut(x-18,y-18,37,37,bptr);
//put foreground sphere
PutMBM(1,x-18,y-18);
//display window on buffer, to the screen
DisplayBuffer(0,y-100);
a++;
}
while(CheckKey(1)!=1&&a<2000); //while escape key not pressed
//close down
FreeMem();
SetTXT();
CloseKeyScan();
}