00001 00026 #include <SDL_image.h> 00027 #include <string.h> 00028 #include <stdlib.h> 00029 #include "states.h" 00030 #include "color.h" 00031 #include "obstacle.h" 00032 #include "tanksprite.h" 00033 #include "message.h" 00034 00035 extern RenderItem background; 00036 00041 Uint32 startTime; 00042 00046 Player *tanks; 00047 00054 static void SplashResize() { 00055 int loop; 00056 // assure good color values 00057 SetupColorVals(); 00058 // put the backgound image in place 00059 background.loc.w = dInfo.pw; 00060 background.loc.h = dInfo.ph; 00061 PlaceRenderItem(&background); 00062 // title at the top 00063 textItems[TEXTITEM_TITLE].loc.y = TOP_MARGIN; 00064 // author a short distance down 00065 textItems[TEXTITEM_AUTH].loc.y = textItems[TEXTITEM_TITLE].loc.y + 00066 textItems[TEXTITEM_TITLE].loc.h + TOP_MARGIN; 00067 // is there a translator? 00068 if (textItems[TEXTITEM_TRANS].parent) { 00069 // place the translator credit further down 00070 textItems[TEXTITEM_TRANS].loc.y = textItems[TEXTITEM_AUTH].loc.y + 00071 textItems[TEXTITEM_AUTH].loc.h + TOP_MARGIN; 00072 } 00073 // GPL notice up from the bottom 00074 textItems[TEXTITEM_GPL].loc.y = dInfo.ph - textItems[TEXTITEM_GPL].loc.h 00075 - BOTTOM_MARGIN; 00076 // loop to p[ace things up from the bottom -- this was more useful before 00077 // multi-line text support was added 00078 for (loop = TEXTITEM_GPL - 1; loop >= TEXTITEM_COPYRIGHT; loop--) { 00079 textItems[loop].loc.y = textItems[loop + 1].loc.y - 00080 textItems[loop].loc.h; 00081 } 00082 // center all text horizontally 00083 for (loop = TEXTITEM_TITLE; loop < TEXTITEM_GPL + 1; loop++) { 00084 // make sure the item exists -- translator may not 00085 if (textItems[loop].parent) { 00086 // compute the centered location 00087 textItems[loop].loc.x = (dInfo.pw >> 1) - 00088 (textItems[loop].loc.w >> 1); 00089 // place the item 00090 PlaceRenderItem(&(textItems[loop])); 00091 } 00092 } 00093 // place two tanks 00094 tanks[0].tank.loc.w = tanks[0].tank.loc.h = 00095 tanks[1].tank.loc.w = tanks[1].tank.loc.h = dInfo.luw << 3; 00096 tanks[0].tank.loc.x = 32; 00097 tanks[1].tank.loc.x = dInfo.pw - tanks[0].tank.loc.w - 32; 00098 tanks[0].tank.loc.y = tanks[1].tank.loc.y = 00099 (dInfo.ph - tanks[0].tank.loc.h) >> 1; 00100 PlaceRenderItem(&(tanks[0].tank)); 00101 PlaceRenderItem(&(tanks[1].tank)); 00102 } 00103 00104 int SplashInit() { 00105 memset(&background, 0, sizeof(background)); 00106 // get memory for a couple tanks to use as icons 00107 if ((tanks = calloc(2, sizeof(Player))) == NULL) { 00108 // out of memory 00109 return STATE_ERROR; 00110 } 00111 // setup position of screen parts 00112 dInfo.luw = dInfo.luh = 8; 00113 dInfo.lw = dInfo.pw / dInfo.luw; 00114 dInfo.lh = dInfo.ph / dInfo.luh; 00115 // put the backgound image in place 00116 background.renderer = SolidFillRenderer; 00117 background.data = &(colorVals[COLOR_REGBACK]); 00118 AddRenderItem(&background, LAYER_BACKGROUND); 00119 // initalize two tanks 00120 tanks[0].tank.renderer = tanks[1].tank.renderer = DrawTank; 00121 tanks[0].rot = 4 << 8; 00122 //tanks[0].team = 0; // implied because of calloc 00123 tanks[1].rot = 12 << 8; 00124 tanks[1].team++; 00125 AddRenderItem(&(tanks[0].tank), LAYER_TANKS); 00126 AddRenderItem(&(tanks[1].tank), LAYER_TANKS); 00127 // set the text color 00128 colorFmtInd[COLOR_TEXT] = colorFmtInd[COLOR_BLACK]; 00129 // attempt to render all the text off-screen 00130 if (!TextSetupStateSplash()) return STATE_ERROR; 00131 // place all the text 00132 SplashResize(); 00133 // record the time 00134 startTime = SDL_GetTicks(); 00135 return STATE_OK; 00136 } 00137 00138 int SplashUninit() { 00139 // see if a background image, rather than a color, was used 00140 if (background.renderer == GenericSurfaceRenderer) { 00141 // remove the background image 00142 SDL_FreeSurface(background.data); 00143 } 00144 RemoveRenderItem(&background); 00145 RemoveRenderItem(&(tanks[0].tank)); 00146 RemoveRenderItem(&(tanks[1].tank)); 00147 free(tanks); 00148 TextUnsetState(); 00149 return STATE_OK; 00150 } 00151 00152 int SplashRun() { 00153 SDL_Event event; 00154 00155 // loop through all waiting events 00156 while (SDL_PollEvent(&event)) { 00157 // figure event type 00158 switch (event.type) { 00159 case SDL_QUIT: 00160 return STATE_QUIT; 00161 break; 00162 case SDL_KEYDOWN: 00163 // check for a request to quit the program 00164 if (event.key.keysym.sym == SDLK_ESCAPE) 00165 return STATE_QUIT; 00166 break; 00167 case SDL_KEYUP: 00168 case SDL_JOYBUTTONDOWN: 00169 // enforce a minimum delay 00170 if ((SDL_GetTicks() - startTime) > 127) 00171 return STATE_MENUROOT; 00172 break; 00173 case SDL_VIDEORESIZE: 00174 ResizeWindow(event.resize.w, event.resize.h); 00175 SplashResize(); 00176 default: 00177 break; 00178 } 00179 } 00180 // ----- run network code ---- 00181 // Without this, if the client quickly connects to a server it will not 00182 // respond until running the menu state, which can be long enough for the 00183 // server to decide that the client is not responding. 00184 ProcessNetworkMessages(); 00185 // see if enough time has been spent on the splash screen 00186 if ((SDL_GetTicks() - startTime) > 4095) { 00187 // move on to the menu 00188 return STATE_MENUROOT; 00189 } 00190 // continue with the splash screen 00191 return STATE_SPLASH; 00192 } 00193