⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 general.cpp

📁 上面上传的autotools一文(也就是《使用GNU autotools 改造一个软件项目》)配套的示例程序源代码。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
      SDL_UnlockSurface(gpScreen);   }   for (i = 0; i < 4; i++) {      DrawUTF8Text(&dat[i * 4], 150 + i * 100, 100, 2, 255, 255, 0);      UpdateScreen();      PlaySound(SND_SOUND1);      UTIL_Delay(1300);   }   DrawUTF8Text(&dat[i * 4], 175, 200, 2, 0, 255, 255);   PlaySound(SND_DISCARD2);   UpdateScreen();   UTIL_Delay(2500);   ScreenFade();}void CGeneral::DrawText(const char *sz, int x, int y, int size, int r, int g, int b){   SDL_Surface *text;   SDL_Rect dstrect;   SDL_Color textcolor = {r, g, b, 0};   SDL_Color black = {0x10, 0x8, 0x8, 0};   TTF_Font *f = (size == 0 ? m_fontBrush : (size == 1 ? m_fontBrushL : m_fontBrushH));   text = TTF_RenderText_Blended(f, sz, black);   dstrect.x = x + 2;   dstrect.y = y + 2;   SDL_BlitSurface(text, NULL, gpScreen, &dstrect);   SDL_FreeSurface(text);   text = TTF_RenderText_Blended(f, sz, textcolor);   dstrect.x = x;   dstrect.y = y;   SDL_BlitSurface(text, NULL, gpScreen, &dstrect);   SDL_FreeSurface(text);}void CGeneral::DrawUTF8Text(const char *sz, int x, int y, int size, int r, int g, int b){   SDL_Surface *text;   SDL_Rect dstrect;   SDL_Color textcolor = {r, g, b, 0};   SDL_Color black = {0x10, 0x8, 0x8, 0};   TTF_Font *f = (size == 0 ? m_fontKai : (size == 1 ? m_fontKaiL : m_fontKaiH));   text = TTF_RenderUTF8_Blended(f, sz, black);   dstrect.x = x + 2;   dstrect.y = y + 2;   SDL_BlitSurface(text, NULL, gpScreen, &dstrect);   SDL_FreeSurface(text);   text = TTF_RenderUTF8_Blended(f, sz, textcolor);   dstrect.x = x;   dstrect.y = y;   SDL_BlitSurface(text, NULL, gpScreen, &dstrect);   SDL_FreeSurface(text);}void CGeneral::DrawMessage(const char *sz){   SDL_Rect dstrect, dstrect2;   dstrect.x = 150;   dstrect.y = 300;   dstrect.w = 340;   dstrect.h = 60;   static SDL_Surface *saved = NULL;   if (sz == NULL) {      // Restore the screen      if (saved != NULL) {         SDL_BlitSurface(saved, NULL, gpScreen, &dstrect);         SDL_FreeSurface(saved);         saved = NULL;         SDL_UpdateRect(gpScreen, 150, 300, 340, 60);      }      return;   }   // Save the current screen if no screen is saved   if (saved == NULL) {      saved = SDL_CreateRGBSurface(gpScreen->flags & (~SDL_HWSURFACE),         340, 60, gpScreen->format->BitsPerPixel, gpScreen->format->Rmask,         gpScreen->format->Gmask, gpScreen->format->Bmask,         gpScreen->format->Amask);      SDL_SetAlpha(saved, 0, 0);      SDL_BlitSurface(gpScreen, &dstrect, saved, NULL);   }   // Draw a box to the screen   SDL_Surface *temp = SDL_CreateRGBSurface(gpScreen->flags & (~SDL_HWSURFACE),      340, 60, gpScreen->format->BitsPerPixel, gpScreen->format->Rmask,      gpScreen->format->Gmask, gpScreen->format->Bmask,      gpScreen->format->Amask);   SDL_SetAlpha(temp, 0, 0);   SDL_FillRect(temp, NULL, SDL_MapRGB(temp->format, 100, 100, 100));   dstrect2.x = 5;   dstrect2.y = 5;   dstrect2.w = 330;   dstrect2.h = 50;   SDL_FillRect(temp, &dstrect2, SDL_MapRGB(temp->format, 20, 100, 190));   SDL_BlitSurface(temp, NULL, gpScreen, &dstrect);   SDL_FreeSurface(temp);   int y = 305, t;   char *line = UTIL_StrGetLine(sz, 26, t);   if (strlen(line) >= strlen(sz)) {      y += 12;   } else {      sz += t;      DrawUTF8Text(line, 160, y);      y += 26;      line = UTIL_StrGetLine(sz, 26, t);   }   DrawUTF8Text(line, 160, y);   SDL_UpdateRect(gpScreen, 150, 300, 340, 60);   PlaySound(SND_DING); // play a hint sound}void CGeneral::DrawTile(const CTile &t, int x, int y, int dir, int size){   SDL_Rect dstrect, dstrect2;   dstrect.x = x;   dstrect.y = y;   if (dir <= PLAYER_CONCEALED) {      // shown tile      dstrect.w = dstrect2.w = TILE_WIDTH;      dstrect.h = dstrect2.h = ((dir < PLAYER_CONCEALED) ?         TILE_HEIGHT_SHOWN : TILE_HEIGHT_CONCEALED);      if (t.GetSuit() == TILESUIT_DRAGON) {         dstrect2.x = (t.index2() + 4) * TILE_WIDTH;         dstrect2.y = 3 * dstrect.h;      } else {         dstrect2.x = t.index2() * TILE_WIDTH;         dstrect2.y = t.index1() * dstrect.h;      }      if (dir < PLAYER_CONCEALED) {         dstrect2.y += TILE_HEIGHT_CONCEALED * 4;      }   } else if (dir == COMPUTER_CONCEALED) {      // concealed tile      dstrect2.x = 0;      dstrect2.y = TILE_HEIGHT_SHOWN * 4 + TILE_HEIGHT_CONCEALED * 4;      dstrect2.w = dstrect.w = TILE_WIDTH;      dstrect2.h = dstrect.h = TILE_HEIGHT_COMPUTER;   } else if (dir == WALL_CONCEALED) {      dstrect2.x = TILE_WIDTH;      dstrect2.y = TILE_HEIGHT_SHOWN * 4 + TILE_HEIGHT_CONCEALED * 4;      dstrect2.w = dstrect.w = TILE_WIDTH;      dstrect2.h = dstrect.h = TILE_HEIGHT_WALL;   }   // Draw the tile to the screen   if (size >= 1) {      SDL_BlitSurface(m_imgTiles, &dstrect2, gpScreen, &dstrect);   } else {      dstrect.w = dstrect.w * 7 / 10;      dstrect.h = dstrect.h * 7 / 10;      UTIL_ScaleBlit(m_imgTiles, &dstrect2, gpScreen, &dstrect);   }}void CGeneral::DrawTiles(const CTile t[], int num, int x, int y, int dir, int size){   int i;   if (dir == COMPUTER_SHOWN) {      // Draw computer's tiles in reverse order      for (i = num - 1; i >= 0; i--) {         DrawTile(t[i], (int)(x + (num - i - 1) * TILE_WIDTH * (size ? 1 : 0.7)),            y, dir, size);      }   } else {      // Otherwise draw in normal order      for (i = 0; i < num; i++) {         DrawTile(t[i], (int)(x + i * TILE_WIDTH * (size ? 1 : 0.7)), y, dir, size);      }   }}void CGeneral::DrawDotBar(int x, int y, bool anim){   SDL_Rect dstrect, dstrect2;   dstrect.x = x;   dstrect2.x = 359;   dstrect.w = dstrect2.w = 20;   if (anim) {      int i;      for (i = 0; i < 20; i++) {         dstrect.y = y + (20 - i) * 85 / 40;         dstrect2.y = 531 + (20 - i) * 85 / 40;         dstrect.h = dstrect2.h = i * 85 / 20;         SDL_BlitSurface(m_imgTiles, &dstrect2, gpScreen, &dstrect);         UpdateScreen(dstrect.x, dstrect.y, dstrect.w, dstrect.h);         UTIL_Delay(10);      }   }   dstrect.h = dstrect2.h = 85;   dstrect.y = y;   dstrect2.y = 531;   SDL_BlitSurface(m_imgTiles, &dstrect2, gpScreen, &dstrect);}void CGeneral::DrawTurn(int turn, int x, int y){   SDL_Rect dstrect, dstrect2;   dstrect.x = x;   dstrect.y = y;   dstrect.w = dstrect2.w = 26;   dstrect.h = dstrect2.h = 53;   dstrect2.x = TILE_WIDTH * 2;   dstrect2.x += ((turn == 0) ? 0 : TILE_WIDTH);   dstrect2.y = TILE_HEIGHT_SHOWN * 4 + TILE_HEIGHT_CONCEALED * 4;   SDL_BlitSurface(m_imgTiles, &dstrect2, gpScreen, &dstrect);}void CGeneral::UpdateScreen(int x, int y, int w, int h){   SDL_UpdateRect(gpScreen, x, y, w, h);}void CGeneral::PlayMusic(Mix_Music *m, int loop, int volume){   if (g_fNoMusic) {      return;   }   if (m == NULL) {      Mix_HaltMusic(); // stop playing any music      return;   }   if (volume == -1) {      float f = atof(cfg.Get("OPTIONS", "MusicVolume", "1"));      if (f < 0) {         f = 0;      } else if (f > 1) {         f = 1;      }      volume = (int)(MIX_MAX_VOLUME * f);   }   Mix_VolumeMusic(volume);   Mix_PlayMusic(m, loop);}void CGeneral::PlaySound(Mix_Chunk *s, int volume){   if (g_fNoSound) {      return;   }   if (volume == -1) {      float f = atof(cfg.Get("OPTIONS", "SoundVolume", "1"));      if (f < 0) {         f = 0;      } else if (f > 1) {         f = 1;      }      volume = (int)(MIX_MAX_VOLUME * f);   }   Mix_VolumeChunk(s, volume);   Mix_PlayChannel(-1, s, 0);}void CGeneral::PlaySound(int num, int volume){   if (g_fNoSound) {      return;   }   if (volume == -1) {      float f = atof(cfg.Get("OPTIONS", "SoundVolume", "1"));      if (f < 0) {         f = 0;      } else if (f > 1) {         f = 1;      }      volume = (int)(MIX_MAX_VOLUME * f);   }   PlaySound(m_snd[num], volume);}void CGeneral::PlayBGMusic(int num, int volume){   m_iCurMusic = num;   if (g_fNoMusic) {      return;   }   if (num < 0 || num > 5) {      PlayMusic(NULL); // stop playing any music   }   PlayMusic(m_musBG[num], -1, volume);}void CGeneral::PlayWinMusic(int volume){   if (g_fNoMusic) {      return;   }   PlayMusic(m_musWin, 1, volume);}void CGeneral::PlayEndRoundMusic(int volume){   m_iCurMusic = 8;   if (g_fNoMusic) {      return;   }   PlayMusic(m_musEndRound, -1, volume);}void CGeneral::Fire(){   int i;   SDL_Surface *save = SDL_CreateRGBSurface(gpScreen->flags & (~SDL_HWSURFACE),      575, 130, gpScreen->format->BitsPerPixel, gpScreen->format->Rmask,      gpScreen->format->Gmask, gpScreen->format->Bmask, gpScreen->format->Amask);   SDL_Rect dstrect;   dstrect.x = 5;   dstrect.y = 470 - 130;   dstrect.w = 575;   dstrect.h = 130;   SDL_BlitSurface(gpScreen, &dstrect, save, NULL);   UTIL_Delay(400);   PlaySound(SND_FIRE);   for (i = 0; i < 6; i++) {      dstrect.y = 470 - 125;      dstrect.h = 125;      SDL_BlitSurface(m_imgFire1, NULL, gpScreen, &dstrect);      UpdateScreen(0, 470 - 130, 575, 130);      UTIL_Delay(100);      dstrect.y = 470 - 130;      dstrect.h = 130;      SDL_BlitSurface(save, NULL, gpScreen, &dstrect);      SDL_BlitSurface(m_imgFire2, NULL, gpScreen, &dstrect);      UpdateScreen(0, 470 - 130, 575, 130);      UTIL_Delay(100);      SDL_BlitSurface(save, NULL, gpScreen, &dstrect);   }   UpdateScreen(0, 470 - 130, 575, 130);   SDL_FreeSurface(save);   UTIL_Delay(100);}void CGeneral::AnimSelfDrawn(const CTile &t){   EraseArea(20, 265, TILE_WIDTH * 10, 303 + TILE_HEIGHT_SHOWN - 265);   UpdateScreen(20, 265, TILE_WIDTH * 10, 303 + TILE_HEIGHT_SHOWN - 265);   int i;   SDL_Rect dstrect;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -