// Filename : BACKGRND.C // Coded by : Scott Evans // Created/Modified : 1/3/98 // Description : Contains functions for Bouncer 2 maps #include "backgrnd.h" #include "sprmap.h" #include "bouncer.h" // Variables in other modules extern GAME_DATA gd; extern OBJECT_LIST_HEADER gun_objects,platform_objects,fan_objects,wind_objects_list; // Current level data buffer byte level_buffer[MAX_MAP_COLUMNS*MAX_MAP_ROWS]; // Function : InitBackground() // Coded by : Scott Evans // Created/Modified : 1/3/98 // 15/7/98 Modified to make use of texture cache // Description : Initialise a background // Parameters : info - pointer to sprite information for map blocks // bg - pointer to background structure // r - define on screen area of background // Returns : None // Notes : None void InitBackground(SPRITE_DATA_INFO *info,BACKGRND *bg,RECT *r) { static OBJECT block; BRIGHTNESS b={0x80<ot[0]=ot; //bg->ot[1]=ot+1; // Clear object structure bzero((u_byte *)&block,sizeof(OBJECT)); // Set object type to GsSPRITE block.type_code=GsSPRITE_OBJECT; // Allow the object to be faded block.allow_fading=1; // Set up sprite used to draw map SetGsSPRITE(&block.type.gss,0,0,0,info->offsets[FIRST_MAP_BLOCK_SPRITE].w,info->offsets[FIRST_MAP_BLOCK_SPRITE].h, info->tpage,0,0,info->cx,info->cy+info->offsets[FIRST_MAP_BLOCK_SPRITE].clut_y,0x80,0x80,0x80,0,0,ONE,ONE,0); SetObjectsBrightness(&block,&b); bg->block=█ // Set up background structure setRECT(&bg->area,r->x,r->y,r->w,r->h); bg->xoff=bg->yoff=0; bg->info=info->offsets; bg->rows=bg->columns=0; bg->no_diamonds=0; // Set blocks width and height bg->bw=info->offsets[FIRST_MAP_BLOCK_SPRITE].w; bg->bh=info->offsets[FIRST_MAP_BLOCK_SPRITE].h; // Set backgrounds CLUT position bg->cx=info->cx; bg->cy=info->cy; // Set level data buffer bg->data=&level_buffer[0]; #ifdef DEBUG_INFO PrintFM("Completed\n"); #endif } // Function : SortBackground() // Coded by : Scott Evans // Created/Modified : 1/3/98 // 15/7/98 Modified to make better use of texture cache // Description : Sort a sprite background in ordering table // Parameters : bg - pointer to background to draw // ot - pointer to ordering table // priority - priority of background in ordering table // Returns : None // Notes : None void SortBackground(BACKGRND *bg,GsOT *ot,u_word priority) { //static u_byte b=0; GsSPRITE *sprite; u_word r,c,h,w,x,y,offset; u_byte blockw,blockh; byte block_no; // Set background screen area h=bg->area.h; w=bg->area.w; y=bg->area.y; // Blocks width and height blockw=bg->bw; blockh=bg->bh; sprite=&bg->block->type.gss; // Clear OT used by background //b=++b&1; //GsClearOt(0,priority,bg->ot[b]); // Draw each row of map for(r=0;rarea.x; offset=(r+bg->yoff)*w; for(c=0;cdata[c+offset])&0x80)) { sprite->x=x; sprite->y=y; sprite->u=bg->info[block_no].u; sprite->v=bg->info[block_no].v; sprite->cy=bg->cy+bg->info[block_no].clut_y; // Build list of primitives in order of texture types ensure best use of texture cache //GsSortFastSprite(sprite,bg->ot[b],block_no); GsSortFastSprite(sprite,ot,priority); } x+=blockw; } y+=blockh; } // Add the background OT to the main OT //GsSortOt(bg->ot[b],ot); } // Function : CopyLevelToBuffer() // Coded by : Scott Evans // Created/Modified : 2/3/98 // Description : Fades the brightness of the background // Parameters : bg - pointer to background to draw // l - pointer to level data // n - level number to load // Returns : None // Notes : None void CopyLevelToBuffer(BACKGRND *bg,LevelHeader *l,u_word n) { // Find parameter block for level LevelPblk *pblock=_GetLevelPblk(l,n); // Calculate size of level u_long size=pblock->nrows*pblock->nclms; // Copy level data to level buffer memcpy(&level_buffer[0],(byte *)pblock+pblock->offset,size); bg->rows=pblock->nrows; bg->columns=pblock->nclms; bg->no_diamonds=pblock->ndiamonds; #ifdef DEBUG_INFO sprintf(fm_string,"Level %d = %d (bytes)\n",n,size); PrintFM(fm_string); sprintf(fm_string,"Rows = %d Columns = %d Diamonds = %d\n",bg->rows,bg->columns,bg->no_diamonds); PrintFM(fm_string); #endif } // Function : MoveBackground() // Coded by : Scott Evans // Created/Modified : 3/3/98 // Description : Moves the background a row at a time // Parameters : bg - pointer to background to draw // mode - UP or DOWN // Returns : Updated position in map // Notes : None u_word MoveBackground(BACKGRND *bg,u_byte mode) { word yoffset; switch(mode) { case UP: yoffset=bg->bh; if(bg->yoff>0) { bg->yoff--; // Move any fans, guns moving platforms etc.. MoveBackgroundObjects(yoffset); } break; case DOWN: if(bg->yoffrows) bg->yoff++; yoffset=-bg->bh; break; } // Check the new row for any background objects CheckMapRow(bg,0); return(bg->yoff); } // Function : GetMapBlock() // Coded by : Scott Evans // Created/Modified : 3/3/98 // Description : Get block number from map // Parameters : bg - pointer to background // row,column - position in map // Returns : Block number // Notes : None byte GetMapBlock(BACKGRND *bg,u_word row,u_word column) { return(bg->data[((row+bg->yoff)*bg->area.w)+column]); } // Function : SetMapBlock() // Coded by : Scott Evans // Created/Modified : 3/3/98 // Description : Set block number in map // Parameters : bg - pointer to background // row,column - position in map // block - block number to set // Returns : None // Notes : None void SetMapBlock(BACKGRND *bg,u_word row,u_word column,byte block) { bg->data[((row+bg->yoff)*bg->area.w)+column]=block; } // Function : InitLevel() // Coded by : Scott Evans // Created/Modified : 7/3/98 // Description : Initialise a level // Parameters : bg - pointer to background // l - pointer to levels // n - level number to initialise // Returns : None // Notes : None void InitLevel(BACKGRND *bg,LevelHeader *l,u_word n) { u_word r; CopyLevelToBuffer(bg,l,n); // Set offset into level bg->yoff=bg->rows-bg->area.h; for(r=0;rarea.h;r++) CheckMapRow(bg,r); #ifdef DEBUG_INFO sprintf(fm_string,"Level %d initialised\n",n); PrintFM(fm_string); sprintf(fm_string,"%d guns created\n",gun_objects.no_objects); PrintFM(fm_string); sprintf(fm_string,"%d platforms created\n",platform_objects.no_objects); PrintFM(fm_string); sprintf(fm_string,"%d fans created\n",fan_objects.no_objects); PrintFM(fm_string); #endif } // Function : CheckMapRow() // Coded by : Scott Evans // Created/Modified : 31/3/98 // Description : Check a map row for special blocks // Parameters : bg - pointer to background // row - number of row to check // Returns : None // Notes : None void CheckMapRow(BACKGRND *bg,u_word row) { u_word c; word block_type; // Check the row for interactive objects for(c=0;carea.w;c++) { block_type=GetMapBlock(bg,row,c); switch(block_type) { case GUN_FACING_LEFT_MAP_BLOCK+2: case GUN_FACING_RIGHT_MAP_BLOCK+2: CreateGunSprite(block_type,row,c); break; case MOVING_PLATFORM_LEFT_MAP_BLOCK: CreateMovingPlatformSprite(row,c); break; } if(block_type>=FAN_FACING_UP_MAP_BLOCK && block_type<=FAN_FACING_RIGHT_MAP_BLOCK+4) CreateFanSprite(block_type,row,c); } } // Function : MoveBackgroundObjects() // Coded by : Scott Evans // Created/Modified : 2/6/98 // Description : Move all the background objects when the level scrolls // Parameters : y - the amount to move each object // Returns : None // Notes : None void MoveBackgroundObjects(word y) { MoveObjectsOnMap(&gun_objects,y); MoveObjectsOnMap(&platform_objects,y); MoveObjectsOnMap(&fan_objects,y); // Also need to move the wind objects MoveObjectsOnMap(&wind_objects_list,y); } // Function : MoveBackgroundObjects() // Coded by : Scott Evans // Created/Modified : 2/6/98 // Description : Move all the background objects // Parameters : y - the amount to move each object // Returns : None // Notes : None void MoveObjectsOnMap(OBJECT_LIST_HEADER *lh,word y) { OBJECT *o=lh->start; while(o) { if(!o->dying) { o->screen.vy+=y; o->position.vy=o->screen.vy<next; } } }