不用tile地图填充每个子屏幕,而仅仅是将每个对象放在世界坐标系中的某个位置。将游戏环境分区,创建一个备用的数据结构来跟踪所有的对象。
// size of universe, could be anything
#define MAX_UNIVERSE_X 6400
#define MAX_UNIVERSE_Y 4800
#define NUM_OBJECTS_UNIVERSE 256 // number of objects in the universe
// used to flag type of object
#define GENERATOR_OBJ 0
#define BEACON_OBJ 1
#define ALIEN_OBJ 2
// TYPES ///
// need something to hold each object
typedef struct SPARSE_OBJ_TYP
{
int type; // type of object: beacon, generator, or alien
// could have just used a bob_ptr here, but I like
// doing this the hard way so you can exactly what's happening
int x,y; // position of object
} SPARSE_OBJ, *SPARSE_OBJ_PTR;
// demo globals
BOB generator, // the generator BOB
alien, // a little alien ship BOB
beacon; // a beacon BOB
int world_x = 0, // current position of viewing window
world_y = 0;
SPARSE_OBJ world[NUM_OBJECTS_UNIVERSE];
int Game_Init(void *parms = NULL, int num_parms = 0)
{
// this is called once after the initial window is created and
// before the main event loop is entered, do all your initialization
// here
srand( GetTickCount());
//初始化DDRAW
char filename[80]; // used to build up files names
ddraw->DDraw_Init( main_window_handle, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP );
bob.Load_Bitmap_File(&bitmap8bit, "GENS4.BMP");
ddraw->Set_Palette(bitmap8bit.palette);
if (!bob.Create_BOB( ddraw->getlpdd(),&generator,0,0,72,84,4,
BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_FRAME,DDSCAPS_SYSTEMMEMORY))
return(0);
for ( int index = 0; index < 4; index++)
bob.Load_Frame_BOB(&generator,&bitmap8bit,index,index%4,index/4,BITMAP_EXTRACT_MODE_CELL);
bob.Set_Animation_BOB(&generator, 0);
bob.Set_Anim_Speed_BOB(&generator, 4);
bob.Unload_Bitmap_File(&bitmap8bit);
bob.Load_Bitmap_File(&bitmap8bit, "ALIENS0.BMP");
if (!bob.Create_BOB(ddraw->getlpdd(),&alien,0,0,56,30,8,
BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_FRAME,DDSCAPS_SYSTEMMEMORY))
return(0);
for (int index = 0; index < 8; index++)
bob.Load_Frame_BOB(&alien,&bitmap8bit,index,index%5,index/5,BITMAP_EXTRACT_MODE_CELL);
bob.Set_Animation_BOB(&alien, 0);
bob.Set_Anim_Speed_BOB(&alien, 4);
bob.Unload_Bitmap_File(&bitmap8bit);
bob.Load_Bitmap_File(&bitmap8bit, "PIPE0.BMP");
if (!bob.Create_BOB( ddraw->getlpdd(),&beacon,0,0,42,36,8,
BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_FRAME,DDSCAPS_SYSTEMMEMORY))
return(0);
for ( int index = 0; index < 8; index++)
bob.Load_Frame_BOB(&beacon,&bitmap8bit,index,index%6,index/6,BITMAP_EXTRACT_MODE_CELL);
bob.Set_Animation_BOB(&beacon, 0);
bob.Set_Anim_Speed_BOB(&beacon, 4);
bob.Unload_Bitmap_File(&bitmap8bit);
ShowCursor( FALSE );
// now generate the sparse universe
for ( int index = 0; index < NUM_OBJECTS_UNIVERSE; index++)
{
// set random position
world[index].x = rand()%MAX_UNIVERSE_X;
world[index].y = rand()%MAX_UNIVERSE_Y;
// set type
world[index].type = rand()%3; // 0, 1, 2 generator, alien, beacon
} // end for index
// return success or failure or your own return code here
return(1);
}