// Filename : MESSAGE.C // Coded by : Scott Evans // Created/Modified : 13/6/98 // Description : B2 message system #include "message.h" u_byte *message_strings[MAX_PAGES][MAX_STRINGS_PER_PAGE+1]={{"Move the screen with","the controller","Press & to CONTINUE","Press ^ to CANCEL",0,0,0}, {"Bouncer 2","Designed, developed and","produced by Scott Evans","First Net Yaroze project","Press & to CONTINUE",0,0,0}, {"Move bat with controller","Shoulder buttons for speed","& to flip bat","~ to set bomb","@ for magnetic beam","^ to release bloke","Press & to CONTINUE",0}, {"Save Game","Press & to SAVE","Press ^ to CANCEL",0,0,0,0}, {"Load Game","Press & to LOAD","Press ^ to CANCEL",0,0,0,0}, {"Saving...","Game saved","Press & to CONTINUE","Memory card ERROR",0,0,0}, {"Loading...","Game loaded","Press & to CONTINUE","Memory card ERROR",0,0,0}, {"Format Card","Press & to FORMAT","Press ^ to CANCEL",0,0,0,0}, {"Formatting...","Format complete","Press & to CONTINUE","Memory card ERROR",0,0,0}, {"Exit Game","Press & to EXIT","Press ^ to CANCEL",0,0,0,0}}; extern OBJECT_LIST_HEADER objects_list,paused_objects; extern SPRITE_DATA_INFO font_sprite_info; extern BRIGHTNESS brightness[]; extern PROGRAM_DATA pd; extern SOUND_DATA *sounds; extern VOLUME menu_volume; extern GAME_DATA gd; OBJECT_LIST_HEADER message_objects; FONT_INFO message_font; u_word current_mpage=0; // Function : InitMessageSystem() // Coded by : Scott Evans // Created/Modified : 13/6/98 // Description : Initialise the message system // Parameters : None // Returns : None // Notes : None void InitMessageSystem(void) { // Set up the object list InitObjectList(&message_objects); // Set the font used for the messages SetFontInfo(&message_font,&font_sprite_info,&message_objects,(8*3)/2,(8*3)/2,&brightness[GAME_MESSAGE_BRIGHTNESS],(ONE*3)/2,(ONE*3)/2); } // Function : CreateTextPage() // Coded by : Scott Evans // Created/Modified : 13/6/98 // Description : Create a page of text messages // Parameters : strings - pointer to array of strings // area - screen area to draw messages in // n - umber of messages created // Returns : Pointer to object strings created // Notes : None OBJECT_STRING *CreateTextPage(u_byte *strings[],RECT *area,u_word *n) { static OBJECT_STRING message_strings[MAX_STRINGS_PER_PAGE]; VECTOR pos={0,SCREEN_HEIGHT+16,0}; word i,w; for(i=0;strings[i];i++) { w=strlen(strings[i])*message_font.cw; pos.vx=area->x+((area->w-w)>>1); PrintString(strings[i],&message_font,&pos,&message_strings[i]); // Decrease the brightness of each message message_font.brightness.r-=(0x12<extra[2]) { if(o->timer) o->timer--; else { if(!o->can_move && o->extra[1]) PlaySoundEffect(sounds,&menu_volume,SFX_MESSAGE_WOOSH); o->can_move=1; } // Bounce each message sligthly if(o->velocity.vy>0 && o->screen.vy>o->extra[0]) { o->screen.vy=o->extra[0]; o->position.vy=o->screen.vy<velocity.vy=-1.6*FPN24_8; } } } // Function : CreateMessages() // Coded by : Scott Evans // Created/Modified : 13/6/98 // Description : Create all page of messages // Parameters : page - page number to create // yspacing - space between each message // Returns : Pointer to objects // Notes : None OBJECT_STRING *CreateMessages(u_word page,word yspacing) { RECT r={0,0,SCREEN_WIDTH,SCREEN_HEIGHT}; OBJECT_STRING *s; OBJECT *o; u_word i,j,n,y,h; long d; // Create the messages s=CreateTextPage(&message_strings[page],&r,&n); // Work out y pos of 1st message if(page==SAVEPROGRESS_MESSAGES || page==LOADPROGRESS_MESSAGES || page==FORMATPROGRESS_MESSAGES) h=((n-1)*message_font.ch)+((n-3)*yspacing); else h=(n*message_font.ch)+((n-2)*yspacing); y=r.y+((r.h-h)>>1); // Set all the objects that make up the messages for(i=0;inext) { SetObjectsAcceleration(o,0,0.2,0); SetObjectsDefaultProperties(o); SetObjectsHandler(o,HandleTextPageMessage); o->extra[0]=y; d=o->extra[0]<velocity.vy=((d-o->position.vy)/40)-(o->acceleration.vy*20); o->can_move=0; o->timer=SECOND*i; // Don't hold message o->extra[2]=1; // Mark the first object of each string if(j==0) o->extra[1]=1; } y+=yspacing; } return(s); } // Function : ClearMessages() // Coded by : Scott Evans // Created/Modified : 13/6/98 // Description : Kil all the message objects // Parameters : l - message object list // Returns : None // Notes : None void ClearMessages(OBJECT_LIST_HEADER *l) { OBJECT *next,*o=l->start; PARTICLE_EXPLOSION explosion; while(o) { next=o->next; if(!gd.paused) SetParticleExplosion(&explosion,&objects_list,HandleMessageExplosionFragment,2,280,2,2,0,0); else SetParticleExplosion(&explosion,&paused_objects,HandleMessageExplosionFragment,2,280,2,2,0,0); setVECTOR(&explosion.maxvel,4,6,0); setVECTOR(&explosion.acc,0,0.2*FPN24_8,0); explosion.b.r=o->brightness.r; explosion.b.g=o->brightness.g; explosion.b.b=o->brightness.b; setRECT(&explosion.r,o->screen.vx,o->screen.vy,8,8); CreateParticleExplosion(&explosion); RemoveObjectFromList(&message_objects,o); o=next; } } // Function : HandleMessageExplosionFragment() // Coded by : Scott Evans // Created/Modified : 13/6/98 // Description : Control explosion fragments // Parameters : o - pointer to object to handle // Returns : None // Notes : None void HandleMessageExplosionFragment(OBJECT *o) { u_byte is_fading=FadeObjectBrightness(o,&brightness[GAME_MIN_BRIGHTNESS],35<type.p.timer>0) o->type.p.timer--; // Kill fragment if(!o->type.p.timer || !is_fading || o->screen.vx<0 || o->screen.vx>pd.screen.w || o->screen.vy<0 || o->screen.vy>pd.screen.h) { if(!gd.paused) RemoveObjectFromList(&objects_list,o); else RemoveObjectFromList(&paused_objects,o); } } // Function : DisplayMessages() // Coded by : Scott Evans // Created/Modified : 13/6/98 // Description : Display all message objects // Parameters : ot - pointer to ordering table // priority - ordering table priority // Returns : None // Notes : None void DisplayMessages(GsOT *ot,u_word priority) { UpdateObjects(&message_objects); SortObjects(&message_objects,ot,priority); } // Function : KillMessages() // Coded by : Scott Evans // Created/Modified : 13/6/98 // Description : Kill all the message objects // Parameters : None // Returns : None // Notes : None void KillMessages(void) { ClearMessages(&message_objects); } // Function : StopMessage() // Coded by : Scott Evans // Created/Modified : 21/7/98 // Description : Stop a message from appearing // Parameters : os - string of objects that make up one message // Returns : None // Notes : None void StopMessage(OBJECT_STRING *os) { OBJECT *o=os->start; u_byte i; for(i=0;ilength;i++) { o->extra[2]=0; o=o->next; } } // Function : StartMessage() // Coded by : Scott Evans // Created/Modified : 21/7/98 // Description : Makes a message appear // Parameters : os - string of objects that make up one message // t - time from now to show message // Returns : None // Notes : None void StartMessage(OBJECT_STRING *os,u_word t) { OBJECT *o=os->start; u_byte i; for(i=0;ilength;i++) { o->extra[2]=1; o->timer=t; o=o->next; } } // Function : SetMessagePosition() // Coded by : Scott Evans // Created/Modified : 21/7/98 // Description : Sets new destination position for message // Parameters : os - string of objects that make up one message // b - new birghtness // y - new position // Returns : None // Notes : None void SetMessagePosition(OBJECT_STRING *os,BRIGHTNESS *b,word y) { OBJECT *o=os->start; u_byte i; long d; for(i=0;ilength;i++) { // Set new position and calculate new velocity o->extra[0]=y; d=o->extra[0]<velocity.vy=((d-o->position.vy)/40)-(o->acceleration.vy*20); // Set new brightness SetObjectsBrightness(o,b); o=o->next; } }