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

📄 racex.cpp

📁 Visual C++ 游戏开发与设计实例 源代码(所有)
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				if(m_iOption == 40) m_iOption = 42 + m_pMultiPlayer.GetNumSPOptions();
				if(m_iOption == 50) m_iOption = 53;
				lLastOption = GetTickCount();
				m_sndChangeOption.Play();
			}

			// If user hit the enter, space or numpadenter
			// Select the next screen or menu depending on the option
			// the user selected
			if(m_Keyboard.CheckKey(DIK_RETURN) ||
			   m_Keyboard.CheckKey(DIK_NUMPADENTER) ||
			   m_Keyboard.CheckKey(DIK_SPACE) )
			{
				lLastOption = GetTickCount();

				switch(m_iOption)
				{
				case 1:
					// Single Player
					// Set the option to 11 to go to the next menu
					m_iOption = 11;
					m_bIsMultiplayer = FALSE;
					m_sndSelect.Play();
					break;
				case 2:
					// Multiplayer Player
					// Set the option to 21 to go to the next menu
					m_iOption = 21;
					m_bIsMultiplayer = TRUE;
					m_sndSelect.Play();
					break;
				case 3:
					m_iState = GS_HELP;
					iStart = 0;
					m_sndSelect.Play();
					break;
				case 4:
					// Options Menu
					m_iOption = 51;
					break;
				case 5:
					m_iState = GS_CREDITS;
					iStart = 0;
					m_sndSelect.Play();
					break;
				case 13:
				case 23:
				case 33:
				case 53:
					// Selected the "BACK" option, go back to the top-level menu
					m_iOption = 1;
					m_sndSelect.Play();
					break;
				case 12:
					// Single Player - Competition Mode
					// Go to the Car Selection Screen
					m_pCompetition.SetCompetitionMode(TRUE);
					m_surfHelmet.Destroy();
					m_surfTitle.Destroy();
					m_iState = GS_SELECTTRACK_AND_CAR;
					iStart = 0;
					m_sndSelect.Play();
					break;
				case 11:
					// Single Player - Single Track
					// Go to the Track selection Screen
					m_pCompetition.SetCompetitionMode(FALSE);
					m_surfHelmet.Destroy();
					m_surfTitle.Destroy();
					m_iState = GS_SELECTTRACK_AND_CAR;
					iStart = 0;
					m_sndSelect.Play();
					break;
				case 21:
					// Create a new multiplayer game
					m_iOption = 31;
					m_sndSelect.Play();
					break;
				case 22:
					// Join a Multiplayer Session
					m_pCompetition.SetCompetitionMode(FALSE);
					m_surfHelmet.Destroy();
					m_surfTitle.Destroy();
					m_iState = GS_JOINGAME;
					iStart = 0;
					m_sndSelect.Play();
					break;
				case 32:
					// New MultiPlayer - Competition Mode
					// Go to the Car Selection Screen
					m_pCompetition.SetCompetitionMode(TRUE);
					m_surfHelmet.Destroy();
					m_surfTitle.Destroy();
					m_iState = GS_CREATEGAME;
					iStart = 0;
					m_sndSelect.Play();
					break;
				case 31:
					// New MultiPlayer - Single Track
					// Go to the Track selection Screen
					m_pCompetition.SetCompetitionMode(FALSE);
					m_surfHelmet.Destroy();
					m_surfTitle.Destroy();
					m_iState = GS_CREATEGAME;
					iStart = 0;
					m_sndSelect.Play();
					break;
				case 51:
					// Multiplayer Options Menu
					m_iOption = 41;
					break;
				case 52:
					// Set the difficulty level
					m_iDifficultyLevel+=20;
					if(m_iDifficultyLevel > 80)
						m_iDifficultyLevel = 0;
					m_pMultiPlayer.SetRegDWValue("DifficultyLevel", (DWORD) m_iDifficultyLevel);
					break;
				case 6:
					// Quit
					PostQuitMessage(0);
					break;
				case 41:
					// Change the Network Service Provider (Modem, LAN, Serial, etc.)
					m_pMultiPlayer.NextSP();
					m_sndChangeOption.Play();
					break;
				}

				if(m_iOption == 42 + m_pMultiPlayer.GetNumSPOptions())
				{
					m_iOption = 51;
					m_sndSelect.Play();
				}

				if(m_iOption > 41 &&
				   m_iOption < 42 + m_pMultiPlayer.GetNumSPOptions())
				{
					if(m_pMultiPlayer.GetSPOptionType(m_iOption-42) == 0)
					{
						m_pMultiPlayer.AdvanceSPOption(m_iOption-42);
					}
				}

			}
		}

		break;

	case GS_SELECTTRACK_AND_CAR:
		// This screen let the user select the track for a single track 
		// game
		#define PANEL_POSITION 220

		BOOL	bHalfScreen, bShowTitle;

		if(m_pCompetition.GetCompetitionMode() == TRUE)
		{
			bShowTitle = TRUE;
			bHalfScreen = TRUE;
		}
		else
		{
			bShowTitle = FALSE;
			if(m_bIsMultiplayer == TRUE && m_pMultiPlayer.IsHosting() == FALSE)
				bHalfScreen = TRUE;
			else
				bHalfScreen = FALSE;
		}

		if(iStart == 0)
		{
			// First create a list of Track files avaible
			m_iOption = 0;
			m_iTrack = 0;

			sort(pTrackNames.begin(), pTrackNames.end(), string_compare);

			m_surfTitle.Destroy();

			m_sptrCar.Create(GetInstHandle(), IDB_BIGCAR_BLUE + m_iOption, 750, 560, 0, 150, 140);

			m_surfCaret.Create(2,15);
			m_surfCaret.LoadBitmap(GetInstHandle(), IDB_CARET);

			m_surfCursor.Create(32, 32, RGB(0,0,0));
			m_surfCursor.LoadBitmap(GetInstHandle(), IDB_CURSOR);

			if(bShowTitle)
			{
				m_surfTitle.Create(600,198);
				m_surfTitle.LoadBitmap(GetInstHandle(), IDB_TITLE_COMPETITION);
			}

			iStart = 1;
			m_sPlayerName = "";
			m_sndType.Create(MAKEINTRESOURCE(IDR_TYPE), DSBCAPS_CTRL3D, DS3DALG_NO_VIRTUALIZATION);
			
			if(bHalfScreen == FALSE)
			{			
				pRaceTrack.Destroy();
				pRaceTrack.ReadFromFile(pTrackNames[m_iOption]);
				// I磍l reuse the helmet surface object FOR THE BACKGROUND
				m_surfHelmet.Create(640, 480, RGB(0,0,0));
				m_surfHelmet.LoadBitmap(GetInstHandle(), IDB_BACKGROUND);
			}
			else
			{
				// I磍l reuse the helmet surface object FOR THE BACKGROUND
				m_surfHelmet.Create(640, 220, RGB(0,0,0));
				m_surfHelmet.LoadBitmap(GetInstHandle(), IDB_BACKGROUND2);
			}
			m_iX = 0; m_iY = 0;
			m_iIncrX = 5;
			m_iIncrY = 0;
		}

		//sprintf(buffer, "X:%.2d Y:%.2d B0: %d B1: %d", m_Mouse.GetX(), m_Mouse.GetY(), m_Mouse.GetRightButton(), m_Mouse.GetLeftButton());
		//m_sPlayerName = buffer;


		iCaretPos = 132;
		
		if(GetTickCount() - lLastCaret > 100)
		{
			bShowCaret = !bShowCaret;
			lLastCaret = GetTickCount();
		}

		if(m_sPlayerName.length() > 0)
		{
			if(bHalfScreen == FALSE)
			{
				iCaretPos = m_txDigital.WriteText(m_pBackBuffer, &m_sPlayerName[0], 130, 20);
			}
			else
			{
				iCaretPos = m_txDigital.WriteText(m_pBackBuffer, &m_sPlayerName[0], 130, 20+PANEL_POSITION);
			}
		}

		if(bShowCaret)
		{
			if(bHalfScreen == FALSE)
				m_surfCaret.Draw(m_pBackBuffer, iCaretPos+2, 21);
			else
				m_surfCaret.Draw(m_pBackBuffer, iCaretPos+2, 21+PANEL_POSITION);
		}
		
		
		if(bHalfScreen == FALSE)
		{
			sprintf(buffer, "%.2d", pRaceTrack.GetNumberOfLaps());
			m_txDigital.WriteText(m_pBackBuffer, pRaceTrack.GetTrackName(), 402, 268);
			m_txDigital.WriteText(m_pBackBuffer, buffer, 402, 322);

			RECT rcDest, rcSrc;
			rcDest.top = 110; rcDest.left = 60;
			rcDest.bottom = 440; rcDest.right = 390;//585;

			rcSrc.left = 0; rcSrc.top = 0;
			rcSrc.right = pRaceTrack.GetWidth();
			rcSrc.bottom = pRaceTrack.GetHeight();

			pRaceTrack.Draw(16, 69, m_iX, m_iY, 370, 370); 
		}
		

		// Draw the big car sprite
		#define CARX 440
		#define CARY 40
		if(GetTickCount() - lLastSprite > 60)
		{
			if(bHalfScreen == FALSE)
				m_sptrCar.Draw(m_pBackBuffer, CARX, CARY);
			else
				m_sptrCar.Draw(m_pBackBuffer, CARX, CARY+PANEL_POSITION);
			lLastSprite = GetTickCount();
		}
		else
		{
			if(bHalfScreen == FALSE)
				m_sptrCar.Draw(m_pBackBuffer, CARX, CARY, FALSE);
			else
				m_sptrCar.Draw(m_pBackBuffer, CARX, CARY+PANEL_POSITION, FALSE);
		}
		
		m_iX += m_iIncrX;
		m_iY += m_iIncrY;

		if(m_iX + 370 >= pRaceTrack.GetWidth())
		{
			if(m_iY % 370 == 0 && m_iIncrY != 0)
			{
				m_iIncrX = -5;
				m_iIncrY = 0;
			}
			else
			{
				m_iIncrX = 0;
				m_iIncrY = 5;
			}

			if(m_iY + 370 >= pRaceTrack.GetWidth())
			{
				m_iIncrY = 0;
				m_iIncrX = 5;
				m_iX = 0;
				m_iY = 0;
			}
		}

		if(m_iX <= 0)
		{
			if(m_iY % 370 == 0 && m_iIncrY != 0)
			{
				m_iIncrX = 5;
				m_iIncrY = 0;
			}
			else
			{
				m_iIncrX = 0;
				m_iIncrY = 5;
			}

			if(m_iY + 370 >= pRaceTrack.GetWidth())
			{
				m_iIncrY = 0;
				m_iIncrX = 5;
			}
		}
		
		// Draw the bounding box
		if(bHalfScreen == FALSE)
			m_surfHelmet.Draw(m_pBackBuffer, 0, 0);
		else
		{
			if(bShowTitle)
				m_surfTitle.Draw(m_pBackBuffer, 20, 5);
			m_surfHelmet.Draw(m_pBackBuffer, 0, PANEL_POSITION+4);
		}

		m_Keyboard.Process();
		m_Mouse.Process();

		CheckInput(&m_sPlayerName, 20);

		m_surfCursor.Draw(m_pBackBuffer, m_Mouse.GetX(), m_Mouse.GetY(), 0, 0, m_Mouse.GetX() > 640-32 ? 640-m_Mouse.GetX() : 0, m_Mouse.GetY() > 480-32 ? 480-m_Mouse.GetY() : 0 );

		if(GetTickCount() - lLastOption > 200)
		{

			int iTmpPos;
			int	iX, iY;

			iX = m_Mouse.GetX();
			iY = m_Mouse.GetY();
			
			if(bHalfScreen == TRUE)
				iY -= PANEL_POSITION;

			// Check if the user hit the Car selection buttons
			if( iX > 448 &&    iY > 14    &&
				iX < 448+68 && iY < 14+16 &&
				m_Mouse.GetLeftButton() == FALSE)
			{
				m_iOption++;
				if(m_iOption == 4)
					m_iOption = 0;
				iTmpPos = m_sptrCar.m_iAbsolutePosition;
				m_sptrCar.Create(GetInstHandle(), IDB_BIGCAR_BLUE + m_iOption, 750, 560, 0, 150, 140);
				m_sptrCar.m_iAbsolutePosition = iTmpPos;
				lLastOption = GetTickCount();
				m_sndChangeOption.Play();
			}

			if( iX > 522 &&    iY > 14    &&
				iX < 522+68 && iY < 14+16 &&
				m_Mouse.GetLeftButton() == FALSE)
			{
				m_iOption--;
				if(m_iOption == -1)
					m_iOption = 3;
				iTmpPos = m_sptrCar.m_iAbsolutePosition;
				m_sptrCar.Create(GetInstHandle(), IDB_BIGCAR_BLUE + m_iOption, 750, 560, 0, 150, 140);
				m_sptrCar.m_iAbsolutePosition = iTmpPos;
				lLastOption = GetTickCount();
				m_sndChangeOption.Play();
			}			
			
			// Check if the user hit the Track Selection Buttons
			if( iX > 211 &&     iY > 431    &&
				iX < 211+125 && iY < 431+25 &&
				m_Mouse.GetLeftButton() == FALSE &&
				bHalfScreen == FALSE)
			{
				m_iTrack++;
				if(m_iTrack == pTrackNames.size())
					m_iTrack = 0;
				pRaceTrack.Destroy();
				pRaceTrack.ReadFromFile(pTrackNames[m_iTrack]);
				lLastOption = GetTickCount();
				m_sndChangeOption.Play();
				m_iX = 0; m_iY = 0;
				m_iIncrX = 5;m_iIncrY = 0;
			}

			if( iX > 73 &&     iY > 431    &&
				iX < 73+125 && iY < 431+25 &&
				m_Mouse.GetLeftButton() == FALSE &&
				bHalfScreen == FALSE)
			{
				m_iTrack--;
				if(m_iTrack < 0)
					m_iTrack = pTrackNames.size()-1;
				pRaceTrack.Destroy();
				pRaceTrack.ReadFromFile(pTrackNames[m_iTrack]);
				lLastOption = GetTickCount();
				m_sndChangeOption.Play();
				m_iX = 0; m_iY = 0;
				m_iIncrX = 5;m_iIncrY = 0;
			}

			if(m_Keyboard.CheckKey(DIK_RETURN) ||
			   m_Keyboard.CheckKey(DIK_NUMPADENTER) )
			{
				m_sndSelect.Play();
				m_surfHelmet.Destroy();
				m_sptrCar.Destroy();

				if(m_bIsMultiplayer)
				{
					// Regardless if its competition or single track,
					// go to the wait screen
					m_iState = GS_NETWORKSTATUS;
					iStart = 0;
					m_sndSelect.Play();
					lLastOption = GetTickCount();
					if(m_pMultiPlayer.IsHosting())
					{
						m_pCompetition.AddPlayer(m_sPlayerName, IDB_CAR_BLUE + m_iOption, CTRL_USER, 0, 0);
						m_pCompetition.SetReadyState(0, TRUE);
					}
					else
					{
						DWORD	dwTemp = IDB_CAR_BLUE + m_iOption;
						memcpy(&buffer[0], &dwTemp, sizeof(DWORD));
						memcpy(&buffer[4],(char*) &m_sPlayerName[0], m_sPlayerName.size());
						m_pMultiPlayer.SendTo(m_pMultiPlayer.GetHost(), MSG_PLAYER_INFO, (LPBYTE) buffer, m_sPlayerName.size() + sizeof(DWORD), DPNSEND_SYNC | DPNSEND_NOLOOPBACK | DPNSEND_GUARANTEED);
					}
				}
				else
				{
					m_pCompetition.AddPlayer("COMPUTER 1", m_iOption == 0 ? IDB_CAR_YEALLOW : IDB_CAR_BLUE, CTRL_COMPUTER, 1, 1);
					m_pCompetition.AddPlayer("COMPUTER 2", m_iOption == 1 ? IDB_CAR_YEALLOW : IDB_CAR_GREEN, CTRL_COMPUTER,2, 2);
					m_pCompetition.AddPlayer("COMPUTER 3", m_iOption == 2 ? IDB_CAR_YEALLOW : IDB_CAR_RED, CTRL_COMPUTER,3, 3);
					m_pCompetition.AddPlayer(m_sPlayerName, IDB_CAR_BLUE + m_iOption, CTRL_USER, 0, 0);

					if(m_pCompetition.GetCompetitionMode() == TRUE)
					{
						// Single Player - Competition
						// Go to the Competition Status Screen
						m_iState = GS_COMPETITIONSTATUS;

⌨️ 快捷键说明

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