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

📄 logo.cpp

📁 《Visual C 6.0高级编程技术——DirectX篇》程序源代码
💻 CPP
字号:
// Logo.cpp: implementation of the CLogo class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Logo.h"
#include "ddutil.h"
#include "GlobalsExtern.h"
#include "StackUp.h"
#include "Game.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CLogo::CLogo()
{
  m_sBitmapLogo = _T("bmp/logo.bmp");
  m_sBitmapOptions = _T("bmp/options.bmp");

  m_Options.Insert(&g_Options_nPlayerNum,   " Number of players ", 1, 1, 2, 1);
  m_Options.Insert(&g_Options_nPF_XSize,    " Playfield width ", 6, 6, 6, 1);
  m_Options.Insert(&g_Options_nPF_YSize,    " Playfield height ", 10, 10, 10, 1);
  m_Options.Insert(&g_Options_bStartFilled, " Filled playfield ", false, "No", "Yes");
  m_Options.Insert(&g_Options_nPF_ObjType,  " Type of objects ", false, "Quadratic", "Any");
  m_Options.Insert(&g_Options_nPF_ObjNum,   " Number of objects ", 5, 1, 5, 1);
  m_Options.Insert(&g_Options_nPF_ObjXSize, " Objects width ", OBJ_XSIZE, OBJ_XSIZE, OBJ_XSIZE, 2);
  m_Options.Insert(&g_Options_nPF_ObjYSize, " Objects height ", OBJ_YSIZE, OBJ_YSIZE, OBJ_YSIZE, 1);
  m_Options.Insert(&g_Options_bRotateType,  " Type of rotation ", false, "Simplex", "Combinative");
  m_Options.Insert(&g_Options_bSoundFX,     " Sound FX ", true, "Off", "On");
  m_Options.Insert(INIT_GAME, "               S   T   A   R   T               ");
  m_Options.Insert(QUIT, "                  Q   U   I   T                  ");

  m_bKeyUpFlag = false;
  m_bKeyDownFlag = false;
  m_bKeyLeftFlag = false;
  m_bKeyRightFlag = false;
}

CLogo::~CLogo()
{

}

/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//                                                                         //
//  DIRECT DRAW                                                            //
//                                                                         //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////

bool CLogo::DD_Init()
{
  WAITFORVB;
  DDBLTFX blt = { 0 };
  blt.dwSize = sizeof(blt);
  blt.dwFillColor = RGB(255, 255, 255);

  DD_BLT(g_lpDDS_Primary->Blt(0, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &blt));

  m_lpDDP_Logo = DDLoadPalette(g_lpDD, m_sBitmapLogo);
  if(m_lpDDP_Logo)
  {
    g_DX_Result = g_lpDDS_Primary->SetPalette(m_lpDDP_Logo);    // make sure to set the palette before loading bitmaps.
    DD_CHECK_ERROR(_T("Error - DD - SetPalette ")  + m_sBitmapLogo);
  }

  m_lpDDS_Logo = DDLoadBitmap(g_lpDD, m_sBitmapLogo, 0, 0);
  if(!m_lpDDS_Logo)
  {
    AfxMessageBox("Error - DD - LoadBitmap " + m_sBitmapLogo);
    return false;
  }

  m_lpDDS_Options = DDLoadBitmap(g_lpDD, m_sBitmapOptions, 0, 0);
  if(!m_lpDDS_Logo)
  {
    AfxMessageBox("Error - DD - LoadBitmap " + m_sBitmapOptions);
    return false;
  }

  OtherLimits(-1);        // all

  return DD_DrawScreen();
}

/////////////////////////////////////////////////////////////////////////////

bool CLogo::DD_DrawScreen()
{
  m_bMenuChanged = true;
  m_Options.SetCurrentItem(10);              // initial selection - S T A R T

  // clear screen

  DDBLTFX blt = { 0 };
  blt.dwSize = sizeof(blt);
  blt.dwFillColor = RGB(255, 255, 255);

  DD_BLT(g_lpDDS_Secondary->Blt(0, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &blt));
  g_DD_FlipScreens();
  DD_BLT(g_lpDDS_Secondary->Blt(0, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &blt));

  // logo

  RECT rcLogoSrc;
  rcLogoSrc.left   = 0;
  rcLogoSrc.top    = 0;
  rcLogoSrc.right  = LOGO_WIDTH;
  rcLogoSrc.bottom = LOGO_HEIGHT;

  RECT rcOptionsSrc;
  rcOptionsSrc.left   = 0;
  rcOptionsSrc.top    = 0;
  rcOptionsSrc.right  = OPTIONS_WIDTH;
  rcOptionsSrc.bottom = OPTIONS_HEIGHT;

  RECT rcLogoDest;
  RECT rcOptionsDest;

  int x;
  int y;
  for(int i = 1; i <= ZOOM_FRAME_NUM; i++)
  {
    x = LOGO_WIDTH * i / ZOOM_FRAME_NUM;
    y = LOGO_HEIGHT * i / ZOOM_FRAME_NUM;

    rcLogoDest.left   = LOGO_XPOS + (LOGO_WIDTH / 2) - x / 2;
    rcLogoDest.top    = LOGO_YPOS + (LOGO_HEIGHT / 2) - y / 2;
    rcLogoDest.right  = LOGO_XPOS + (LOGO_WIDTH / 2) - x / 2 + x;
    rcLogoDest.bottom = LOGO_YPOS + (LOGO_HEIGHT / 2) - y / 2 + y;

    x = OPTIONS_WIDTH / ZOOM_FRAME_NUM * i;
    y = OPTIONS_HEIGHT / ZOOM_FRAME_NUM * i;

    rcOptionsDest.left   = OPTIONS_XPOS + (OPTIONS_WIDTH / 2) - x / 2;
    rcOptionsDest.top    = OPTIONS_YPOS + (OPTIONS_HEIGHT / 2) - y / 2;
    rcOptionsDest.right  = OPTIONS_XPOS + (OPTIONS_WIDTH / 2) - x / 2 + x;
    rcOptionsDest.bottom = OPTIONS_YPOS + (OPTIONS_HEIGHT / 2) - y / 2 + y;

    WAITFORVB;
    g_DD_FlipScreens();
    DD_BLT(g_lpDDS_Secondary->Blt(&rcLogoDest, m_lpDDS_Logo, &rcLogoSrc, 0, NULL));
    DD_BLT(g_lpDDS_Secondary->Blt(&rcOptionsDest, m_lpDDS_Options, &rcOptionsSrc, 0, NULL));
  }

  WAITFORVB;
  g_DD_FlipScreens();
  DD_BLT(g_lpDDS_Secondary->Blt(&rcLogoDest, m_lpDDS_Logo, &rcLogoSrc, 0, NULL));
  DD_BLT(g_lpDDS_Secondary->Blt(&rcOptionsDest, m_lpDDS_Options, &rcOptionsSrc, 0, NULL));

  PrintText(true);    // print logo text

  return true;
}

/////////////////////////////////////////////////////////////////////////////
// text

void CLogo::PrintText(bool bShow)
{
  HDC hDC;
  if(g_lpDDS_Primary->GetDC(&hDC) == DD_OK)
  {
    SetBkColor(hDC, RGB(255, 255, 255));
    if(bShow)
      SetTextColor(hDC, RGB(0, 128, 255));
    else
      SetTextColor(hDC, RGB(255, 255, 255));

    CString sItem;
    CString sItemValue;
    int j = m_Options.GetItemNum();
    for(int i = 0; i < j; i++)
    {
      WAITFORVB;
      WAITFORVB;
      m_Options.GetItem(i, sItem, sItemValue);
      TextOut(hDC, MENU_XBEG, MENU_YBEG + i * MENU_ITEM_HEIGHT, sItem, lstrlen(sItem));
      TextOut(hDC, MENU_ITEM_XBEG, MENU_YBEG + i * MENU_ITEM_HEIGHT, sItemValue, lstrlen(sItemValue));
    }

    CString sText;
    sText = _T("

⌨️ 快捷键说明

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