player.c

Go to the documentation of this file.
00001 
00024 #include "color.h"
00025 #include "game.h"
00026 #include "tanksprite.h"
00027 #include <string.h>
00028 #include <assert.h>
00029 
00030 
00031 Uint32 localPlayer = 0;
00032 Uint8  localUpdateFlags;
00033 
00034 Player players[MAX_PLAYERS] = { 0 };
00035 
00036 void AddPlayer(Player *p) {
00037     #ifdef MSG_DEBUG
00038     printf("Init player %d\n", p->pid);
00039     #endif
00040     assert(p->tank.renderer == NULL);
00041     assert(p->shell.renderer == NULL);
00042     // make the player active
00043     p->flags |= PLAYER_ACTIVE;
00044     p->deadTime = DEAD_TIME + 1;
00045     // create the required render items
00046     // start with the tank
00047     p->tank.loc.x = (p->x >> 8) * dInfo.luw;
00048     p->tank.loc.y = (p->y >> 8) * dInfo.luh;
00049     p->tank.loc.w = dInfo.luw * 8;
00050     p->tank.loc.h = dInfo.luh * 8;
00051     p->tank.renderer = DrawTank;
00052     AddRenderItem(&(p->tank), LAYER_TANKS);
00053     if (!(p->flags & PLAYER_DEAD)) {
00054         QueuePlaceTank(p->pid);
00055     }
00056     // add the shell
00057     p->shell.loc.w = dInfo.luw;
00058     p->shell.loc.h = dInfo.luh;
00059     p->shell.data = &(colorVals[p->team]);
00060     p->shell.renderer = SolidFillRenderer;
00061     AddRenderItem(&(p->shell), LAYER_TANKS);
00062     // check for an unset name
00063     if (p->name[0] == 0) {
00064         // set a default name
00065         rtsa_strcpy(p->name, strings[STRING_DEFAULTNAME]);
00066     }
00067     // render the player's name
00068     else if (TextRenderString(&(p->labelName), FONT_PLAYER, 0,
00069     colorFmtInd[COLOR_BLACK], p->name)) {
00070         // add the name
00071         AddRenderItem(&(p->labelName), LAYER_NAMES);
00072         if (dInfo.showLabels && !(p->flags & PLAYER_DEAD)) {
00073             PlacePlayerLabel(p);
00074         }
00075     }
00076 }
00077 
00078 void RemovePlayer(Player *p) {
00079     // see if the player is still active
00080     if (p->flags & PLAYER_ACTIVE) {
00081         // clear the player's render items
00082         ClearRenderItem(&(p->tank));
00083         // remove the player's render items
00084         RemoveRenderItem(&(p->tank));
00085         ClearRenderItem(&(p->shell));
00086         RemoveRenderItem(&(p->shell));
00087         // check for an existing name label
00088         if (p->labelName.renderer != NULL) {
00089             ClearRenderItem(&(p->labelName));
00090             RemoveRenderItem(&(p->labelName));
00091         }
00092         // get rid of any rendered text used for the player
00093         if (p->labelName.data) {
00094             SDL_FreeSurface(p->labelName.data);
00095         }
00096         /*
00097         if (p->largeName.data) {
00098             SDL_FreeSurface(p->largeName.data);
00099         }
00100         if (p->scoreText.data) {
00101             SDL_FreeSurface(p->scoreText.data);
00102         }
00103         */
00104     }
00105     // clear out everything
00106     memset(p, 0, sizeof(Player));
00107     //p->flags = 0;
00108 }

Generated on Mon May 28 04:41:39 2007 for Retro Tank Super Attack by  doxygen 1.5.2