RaceX.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:70k
- // RACE X
- //
- // Written by Mauricio Teichmann Ritter
- //
- // Copyright (C) 2002, Brazil. All rights reserved.
- //
- //
- #include "stdafx.h"
- #include "racex.h"
- #include <algorithm>
- // This GUID value is used by DirectPlay. Each direct play game needs a GUID
- // so that we can find sessions of a game in the network
- #ifndef APP_GUID
- #define APP_GUID
- static const GUID g_guidApp =
- { 0xce1aeec6, 0x8291, 0x4b9e, { 0xa1, 0x2, 0x16, 0xd4, 0x19, 0xc1, 0x87, 0x48 } };
- #endif
- cRaceXApp* GetRaceXApp()
- {
- return (cRaceXApp*)GetMainApp();
- }
- int string_compare(string s1, string s2)
- {
- //return strcmp(s1,s2);
- return s1 < s2 ? 1 : 0;
- }
- cApplication* CreateApplication()
- {
- cRaceXApp* theApp;
-
- theApp = new cRaceXApp();
- return (cApplication*)theApp;
- }
- void cRaceXApp::DoIdle()
- {
-
- // In this function is where the game logic starts
- // Each time we don磘 have a system message to process, the cApplication base
- // class will call the DoIdle virtual function
-
- DDBLTFX ddbltfx;
- char buffer[255];
-
- // This static variables are used to control some game timings
- static long lLastIdle = 0;
- static long lLastOption = 0;
- static long lLastSprite = 0;
- static long lLastCaret = 0;
- static BOOL bShowCaret = FALSE;
- int iCaretPos;
- cRaceCar* pTmpCar;
- string sTmp;
- long lStart;
- int i = 0, j = 0;
- // The frames are processed in a 30 miliseconds rate
- // If we didn磘 reach the 30 milisecond mark, we磍l not flip
- // the primary surface
- if(GetTickCount() - lLastIdle < 30)
- {
- PreventFlip();
- return;
- }
- // Update the LastIdle variable
- lLastIdle = GetTickCount();
- // Clear the BackBuffer with black color
- ddbltfx.dwSize = sizeof(ddbltfx);
- ddbltfx.dwFillColor = RGB(0,0,0);
- GetMainApp()->m_pBackBuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx );
- // Based on the game state we磍l show each game screen
- switch(m_iState)
- {
- case GS_HELP:
- // Help screen
- m_txDigital.WriteText(m_pBackBuffer, "RACING WITH RACEX", 200, 40);
- m_txDigital.WriteText(m_pBackBuffer, "UP ARROW", 50, 140);
- m_txDigital.WriteText(m_pBackBuffer, "ACCELERATE THE CAR", 270, 140);
- m_txDigital.WriteText(m_pBackBuffer, "RIGHT ARROW", 50, 180);
- m_txDigital.WriteText(m_pBackBuffer, "TURN THE CAR CLOCKWISE", 270, 180);
- m_txDigital.WriteText(m_pBackBuffer, "LEFT ARROW", 50, 220);
- m_txDigital.WriteText(m_pBackBuffer, "TURN THE CAR UNCLOCKIWISE", 270, 220);
- m_txDigital.WriteText(m_pBackBuffer, "DOWN ARROW", 50, 260);
- m_txDigital.WriteText(m_pBackBuffer, "BREAK THE CAR", 270, 260);
- m_txDigital.WriteText(m_pBackBuffer, "PRESS ENTER TO CONTINUE", 160, 360);
- // If the user hit enter os space or escape, go back to the main screen
- m_Keyboard.Process();
- if(GetTickCount() - lLastOption > 200)
- {
- if(m_Keyboard.CheckKey(DIK_RETURN) ||
- m_Keyboard.CheckKey(DIK_NUMPADENTER) ||
- m_Keyboard.CheckKey(DIK_SPACE) ||
- m_Keyboard.CheckKey(DIK_ESCAPE))
- {
- m_iState = GS_MAINSCREEN;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- }
- break;
- case GS_WAITCOMPETITION:
-
- // This game state is used the multiplayer game.
- // When we磖e in the competiton mode, we磍l show this screen
- // when we already saw the competition status screen but the
- // other network player didn磘 saw it yet.
- if(iStart = 0)
- {
- lLastSprite = 0;
- }
- if(GetTickCount() - lLastSprite > 500)
- {
- bShowCaret = !bShowCaret;
- lLastSprite = GetTickCount();
- }
- if(bShowCaret)
- {
- m_txDigital.WriteText(m_pBackBuffer, "WAITING OTHER PLAYERS", 180, 120);
- m_txDigital.WriteText(m_pBackBuffer, "LOOK AT COMPETITION RESULTS", 125, 180);
- m_txDigital.WriteText(m_pBackBuffer, "PLEASE WAIT...", 225, 240);
- }
- // Check if all the players are ready (saw the competition status)
- // If so, go to the next race
- if(m_pCompetition.AllPlayersReady() && m_pMultiPlayer.IsHosting())
- {
- strcpy(buffer, pRaceTrack.GetFileName());
- i = strlen(buffer);
- m_pMultiPlayer.SendTo(0, MSG_START_RACE, (unsigned char *) &buffer[0], i, DPNSEND_SYNC | DPNSEND_NOLOOPBACK | DPNSEND_GUARANTEED);
- m_iState = GS_RACE;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- break;
- case GS_WAIT:
- // This state is used in the multiplayer game
- // If we need to start a race and the other players didn磘 finish their
- // configuration yet (doesn磘 inform the name and car color) we
- // need to wait.
- if(iStart = 0)
- {
- lLastSprite = 0;
- }
- if(GetTickCount() - lLastSprite > 500)
- {
- bShowCaret = !bShowCaret;
- lLastSprite = GetTickCount();
- }
- if(bShowCaret)
- {
- m_txDigital.WriteText(m_pBackBuffer, "WAITING OTHER PLAYERS", 180, 150);
- m_txDigital.WriteText(m_pBackBuffer, "PLEASE WAIT...", 240, 200);
- }
-
- // Check if all the players are ready
- if(m_pCompetition.AllPlayersReady() && m_pMultiPlayer.IsHosting())
- {
- // If we磖e in the competition mode, we go to the competition status
- // screen. If we磖e in single track mode, start the race
- if(m_pCompetition.GetCompetitionMode() == TRUE)
- {
- m_pCompetition.ResetReadyState();
- m_iState = GS_COMPETITIONSTATUS;
- iStart = 0;
- m_sndSelect.Play();
- lLastOption = GetTickCount();
- m_pMultiPlayer.SendTo(0, MSG_COMPETITIONSTATUS, NULL, 0, DPNSEND_SYNC | DPNSEND_NOLOOPBACK | DPNSEND_GUARANTEED);
- }
- else
- {
- strcpy(buffer, pRaceTrack.GetFileName());
- i = strlen(buffer);
- m_pMultiPlayer.SendTo(0, MSG_START_RACE, (unsigned char *) &buffer[0], i, DPNSEND_SYNC | DPNSEND_NOLOOPBACK | DPNSEND_GUARANTEED);
- m_iState = GS_RACE;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- }
- break;
- case GS_CREDITS:
- // This state show the credits of the game
- // **********************************************************
- // * *
- // * PLEASE !! RESPECT THE COPYRIGHTS AND DON碩 CHANGE IT ! *
- // * *
- // **********************************************************
- #define LINE_STEP 40
- lStart = 480;
- iStart+=1;
-
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "GAME DESIGN", 120, lStart-iStart);
- m_txDigital.WriteText(m_pBackBuffer, "MAURICIO RITTER", 340, lStart-iStart);
- }
-
- lStart+=40;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "3D MODELING", 120, lStart-iStart);
- m_txDigital.WriteText(m_pBackBuffer, "MAURICIO RITTER", 340, lStart-iStart);
- }
- lStart+=40;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "TEXTURES", 120, lStart-iStart);
- m_txDigital.WriteText(m_pBackBuffer, "MAURICIO RITTER", 340, lStart-iStart);
- }
- lStart+=40;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "2D ART", 120, lStart-iStart);
- m_txDigital.WriteText(m_pBackBuffer, "MAURICIO RITTER", 340, lStart-iStart);
- }
- lStart+=40;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "LEVEL DESIGN", 120, lStart-iStart);
- m_txDigital.WriteText(m_pBackBuffer, "MAURICIO RITTER", 340, lStart-iStart);
- }
- lStart+=40;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "PROGRAMMING", 120, lStart-iStart);
- m_txDigital.WriteText(m_pBackBuffer, "MAURICIO RITTER", 340, lStart-iStart);
- }
- lStart+=40;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "SOUND EDITING", 120, lStart-iStart);
- m_txDigital.WriteText(m_pBackBuffer, "MAURICIO RITTER", 340, lStart-iStart);
- }
- lStart+=40;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "MUSIC", 120, lStart-iStart);
- m_txDigital.WriteText(m_pBackBuffer, "MAURICIO RITTER", 340, lStart-iStart);
- }
- lStart+=40;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "SPECIAL THANKS TO ALL MY BETA TESTERS", 50, lStart-iStart);
- }
- lStart+=30;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "IN SPECIAL TO", 120, lStart-iStart);
- m_txDigital.WriteText(m_pBackBuffer, "COLIN DAVIES", 340, lStart-iStart);
- }
- lStart+=20;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "ISAAC SASSON", 340, lStart-iStart);
- }
- lStart+=20;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "JAMES T JOHNSON", 340, lStart-iStart);
- }
- lStart+=20;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "NISHANT SIVAKUMAR", 340, lStart-iStart);
- }
- lStart+=20;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "NNAMDI ONYEYIRI", 340, lStart-iStart);
- }
- lStart+=20;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "SMITHA", 340, lStart-iStart);
- }
- lStart+=40;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "THIS GAME IS TOTALLY FREEWARE", 120, lStart-iStart);
- }
- lStart+=40;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "IF YOU WANT TO CONTACT ME ABOUT THE GAME", 20, lStart-iStart);
- }
- lStart+=40;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "JUST SEND AN EMAIL TO", 160, lStart-iStart);
- }
- lStart+=40;
- if(lStart-iStart > 15 && lStart-iStart < 465)
- {
- m_txDigital.WriteText(m_pBackBuffer, "MAURICIORITTER@HOTMAIL.COM", 130, lStart-iStart);
- }
- //lStart+=480;
- if(iStart > lStart)
- {
- iStart = 0;
- }
- // If the user hit enter os space or escape, go back to the main screen
- m_Keyboard.Process();
- if(GetTickCount() - lLastOption > 200)
- {
- if(m_Keyboard.CheckKey(DIK_RETURN) ||
- m_Keyboard.CheckKey(DIK_NUMPADENTER) ||
- m_Keyboard.CheckKey(DIK_SPACE) ||
- m_Keyboard.CheckKey(DIK_ESCAPE))
- {
- m_iState = GS_MAINSCREEN;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- }
- break;
- case GS_NETWORKSTATUS:
- // This state is used the multiplayer game
- // It shows the current multiplayer game status (number of connected,
- // players, their name and car color)
- if(iStart == 0)
- {
- iStart = 1;
- m_surfTitle.Destroy();
- for(i=0;i<4;i++)
- {
- m_surfBigCars[i].Create(150, 140, RGB(0,0,0));
- m_surfBigCars[i].LoadBitmap(GetInstHandle(), IDB_BIGCAR_BLUE + i);
- }
- m_surfCarPannel.Create(320,110, RGB(0,0,0));
- m_surfCarPannel.LoadBitmap(GetInstHandle(), IDB_CAR_PANNEL);
- m_surfHelmet.Create(640,60, RGB(0,0,0));
- m_surfHelmet.LoadBitmap(GetInstHandle(), IDB_CURRENTCONNECTED_PANEL);
-
- m_surfTitle.Create(520,40, RGB(0,0,0));
- m_surfTitle.LoadBitmap(GetInstHandle(), IDB_MULTIPLAYERSTATUS_TITLE);
- m_surfPositions.Create(120,40, RGB(0,0,0));
- m_surfPositions.LoadBitmap(GetInstHandle(), IDB_POSITIONS);
- }
- // If the number of players is different from the last iteration,
- // a new player connected to the game session. Add this player to the
- // competition or race.
- if(m_pMultiPlayer.GetNumConnected() != m_pCompetition.GetNumberOfCars()-1)
- {
- for(i=0;i<m_pMultiPlayer.GetNumConnected();i++)
- {
- if(m_pCompetition.DPNIDExists(m_pMultiPlayer.GetPlayerInfo(i)->dpnidPlayer) == FALSE)
- {
- m_pCompetition.AddPlayer("UNKNOWN", -1, CTRL_NETWORK_REMOTE, i+1, m_pMultiPlayer.GetPlayerInfo(i)->dpnidPlayer);
- }
- }
- }
- m_surfTitle.Draw(m_pBackBuffer, 60,0);
- m_surfHelmet.Draw(m_pBackBuffer, 0,80);
- // Show each one of the connected players
- for(i=0;i<m_pCompetition.GetNumberOfCars();i++)
- {
- switch(i)
- {
- case 0:
- if(m_pCompetition.GetColor(i) != -1)
- m_surfBigCars[m_pCompetition.GetColor(i) - IDB_CAR_BLUE].Draw(m_pBackBuffer, 10, 140, 20, 14, 130, 106);
- m_surfCarPannel.Draw(m_pBackBuffer, 0, 140);
- m_surfPositions.Draw(m_pBackBuffer, 130, 2 + 140, 0, 0, 30, 40);
- sTmp = m_pCompetition.GetPlayerName(m_pCompetition.GetPlayerID(0));
- m_txDigitalSmall.WriteText(m_pBackBuffer, &sTmp[0], 145, 78 + 140);
- break;
- case 1:
- if(m_pCompetition.GetColor(i) != -1)
- m_surfBigCars[m_pCompetition.GetColor(i) - IDB_CAR_BLUE].Draw(m_pBackBuffer, 330, 140, 20, 14, 130, 106);
- m_surfCarPannel.Draw(m_pBackBuffer, 320, 140);
- m_surfPositions.Draw(m_pBackBuffer, 450, 2 + 140, 30, 0, 30, 40);
- sTmp = m_pCompetition.GetPlayerName(m_pCompetition.GetPlayerID(1));
- m_txDigitalSmall.WriteText(m_pBackBuffer, &sTmp[0], 145 + 310, 78 + 140);
- break;
- case 2:
- if(m_pCompetition.GetColor(i) != -1)
- m_surfBigCars[m_pCompetition.GetColor(i) - IDB_CAR_BLUE].Draw(m_pBackBuffer, 10, 250, 20, 14, 130, 106);
- m_surfCarPannel.Draw(m_pBackBuffer, 0, 250);
- m_surfPositions.Draw(m_pBackBuffer, 130, 2 + 250, 60, 0, 30, 40);
- sTmp = m_pCompetition.GetPlayerName(m_pCompetition.GetPlayerID(0));
- m_txDigitalSmall.WriteText(m_pBackBuffer, &sTmp[0], 145, 78 + 250);
- break;
- case 3:
- if(m_pCompetition.GetColor(i) != -1)
- m_surfBigCars[m_pCompetition.GetColor(i) - IDB_CAR_BLUE].Draw(m_pBackBuffer, 330, 250, 20, 14, 130, 106);
- m_surfCarPannel.Draw(m_pBackBuffer, 320, 250);
- m_surfPositions.Draw(m_pBackBuffer, 450, 2 + 250, 90, 0, 30, 40);
- sTmp = m_pCompetition.GetPlayerName(m_pCompetition.GetPlayerID(1));
- m_txDigitalSmall.WriteText(m_pBackBuffer, &sTmp[0], 145 + 310, 78 + 250);
- break;
- }
- }
-
- // If the user is hosting the session, he need to press enter to start
- // the race with the currently connected players
- // If its a peer, he need to wait the Start command from the host
- if(m_pMultiPlayer.IsHosting())
- {
- m_txVerdana.WriteText(m_pBackBuffer, "PRESS ENTER TO START THE RACE", 140, 420);
- }
- else
- {
- m_txVerdana.WriteText(m_pBackBuffer, "WAITING START MESSAGE FROM GAME CREATOR", 40, 420);
- }
-
- // Process the keyboard for input
- m_Keyboard.Process();
- if(GetTickCount() - lLastOption > 200)
- {
- if(m_pMultiPlayer.IsHosting())
- {
- if(m_Keyboard.CheckKey(DIK_RETURN) ||
- m_Keyboard.CheckKey(DIK_NUMPADENTER) )
- {
-
- for(i=0;i<4;i++)
- {
- m_surfBigCars[i].Destroy();
- }
- m_sptrCar.Destroy();
-
- if(m_pCompetition.GetCompetitionMode() == TRUE)
- {
- if(m_pCompetition.AllPlayersReady())
- {
- // Multiplayer Player - Competition
- // Go to the Competition Status Screen
- m_pCompetition.ResetReadyState();
- m_iState = GS_COMPETITIONSTATUS;
- iStart = 0;
- m_sndSelect.Play();
- lLastOption = GetTickCount();
- m_pMultiPlayer.SendTo(0, MSG_COMPETITIONSTATUS, NULL, 0, DPNSEND_SYNC | DPNSEND_NOLOOPBACK | DPNSEND_GUARANTEED);
- }
- else
- {
- // Players are not ready (some are without name and car color)
- // Go to the wait screen
- m_iState = GS_WAIT;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- }
- else
- {
- if(m_pCompetition.AllPlayersReady())
- {
- // All the players are ready !
- // LET THE RACE BEGIN !
- strcpy(buffer, pRaceTrack.GetFileName());
- i = strlen(buffer);
- // Send a STARTRACE message to all the peers
- m_pMultiPlayer.SendTo(0, MSG_START_RACE, (unsigned char *) &buffer[0], i, DPNSEND_SYNC | DPNSEND_NOLOOPBACK | DPNSEND_GUARANTEED);
- m_iState = GS_RACE;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- else
- {
- // Players are not ready (some are without name and car color)
- // Go to the wait screen
- m_iState = GS_WAIT;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- }
- break;
- }
- }
- }
-
- break;
- case GS_CREATEGAME:
- // This is used in the multiplayer game
- // When a user is creating a new gaming session, show the
- // new game panel so that he can enter the game name
- if(iStart == 0)
- {
- m_iOption = 1;
- m_surfTitle.Create(370,160);
- m_surfTitle.LoadBitmap(GetInstHandle(), IDB_BACKGROUND3);
- 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);
- m_sndSelect.Create(MAKEINTRESOURCE(IDR_SELECT), DSBCAPS_CTRL3D, DS3DALG_NO_VIRTUALIZATION);
- m_sndChangeOption.Create(MAKEINTRESOURCE(IDR_CHANGEOPTION), DSBCAPS_CTRL3D, DS3DALG_NO_VIRTUALIZATION);
- m_sndType.Create(MAKEINTRESOURCE(IDR_TYPE), DSBCAPS_CTRL3D, DS3DALG_NO_VIRTUALIZATION);
- m_sGameName = "";
- iStart = 1;
- }
- iCaretPos = 172;
-
- if(GetTickCount() - lLastCaret > 100)
- {
- bShowCaret = !bShowCaret;
- lLastCaret = GetTickCount();
- }
- m_surfTitle.Draw(m_pBackBuffer, 135, 140);
- if(m_sGameName.length() > 0)
- {
- iCaretPos = m_txDigital.WriteText(m_pBackBuffer, &m_sGameName[0], 170, 220);
- }
- if(bShowCaret)
- {
- m_surfCaret.Draw(m_pBackBuffer, iCaretPos+2, 221);
- }
- m_Keyboard.Process();
- m_Mouse.Process();
- 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 );
- CheckInput(&m_sGameName, 20);
- if(GetTickCount() - lLastOption > 200)
- {
- if(m_Keyboard.CheckKey(DIK_ESCAPE))
- {
- m_iState = GS_MAINSCREEN;
- iStart = 0;
- m_surfHelmet.Destroy();
- pRaceTrack.Destroy();
- m_sptrCar.Destroy();
- lLastOption = GetTickCount();
- }
- if(m_Keyboard.CheckKey(DIK_RETURN) ||
- m_Keyboard.CheckKey(DIK_NUMPADENTER) )
- {
- lLastOption = GetTickCount();
- if(m_sGameName.size() == 0)
- {
- m_sGameName = "NEW GAME";
- }
- else
- {
- m_pMultiPlayer.Host(&m_sGameName[0]);
- m_iState = GS_SELECTTRACK_AND_CAR;
- iStart = 0;
- m_sndSelect.Play();
- }
- }
- }
- break;
- case GS_JOINGAME:
- // The user is trying to join a multiplayer game
- if(iStart == 0)
- {
- m_iOption = 1;
- m_surfTitle.Create(450,300);
- m_surfTitle.LoadBitmap(GetInstHandle(), IDB_BACKGROUND4);
- m_surfCursor.Create(32, 32, RGB(0,0,0));
- m_surfCursor.LoadBitmap(GetInstHandle(), IDB_CURSOR);
- m_sndSelect.Create(MAKEINTRESOURCE(IDR_SELECT), DSBCAPS_CTRL3D, DS3DALG_NO_VIRTUALIZATION);
- m_sndChangeOption.Create(MAKEINTRESOURCE(IDR_CHANGEOPTION), DSBCAPS_CTRL3D, DS3DALG_NO_VIRTUALIZATION);
- m_sndType.Create(MAKEINTRESOURCE(IDR_TYPE), DSBCAPS_CTRL3D, DS3DALG_NO_VIRTUALIZATION);
-
- m_iOption = -1;
-
- iStart = 1;
- lLastSprite = 70;
- lLastCaret = 3;
- }
- else
- {
- if(iStart == 1)
- {
- iStart = 2;
- m_pMultiPlayer.EnumSessions();
- }
- }
- if(iStart == 1)
- {
- // We磖e still searching for sessions...
- // Wait ultil we have finished
- m_txVerdana.WriteText(m_pBackBuffer, "SEARCHING FOR RACEX SESSIONS", 150, 150);
- m_txVerdana.WriteText(m_pBackBuffer, "PLEASE WAIT...", 250, 200);
- m_iOption = 0;
- }
- else
- {
- // Show the avaible games to the user
- m_surfTitle.Draw(m_pBackBuffer, 95, 90);
- if(m_pMultiPlayer.GetNumSessions() == 0)
- {
- // No games wore found in the network
- m_txVerdana.WriteText(m_pBackBuffer, "NO NETWORK GAMES FOUND", 165, 190);
- m_txVerdana.WriteText(m_pBackBuffer, "USE THE SEARCH BUTTON", 175, 230);
- m_txVerdana.WriteText(m_pBackBuffer, "TO TRY AGAIN.", 230, 250);
-
- }
- else
- {
- // Show all the games
- HDC hdc;
- m_pBackBuffer->GetDC(&hdc);
- SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
- HPEN hPen = CreatePen(PS_SOLID,1,RGB(0,(int) lLastSprite,0));
- lLastSprite+=lLastCaret;
- if(lLastSprite > 170 || lLastSprite < 70)
- {
- lLastCaret = lLastCaret * -1;
- lLastSprite+=lLastCaret;
- }
-
- HPEN hOldPen = (HPEN) SelectObject(hdc, hPen);
- Rectangle(hdc, 120, 163 + (m_iOption * 24), 520, 182 + (m_iOption * 24));
- SelectObject(hdc, hOldPen);
- DeleteObject(hPen);
- m_pBackBuffer->ReleaseDC(hdc);
-
- for(i=0;i< (m_pMultiPlayer.GetNumSessions() < 7 ? m_pMultiPlayer.GetNumSessions() : 7);i++)
- {
- m_pMultiPlayer.GetSessionName(i, buffer, 255);
- m_txDigital.WriteText(m_pBackBuffer, buffer, 122, 165 + (i * 24));
- }
- }
- }
- if(iStart > 1)
- 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 );
- // Process the keyboard and mouse for input
- m_Keyboard.Process();
- m_Mouse.Process();
- if(GetTickCount() - lLastOption > 200)
- {
- int iX, iY;
- iX = m_Mouse.GetX();
- iY = m_Mouse.GetY();
-
- // Check if the user hit the Search Button
- if( iX > 233+95 && iY > 251+90 &&
- iX < 357+95 && iY < 277+90 &&
- m_Mouse.GetLeftButton() == FALSE)
- {
- iStart = 0;
- }
- // Check if the user hit the Join Button
- if( iX > 87+95 && iY > 251+90 &&
- iX < 211+95 && iY < 277+90 &&
- m_Mouse.GetLeftButton() == FALSE)
- {
- m_iState = GS_SELECTTRACK_AND_CAR;
- iStart = 0;
- m_sndSelect.Play();
- lLastOption = GetTickCount();
- m_pMultiPlayer.Connect(m_iOption);
- }
- if( iX > 120 && iY > 163 &&
- iX < 520 && iY < 327 &&
- m_Mouse.GetLeftButton() == FALSE)
- {
- if( (iY - 163) / 24 < m_pMultiPlayer.GetNumSessions() )
- m_iOption = (iY - 163) / 24;
- }
- if(m_Keyboard.CheckKey(DIK_RETURN) ||
- m_Keyboard.CheckKey(DIK_NUMPADENTER) )
- {
- m_sndSelect.Play();
- m_surfHelmet.Destroy();
- m_sptrCar.Destroy();
- }
- if(m_Keyboard.CheckKey(DIK_ESCAPE))
- {
- m_iState = GS_MAINSCREEN;
- iStart = 0;
- m_surfHelmet.Destroy();
- pRaceTrack.Destroy();
- m_sptrCar.Destroy();
- lLastOption = GetTickCount();
- }
- }
- break;
- case GS_MAINSCREEN:
- // The iStart is set to 0 when we are starting the program
- // or we are coming from another screen, so that we can
- // initialize the objects necessary to create the screen
- if(iStart == 0)
- {
- m_iOption = 1;
- m_txVerdana.Create(2);
- m_txDigitalSmall.Create(3);
- m_surfTitle.Create(450,260);
- m_surfTitle.LoadBitmap(GetInstHandle(), IDB_TITLE);
- m_surfHelmet.Create(28,26);
- m_surfHelmet.LoadBitmap(GetInstHandle(), IDB_HELMET);
- m_sndSelect.Create(MAKEINTRESOURCE(IDR_SELECT), DSBCAPS_CTRL3D, DS3DALG_NO_VIRTUALIZATION);
- m_sndChangeOption.Create(MAKEINTRESOURCE(IDR_CHANGEOPTION), DSBCAPS_CTRL3D, DS3DALG_NO_VIRTUALIZATION);
- m_pCompetition.Reset();
- iStart = 1;
- }
- // Draw the Title in the middle of the screen
- m_surfTitle.Draw(m_pBackBuffer, 104, 20);
- j = 280;
- // If we are in the menu (option less then 6), draw the top-level menu
- if(m_iOption <= 6)
- {
- m_txVerdana.WriteText(m_pBackBuffer, "SINGLE PLAYER GAME", 200, j);
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "MULTIPLAYER GAME", 200, j);
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "HELP", 200, j);
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "OPTIONS", 200, j);
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "CREDITS", 200, j);
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "QUIT", 200, j);
- }
- // option is greater than 6, states the we are in the submenu
- else if (m_iOption > 10 && m_iOption < 21)
- {
- m_txVerdana.WriteText(m_pBackBuffer, "SINGLE TRACK MODE", 200, j);
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "COMPETITION MODE", 200, j);
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "BACK", 200, j);
- j+= 26;
- }
- else if (m_iOption > 20 && m_iOption < 31)
- {
- m_txVerdana.WriteText(m_pBackBuffer, "CREATE A NEW GAME", 200, j);
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "JOIN A GAME", 200, j);
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "BACK", 200, j);
- }
- else if (m_iOption > 30 && m_iOption < 41)
- {
- m_txVerdana.WriteText(m_pBackBuffer, "SINGLE TRACK MODE", 200, j);
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "COMPETITION MODE", 200, j);
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "BACK", 200, j);
- }
- else if (m_iOption > 40 && m_iOption < 51)
- {
- m_txVerdana.WriteText(m_pBackBuffer, "MUTIPLAYER PROVIDER - ", 100, j);
- m_txVerdana.WriteText(m_pBackBuffer, m_pMultiPlayer.GetSPName(m_pMultiPlayer.GetSPIndex()), 384, j);
- j+= 26;
- i = 0;
- while(i < m_pMultiPlayer.GetNumSPOptions())
- {
- m_txVerdana.WriteText(m_pBackBuffer, m_pMultiPlayer.GetSPOptionName(i), 100, j);
- m_pMultiPlayer.GetSPOption(i, buffer, 255);
- m_txVerdana.WriteText(m_pBackBuffer, buffer, 384, j);
- i++;
- j+= 26;
- }
- //m_txVerdana.WriteText(m_pBackBuffer, "COMPETITION MODE", 200, 310);
- m_txVerdana.WriteText(m_pBackBuffer, "BACK", 100, j);
- }
- else if (m_iOption > 50 && m_iOption < 61)
- {
- m_txVerdana.WriteText(m_pBackBuffer, "MULTIPLAYER OPTIONS", 200, j);
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "DIFFICULTY LEVEL- ", 200, j);
- switch(m_iDifficultyLevel)
- {
- case 0:
- m_txVerdana.WriteText(m_pBackBuffer, "EASY", 420, j);
- break;
- case 20:
- m_txVerdana.WriteText(m_pBackBuffer, "NORMAL", 420, j);
- break;
- case 40:
- m_txVerdana.WriteText(m_pBackBuffer, "PRETTY HARD", 420, j);
- break;
- case 60:
- m_txVerdana.WriteText(m_pBackBuffer, "HARD", 420, j);
- break;
- case 80:
- m_txVerdana.WriteText(m_pBackBuffer, "HELL HARD", 420, j);
- break;
- }
- j+= 26;
- m_txVerdana.WriteText(m_pBackBuffer, "BACK", 200, j);
- }
- // Process the keyboard for input
- m_Keyboard.Process();
- // Draw the helmet icon according to the selected option
- if (m_iOption > 40 && m_iOption < 51)
- m_surfHelmet.Draw(m_pBackBuffer, 63, 277 + ( ( (m_iOption%10) -1) * 26));
- else
- m_surfHelmet.Draw(m_pBackBuffer, 163, 277 + ( ( (m_iOption%10) -1) * 26));
- if(GetTickCount() - lLastOption > 200)
- {
- // If user hit the down key, change the option
- if(m_Keyboard.CheckKey(DIK_DOWN))
- {
- m_iOption++;
- if(m_iOption > 6 && m_iOption < 11) m_iOption = 1;
- if(m_iOption > 13 && m_iOption < 21) m_iOption = 11;
- if(m_iOption > 23 && m_iOption < 31) m_iOption = 21;
- if(m_iOption > 33 && m_iOption < 41) m_iOption = 31;
- if(m_iOption > 42 + m_pMultiPlayer.GetNumSPOptions() && m_iOption < 51) m_iOption = 41;
- if(m_iOption > 53 && m_iOption < 61) m_iOption = 51;
- lLastOption = GetTickCount();
- m_sndChangeOption.Play();
- }
- // If user hit the up key, change the option
- if(m_Keyboard.CheckKey(DIK_UP))
- {
- m_iOption--;
- if(m_iOption < 1) m_iOption = 6;
- if(m_iOption == 10) m_iOption = 13;
- if(m_iOption == 20) m_iOption = 23;
- if(m_iOption == 30) m_iOption = 33;
- 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;
- iStart = 0;
- m_sndSelect.Play();
- lLastOption = GetTickCount();
- }
- else
- {
- // Single Player - Single Track
- // Go to the Track selection Screen
- m_iState = GS_RACE;
- iStart = 0;
- m_sndSelect.Play();
- lLastOption = GetTickCount();
- }
- }
- }
- if(m_Keyboard.CheckKey(DIK_ESCAPE))
- {
- m_iState = GS_MAINSCREEN;
- iStart = 0;
- m_surfHelmet.Destroy();
- pRaceTrack.Destroy();
- m_sptrCar.Destroy();
- lLastOption = GetTickCount();
- }
- }
- break;
- case GS_RACE:
- // Draw the Race Track on the screen
- pRaceTrack.Draw(0,0, -1, -1, 640, 460);
- if(iStart == 0)
- {
- m_surfTitle.Destroy();
- // We haven磘 create the cars yet
- // Create the cars based on the cCompetition class information
- for(i=0;i<m_pCompetition.GetNumberOfCars();i++)
- {
- pCar = new cRaceCar;
- pCar->Create(m_pCompetition.GetColor(i));
- pCar->SetControlType(m_pCompetition.GetControlType(i));
- pCar->SetID(m_pCompetition.GetPlayerID(i));
- pRaceTrack.AddCar(pCar);
- }
- iStart = 1;
- }
- // Process the keyboard input
- m_Keyboard.Process();
- if(m_Keyboard.CheckKey(DIK_ESCAPE))
- {
- m_iState = GS_MAINSCREEN;
- iStart = 0;
- m_surfHelmet.Destroy();
- pRaceTrack.Destroy();
- lLastOption = GetTickCount();
- break;
- }
- // Process the Race Track
- pRaceTrack.Process();
- for(i=0;i<m_pCompetition.GetNumberOfCars();i++)
- {
- if(pRaceTrack.m_pRaceCars[i]->GetControlType() == CTRL_USER || pRaceTrack.m_pRaceCars[i]->GetControlType() == CTRL_NETWORK_LOCAL)
- {
- pCar = pRaceTrack.m_pRaceCars[i];
- DWORD dwFreq = 0;
- }
- }
-
- // Write the race stats on the screen
- sprintf(buffer, "LAPS %02d", pCar->m_iLaps);
- m_txDigital.WriteText(m_pBackBuffer, buffer, 2, 463);
- sprintf(buffer, "SPEED %003dKM", pCar->GetSpeed());
- m_txDigital.WriteText(m_pBackBuffer, buffer, 125, 463);
- sprintf(buffer, "POSITION %d", pCar->GetPosition());
- m_txDigital.WriteText(m_pBackBuffer, buffer, 315, 463);
- lStart = 0;
- m_txDigitalSmall.WriteText(m_pBackBuffer, "ELAPSE TIME -", 472, 461);
- m_txDigitalSmall.WriteText(m_pBackBuffer, "LAST LAP TIME -", 460, 471);
- if(pCar->GetCarState() != CARSTATE_RACECOMPLETED)
- lStart = pCar->GetLapElapseTime();
- sprintf(buffer,"%02d:%02d:%003d", (lStart / 60000), (lStart / 1000) % 60, lStart % 1000);
- m_txDigitalSmall.WriteText(m_pBackBuffer, buffer, 575, 461, true);
- lStart = pCar->GetLastLapTime();
- sprintf(buffer,"%02d:%02d:%003d", (lStart / 60000), (lStart / 1000) % 60, lStart % 1000);
- m_txDigitalSmall.WriteText(m_pBackBuffer, buffer, 575, 471, true);
- if( pCar->GetCarState() == CARSTATE_RACECOMPLETED &&
- pCar->GetLapElapseTime() > 4000)
- {
- if(m_bIsMultiplayer == TRUE)
- {
- int iNumCompleted = 0;
- for(i=0;i<pRaceTrack.GetNumberOfCars();i++)
- {
- if(pRaceTrack.m_pRaceCars[i]->GetCarState() == CARSTATE_RACECOMPLETED)
- iNumCompleted++;
- }
- if(iNumCompleted == pRaceTrack.GetNumberOfCars())
- {
- m_iState = GS_RACECOMPLETED;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- }
- else
- {
- m_iState = GS_RACECOMPLETED;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- }
- break;
- case GS_RACECOMPLETED:
- // When the user completes the race, this screen is showed
- // It shows the position of each player in the race and
- // the elapse time of each lap
- long lBestLapTime, lAvarageLapTime;
- lBestLapTime = 999999999;
- lAvarageLapTime = 0;
- if(iStart == 0)
- {
- iStart = 1;
- for(i=0;i<4;i++)
- {
- m_surfBigCars[i].Create(150, 140, RGB(0,0,0));
- m_surfBigCars[i].LoadBitmap(GetInstHandle(), IDB_BIGCAR_BLUE + i);
- }
- m_sndSelect.Create(MAKEINTRESOURCE(IDR_FINISHEDRACE), DSBCAPS_STATIC , DS3DALG_DEFAULT);
- //m_sndSelect.SetPosition(0.0f,0.0f,0.0f);
- m_sndSelect.Play(0, DSBPLAY_LOOPING);
- for(i=0;i<pRaceTrack.GetNumberOfCars();i++)
- {
- pTmpCar = pRaceTrack.GetCar(i);
- m_pCompetition.AddPointToPlayer(pTmpCar->GetID(), 3-i);
- }
- m_surfCarPannel.Create(320,110, RGB(0,0,0));
- m_surfCarPannel.LoadBitmap(GetInstHandle(), IDB_CAR_PANNEL);
- m_surfHelmet.Create(320,280, RGB(0,0,0));
- m_surfHelmet.LoadBitmap(GetInstHandle(), IDB_LAP_RESULTS_PANNEL);
- m_surfPanel.Create(320,160, RGB(0,0,0));
- m_surfPanel.LoadBitmap(GetInstHandle(), IDB_RACE_STATS);
-
- m_surfTitle.Create(400,40, RGB(0,0,0));
- m_surfTitle.LoadBitmap(GetInstHandle(), IDB_RACERESULTS_TITLE);
- m_surfPositions.Create(120,40, RGB(0,0,0));
- m_surfPositions.LoadBitmap(GetInstHandle(), IDB_POSITIONS);
- }
- m_surfTitle.Draw(m_pBackBuffer, 120, 0);
- for(i=0;i<pRaceTrack.GetNumberOfCars();i++)
- {
- pTmpCar = pRaceTrack.GetCar(i);
-
- //m_txVerdana.WriteText(m_pBackBuffer, "RACE RESULTS", 20, 5);
- m_surfBigCars[pTmpCar->GetCarColor() - IDB_CAR_BLUE].Draw(m_pBackBuffer, 10, 40 + (i * 110), 20, 14, 130, 106);
- m_surfCarPannel.Draw(m_pBackBuffer, 0, 40 + (i * 110));
- m_surfPositions.Draw(m_pBackBuffer, 130, 42 + (i*110), i*30, 0, 30, 40);
-
- //sprintf(buffer,"%d", i+1);
- //m_txVerdana.WriteText(m_pBackBuffer, buffer, 160, 30 + (i * 110));
- sTmp = m_pCompetition.GetPlayerName(pTmpCar->GetID());
- m_txDigitalSmall.WriteText(m_pBackBuffer, &sTmp[0], 145, 118 + (i*110));
- if(pTmpCar->GetControlType() == CTRL_USER || pTmpCar->GetControlType() == CTRL_NETWORK_LOCAL)
- {
- //m_txVerdana.WriteText(m_pBackBuffer, "YOU FINISHED THE RACE", 320, 300);
- //sprintf(buffer, "IN THE %dTH POSITION", pTmpCar->GetPosition());
- //m_txVerdana.WriteText(m_pBackBuffer, buffer, 320, 320);
- int j;
- for(j=0;j<pRaceTrack.GetNumberOfLaps();j++)
- {
- sprintf(buffer,"LAP %d", j+1);
- m_txDigitalSmall.WriteText(m_pBackBuffer, buffer, 340, 90 + (j * 12), false);
-
- lStart = pTmpCar->GetLapElapseTime(j);
- if(lStart < lBestLapTime)
- lBestLapTime = lStart;
- lAvarageLapTime+= lStart;
- sprintf(buffer,"%02d:%02d:%003d", (lStart / 60000), (lStart / 1000) % 60, lStart % 1000);
- m_txDigitalSmall.WriteText(m_pBackBuffer, buffer, 400, 90 + (j * 12), true);
- }
- }
- }
- m_surfHelmet.Draw(m_pBackBuffer, 320, 40);
- m_surfPanel.Draw(m_pBackBuffer, 320, 320);
- lAvarageLapTime /= pRaceTrack.GetNumberOfLaps();
- sprintf(buffer,"%02d:%02d:%003d", (lAvarageLapTime / 60000), (lAvarageLapTime / 1000) % 60, lAvarageLapTime % 1000);
- m_txDigitalSmall.WriteText(m_pBackBuffer, buffer, 544, 350, true);
- sprintf(buffer,"%02d:%02d:%003d", (lBestLapTime / 60000), (lBestLapTime / 1000) % 60, lBestLapTime % 1000);
- m_txDigitalSmall.WriteText(m_pBackBuffer, buffer, 544, 382 , true);
- // Process the keyboard for input
- m_Keyboard.Process();
- if(GetTickCount() - lLastOption > 200)
- {
- if(m_Keyboard.CheckKey(DIK_RETURN) ||
- m_Keyboard.CheckKey(DIK_NUMPADENTER))
- {
-
- if(m_pCompetition.GetCompetitionMode() == TRUE)
- {
- for(i=0;i<4;i++)
- {
- m_surfBigCars[i].Destroy();
- }
- m_sndSelect.Stop(TRUE);
- pRaceTrack.Destroy();
- m_sptrCar.Destroy();
- m_surfTitle.Destroy();
- m_surfCarPannel.Destroy();
- m_surfHelmet.Destroy();
- m_surfPositions.Destroy();
-
- m_pCompetition.NextRace();
- m_pCompetition.ResetReadyState();
- m_iState = GS_COMPETITIONSTATUS;
- iStart = 0;
- //m_sndSelect.Play();
- lLastOption = GetTickCount();
- }
- else
- {
- for(i=0;i<4;i++)
- {
- m_surfBigCars[i].Destroy();
- }
- m_surfTitle.Destroy();
- m_surfCarPannel.Destroy();
- m_surfHelmet.Destroy();
- m_surfPositions.Destroy();
- m_sndSelect.Stop(TRUE);
- //m_sndSelect.Destroy();
- pRaceTrack.Destroy();
- m_sptrCar.Destroy();
- m_iState = GS_MAINSCREEN;
- iStart = 0;
- //m_sndSelect.Play();
- lLastOption = GetTickCount();
- }
- break;
- }
- }
- break;
- case GS_COMPETITIONSTATUS:
- // Shows the competition status
- // It shows the position of each player in the competition and
- // the next race information
- // If the competition is finished, show the tophy for the player
-
- BOOL bFinished;
- int iPosition;
- iPosition = 4;
- for(i=0;i<4;i++)
- {
- if(m_pCompetition.GetControlType(i) == CTRL_USER || m_pCompetition.GetControlType(i) == CTRL_NETWORK_LOCAL)
- {
- iPosition = i+1;
- break;
- }
- }
- if(m_pCompetition.GetNextRace() == "")
- bFinished = TRUE;
- else
- bFinished = FALSE;
- if(iStart == 0)
- {
- iStart = 1;
- m_surfTitle.Destroy();
- for(i=0;i<4;i++)
- {
- m_surfBigCars[i].Create(750, 560, RGB(0,0,0));
- m_surfBigCars[i].LoadBitmap(GetInstHandle(), IDB_BIGCAR_BLUE + i);
- }
- m_surfCarPannel.Create(320,110, RGB(0,0,0));
- m_surfCarPannel.LoadBitmap(GetInstHandle(), IDB_CAR_PANNEL_COMPETITION);
- m_surfTitle.Create(600,40, RGB(0,0,0));
- m_surfTitle.LoadBitmap(GetInstHandle(), IDB_COMPETITIONSTATUS_TITLE);
- m_surfPositions.Create(120,40, RGB(0,0,0));
- m_surfPositions.LoadBitmap(GetInstHandle(), IDB_POSITIONS);
- m_surfHelmet.Create(320,440, RGB(0,0,0));
- if(bFinished)
- {
- m_surfHelmet.LoadBitmap(GetInstHandle(), IDB_FINISHCOMPETITION_PANEL);
- m_surfTophy.Create(280,300);
- switch(iPosition)
- {
- case 1:
- m_surfTophy.LoadBitmap(GetInstHandle(), IDB_TOPHY_GOLD);
- break;
- case 2:
- m_surfTophy.LoadBitmap(GetInstHandle(), IDB_TOPHY_SILVER);
- break;
- case 3:
- m_surfTophy.LoadBitmap(GetInstHandle(), IDB_TOPHY_COOPER);
- break;
- case 4:
- m_surfTophy.LoadBitmap(GetInstHandle(), IDB_TOPHY_NONE);
- break;
- }
- }
- else
- m_surfHelmet.LoadBitmap(GetInstHandle(), IDB_NEXTRACEINFO_PANEL);
- pRaceTrack.Destroy();
- if(!bFinished)
- pRaceTrack.ReadFromFile(&m_pCompetition.GetNextRace()[0]);
- }
- if(bFinished)
- {
- m_surfTophy.Draw(m_pBackBuffer, 340, 60);
- }
- m_surfTitle.Draw(m_pBackBuffer, 20, 0);
- m_surfHelmet.Draw(m_pBackBuffer, 320, 40);
- for(i=0;i<m_pCompetition.GetNumberOfCars();i++)
- {
- m_surfBigCars[m_pCompetition.GetColor(i) - IDB_CAR_BLUE].Draw(m_pBackBuffer, 10, 40 + (i * 110), 20, 14, 130, 106);
- m_surfCarPannel.Draw(m_pBackBuffer, 0, 40 + (i * 110));
- m_surfPositions.Draw(m_pBackBuffer, 130, 42 + (i*110), i*30, 0, 30, 40);
- sTmp = m_pCompetition.GetPlayerName(m_pCompetition.GetPlayerID(i));
- m_txDigitalSmall.WriteText(m_pBackBuffer, &sTmp[0], 145, 110 + (i*110));
- sprintf(buffer,"%d", m_pCompetition.GetPlayerPointsByPosition(i));
- m_txDigitalSmall.WriteText(m_pBackBuffer, buffer, 285, 130 + (i*110));
- }
-
- if(bFinished)
- {
- sprintf(buffer, "YOU FINISHED THE COMPETITION", iPosition);
- m_txDigitalSmall.WriteText(m_pBackBuffer, buffer, 375, 380);
- sprintf(buffer, "IN THE %dTH POSITION.", iPosition);
- m_txDigitalSmall.WriteText(m_pBackBuffer, buffer, 405, 395);
- switch(iPosition)
- {
- case 1:
- sprintf(buffer, "CONGRATS, YOU GOT THE GOLDEN TOPHY");
- break;
- case 2:
- sprintf(buffer, "CONGRATS, YOU GOT THE SILVER TOPHY");
- break;
- case 3:
- sprintf(buffer, "CONGRATS, YOU GOT THE COOPER TOPHY");
- break;
- case 4:
- sprintf(buffer, "SORRY, NO TOPHY FOR SLOW DRIVERS.");
- break;
- }
- m_txDigitalSmall.WriteText(m_pBackBuffer, buffer, 354, 410);
- }
- else
- {
- sprintf(buffer, "%.2d", pRaceTrack.GetNumberOfLaps());
- m_txDigital.WriteText(m_pBackBuffer, pRaceTrack.GetTrackName(), 350, 144);
- m_txDigital.WriteText(m_pBackBuffer, buffer, 582, 194);
- }
- // Process the keyboard for input
- m_Keyboard.Process();
- if(GetTickCount() - lLastOption > 200)
- {
- if(m_Keyboard.CheckKey(DIK_RETURN) ||
- m_Keyboard.CheckKey(DIK_NUMPADENTER))
- {
-
- for(i=0;i<4;i++)
- {
- m_surfBigCars[i].Destroy();
- }
- m_surfTitle.Destroy();
- m_surfCarPannel.Destroy();
- m_surfHelmet.Destroy();
- m_surfPositions.Destroy();
- m_surfTophy.Destroy();
- m_sptrCar.Destroy();
- if(bFinished)
- {
- m_iState = GS_MAINSCREEN;
- }
- else
- {
- if(m_bIsMultiplayer == TRUE)
- {
- if(m_pMultiPlayer.IsHosting())
- {
- m_pCompetition.SetReadyState(0,TRUE);
- if(m_pCompetition.AllPlayersReady())
- {
- m_iState = GS_RACE;
- strcpy(buffer, pRaceTrack.GetFileName());
- i = strlen(buffer);
- m_pMultiPlayer.SendTo(0, MSG_START_RACE, (unsigned char *) &buffer[0], i, DPNSEND_SYNC | DPNSEND_NOLOOPBACK | DPNSEND_GUARANTEED);
- m_iState = GS_RACE;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- else
- {
- m_iState = GS_WAITCOMPETITION;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- }
- else
- {
- m_pMultiPlayer.SendTo(0, MSG_PLAYER_READY, NULL, 0, DPNSEND_SYNC | DPNSEND_NOLOOPBACK | DPNSEND_GUARANTEED);
- if(m_iState != GS_RACE)
- m_iState = GS_WAITCOMPETITION;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- }
- else
- {
- m_iState = GS_RACE;
- iStart = 0;
- lLastOption = GetTickCount();
- }
- }
- iStart = 0;
- lLastOption = GetTickCount();
- break;
- }
- }
- break;
- }
- }
- void cRaceXApp::IncomingMessage(DWORD dwType, int idSender, BYTE* pBuffer, DWORD dwBufferSize)
- {
- LPBYTE pTmpBuffer;
- DWORD dwTmp;
- BYTE bTmp;
- string sTmp;
- char buffer[1024];
- int iOffset, i;
- // This is a virtual function of the cMessageHandler class
- // and is used on multiplayer games
- // Here we receive all the messages from the network, and process them
- // based on theier type.
- switch(dwType)
- {
- case MSG_PLAYER_READY:
- if(m_pMultiPlayer.IsHosting())
- {
- m_pCompetition.SetReadyState(m_pCompetition.GetPlayerIDbyDPNID(idSender), TRUE);
- }
- break;
- case MSG_PLAYER_INFO:
- memcpy(&dwTmp, pBuffer, sizeof(DWORD));
- memcpy(buffer, (pBuffer+sizeof(DWORD)), dwBufferSize-sizeof(DWORD));
- buffer[dwBufferSize-sizeof(DWORD)] = ' ';
- m_pCompetition.SetPlayerColor(m_pCompetition.GetPlayerIDbyDPNID(idSender), dwTmp);
- m_pCompetition.SetPlayerName(m_pCompetition.GetPlayerIDbyDPNID(idSender), buffer);
- m_pCompetition.SetReadyState(m_pCompetition.GetPlayerIDbyDPNID(idSender), TRUE);
- iOffset = 0;
- dwTmp = m_pCompetition.GetNumberOfCars();
- memcpy(&buffer[iOffset], &dwTmp , sizeof(DWORD));
- iOffset += sizeof(int);
- for(i=0;i<m_pCompetition.GetNumberOfCars();i++)
- {
- bTmp = m_pCompetition.GetPlayerID(i);
- memcpy(&buffer[iOffset], &bTmp , sizeof(BYTE));
- iOffset += sizeof(BYTE);
- dwTmp = m_pCompetition.GetPlayerDPNID(m_pCompetition.GetPlayerID(i));
- memcpy(&buffer[iOffset], &dwTmp , sizeof(DWORD));
- iOffset += sizeof(DWORD);
- dwTmp = m_pCompetition.GetPlayerColor(m_pCompetition.GetPlayerID(i));
- memcpy(&buffer[iOffset], &dwTmp , sizeof(DWORD));
- iOffset += sizeof(DWORD);
- sTmp = m_pCompetition.GetPlayerName(m_pCompetition.GetPlayerID(i));
- dwTmp = sTmp.size();
- memcpy(&buffer[iOffset], &dwTmp , sizeof(DWORD));
- iOffset += sizeof(DWORD);
- memcpy(&buffer[iOffset], &sTmp[0] , dwTmp);
- iOffset += dwTmp;
- }
- m_pMultiPlayer.SendTo(DPNID_ALL_PLAYERS_GROUP, MSG_RACECARS_INFO, (unsigned char *) &buffer[0], iOffset+1, DPNSEND_SYNC | DPNSEND_NOLOOPBACK | DPNSEND_GUARANTEED);
- break;
- case MSG_RACECARS_INFO:
- if(!m_pMultiPlayer.IsHosting())
- {
- DWORD dwNumCars;
- BYTE bPlayerId;
- int iPlayerDPNID;
- int iCarColor;
- m_pCompetition.Reset();
- pTmpBuffer = pBuffer;
- memcpy(&dwNumCars, pTmpBuffer, sizeof(DWORD));
- pTmpBuffer+=sizeof(DWORD);
-
- for(i=0;i<dwNumCars;i++)
- {
- memcpy(&bPlayerId, pTmpBuffer, sizeof(BYTE));
- pTmpBuffer+=sizeof(BYTE);
-
- memcpy(&iPlayerDPNID, pTmpBuffer, sizeof(DWORD));
- pTmpBuffer+=sizeof(DWORD);
- memcpy(&iCarColor, pTmpBuffer, sizeof(DWORD));
- pTmpBuffer+=sizeof(DWORD);
-
- memcpy(&dwTmp, pTmpBuffer, sizeof(DWORD));
- pTmpBuffer+=sizeof(DWORD);
- memcpy(&buffer[0], pTmpBuffer ,dwTmp);
- buffer[dwTmp] = ' ';
- pTmpBuffer+=dwTmp;
- sTmp = buffer;
- #ifdef _DEBUG
- Log("CAR: PID: %d, DPNID: %d, NAME: %s, MYID: %dn",bPlayerId, iPlayerDPNID, &buffer[0], m_pMultiPlayer.GetMyId());
- #endif
- m_pCompetition.AddPlayer(sTmp, iCarColor,m_pMultiPlayer.GetMyId()==iPlayerDPNID ? CTRL_NETWORK_LOCAL : CTRL_NETWORK_REMOTE, bPlayerId, iPlayerDPNID);
- }
- }
- break;
- case MSG_START_RACE:
- if(!m_pMultiPlayer.IsHosting())
- {
- if(m_iState == GS_NETWORKSTATUS)
- {
- for(i=0;i<4;i++)
- {
- m_surfBigCars[i].Destroy();
- }
- m_sptrCar.Destroy();
- }
- memcpy(&buffer[0], pBuffer, dwBufferSize);
- buffer[dwBufferSize] = ' ';
- pRaceTrack.ReadFromFile(buffer);
- m_bSendKeyboard = TRUE;
- m_iState = GS_RACE;
- iStart = 0;
- }
- break;
- case MSG_KEYBOARD_STATUS:
- if(m_pMultiPlayer.IsHosting())
- {
- BYTE bStatus;
- BYTE bInformation = 0;
- BYTE buffer[200];
- int iOffset = 0;
- BYTE bID, bSpeed, bPosition, bLaps, bMask, bAngle, bState;
- DWORD dwElapseTime, dwLastLapTime;
- unsigned short iCarX, iCarY;
- int iX, iY;
- memcpy(&bStatus, pBuffer, sizeof(BYTE));
- pRaceTrack.SetRemoteKeyboardStatus(m_pCompetition.GetPlayerIDbyDPNID(idSender), bStatus);
- for(i=0;i<(int)pRaceTrack.GetNumberOfCars();i++)
- {
- iOffset = 0;
- bID = pRaceTrack.m_pRaceCars[i]->GetID();
-
- memcpy(&buffer[iOffset], &bID, sizeof(BYTE));
- iOffset+=sizeof(BYTE);
-
- if(idSender == m_pCompetition.GetPlayerDPNID(bID))
- {
- bMask = 0;
- dwElapseTime = pRaceTrack.m_pRaceCars[i]->GetLapElapseTime();
- memcpy(&buffer[iOffset], &dwElapseTime, sizeof(DWORD));
- iOffset+=sizeof(DWORD);
- int iMaskOffset = iOffset;
- iOffset++;
- if(pRaceTrack.m_pRaceCars[i]->m_iLaps != pRaceTrack.m_pRaceCars[i]->m_bLastSent_Laps)
- {
- bMask |= 0x01;
- bLaps = pRaceTrack.m_pRaceCars[i]->m_iLaps;
- memcpy(&buffer[iOffset], &bLaps, sizeof(BYTE));
- iOffset+=sizeof(BYTE);
- pRaceTrack.m_pRaceCars[i]->m_bLastSent_Laps = pRaceTrack.m_pRaceCars[i]->m_iLaps;
- }
- if((pRaceTrack.m_pRaceCars[i]->GetSpeed()/10) != pRaceTrack.m_pRaceCars[i]->m_bLastSent_Speed)
- {
- bMask |= 0x02;
- bSpeed = (pRaceTrack.m_pRaceCars[i]->GetSpeed() / 10);
- memcpy(&buffer[iOffset], &bSpeed, sizeof(BYTE));
- iOffset+=sizeof(BYTE);
- pRaceTrack.m_pRaceCars[i]->m_bLastSent_Speed = (pRaceTrack.m_pRaceCars[i]->GetSpeed()/10);
- }
- if(pRaceTrack.m_pRaceCars[i]->GetPosition() != pRaceTrack.m_pRaceCars[i]->m_bLastSent_Position)
- {
- bMask |= 0x04;
- bPosition = pRaceTrack.m_pRaceCars[i]->GetPosition();
- memcpy(&buffer[iOffset], &bPosition, sizeof(BYTE));
- iOffset+=sizeof(BYTE);
- pRaceTrack.m_pRaceCars[i]->m_bLastSent_Position = pRaceTrack.m_pRaceCars[i]->GetPosition();
- }
- if(pRaceTrack.m_pRaceCars[i]->GetLastLapTime() != pRaceTrack.m_pRaceCars[i]->m_dwLastSent_LastLapTime)
- {
- bMask |= 0x08;
- dwLastLapTime = pRaceTrack.m_pRaceCars[i]->GetLastLapTime();
- memcpy(&buffer[iOffset], &dwLastLapTime, sizeof(DWORD));
- iOffset+=sizeof(DWORD);
- pRaceTrack.m_pRaceCars[i]->m_dwLastSent_LastLapTime = pRaceTrack.m_pRaceCars[i]->GetLastLapTime();
- }
- pRaceTrack.m_pRaceCars[i]->GetPos(&iX, &iY);
- iCarX = (unsigned short) iX;
- iCarY = (unsigned short) iY;
- if(iCarX != pRaceTrack.m_pRaceCars[i]->m_nLastSent_PosX)
- {
- bMask |= 0x10;
- memcpy(&buffer[iOffset], &iCarX, sizeof(unsigned short));
- iOffset+=sizeof(unsigned short);
- pRaceTrack.m_pRaceCars[i]->m_nLastSent_PosX = iCarX;
- }
- if(iCarY != pRaceTrack.m_pRaceCars[i]->m_nLastSent_PosY)
- {
- bMask |= 0x20;
- memcpy(&buffer[iOffset], &iCarY, sizeof(unsigned short));
- iOffset+=sizeof(unsigned short);
- pRaceTrack.m_pRaceCars[i]->m_nLastSent_PosY = iCarY;
- }
- if(pRaceTrack.m_pRaceCars[i]->m_iAngle != pRaceTrack.m_pRaceCars[i]->m_bLastSent_Angle)
- {
- bMask |= 0x40;
- bAngle = (BYTE) (pRaceTrack.m_pRaceCars[i]->m_iAngle / 10);
- memcpy(&buffer[iOffset], &bAngle, sizeof(BYTE));
- iOffset+=sizeof(BYTE);
- pRaceTrack.m_pRaceCars[i]->m_bLastSent_Angle = (BYTE) pRaceTrack.m_pRaceCars[i]->m_iAngle;
- }
- if(pRaceTrack.m_pRaceCars[i]->GetCarState() != pRaceTrack.m_pRaceCars[i]->m_bLastSent_CarState)
- {
- bMask |= 0x80;
- bState = (BYTE) pRaceTrack.m_pRaceCars[i]->GetCarState();
- memcpy(&buffer[iOffset], &bState, sizeof(BYTE));
- iOffset+=sizeof(BYTE);
- pRaceTrack.m_pRaceCars[i]->m_bLastSent_CarState = pRaceTrack.m_pRaceCars[i]->GetCarState();
- }
- memcpy(&buffer[iMaskOffset], &bMask, sizeof(BYTE));
- m_pMultiPlayer.SendTo(idSender, MSG_RACECARS_STATUS, (unsigned char *) &buffer[0], iOffset, 0 /*DPNSEND_SYNC*/);
- }
- else
- {
- pRaceTrack.m_pRaceCars[i]->GetPos(&iX, &iY);
- iCarX = (unsigned short) iX;
- iCarY = (unsigned short) iY;
- memcpy(&buffer[iOffset], &iCarX, sizeof(unsigned short));
- iOffset+=sizeof(unsigned short);
- memcpy(&buffer[iOffset], &iCarY, sizeof(unsigned short));
- iOffset+=sizeof(unsigned short);
- bState = (BYTE) pRaceTrack.m_pRaceCars[i]->GetCarState();
- memcpy(&buffer[iOffset], &bState, sizeof(BYTE));
- iOffset+=sizeof(BYTE);
- if(bState == CARSTATE_RACECOMPLETED)
- {
- bPosition = (BYTE) (pRaceTrack.m_pRaceCars[i]->GetPosition());
- memcpy(&buffer[iOffset], &bPosition, sizeof(BYTE));
- iOffset+=sizeof(BYTE);
- }
- else
- {
- bAngle = (BYTE) (pRaceTrack.m_pRaceCars[i]->m_iAngle / 10);
- memcpy(&buffer[iOffset], &bAngle, sizeof(BYTE));
- iOffset+=sizeof(BYTE);
- }
- m_pMultiPlayer.SendTo(idSender, MSG_RACECARS_STATUS, (unsigned char *) &buffer[0], iOffset, 0 /*DPNSEND_SYNC*/);
- } /* IF SENDER*/
- } /* FOR */
- } /* IF IS HOSTING */
- break;
- case MSG_COMPETITIONSTATUS:
- m_pCompetition.SetCompetitionMode(TRUE);
- m_iState = GS_COMPETITIONSTATUS;
- iStart = 0;
- m_sndSelect.Play();
- break;
- case MSG_RACECARS_STATUS:
- if(!m_pMultiPlayer.IsHosting())
- {
- BYTE bCarId;
- unsigned short iCarX = -1, iCarY = -1;
- BYTE bCarPosition = -1;
- BYTE bCarState = -1;
- BYTE bAngle = -1;
- BYTE bSpeed = -1;
- BYTE bPosition = -1;
- BYTE bLaps = -1;
- BYTE bMask = -1;
- DWORD dwLastLapTime = -1;
- DWORD dwElapseTime = -1;
- pTmpBuffer = pBuffer;
- memcpy(&bCarId, pTmpBuffer, sizeof(BYTE));
- pTmpBuffer+=sizeof(BYTE);
-
- if(bCarId == pRaceTrack.GetLocalCarID())
- {
- memcpy(&dwElapseTime, pTmpBuffer, sizeof(DWORD));
- pTmpBuffer+=sizeof(DWORD);
-
- memcpy(&bMask, pTmpBuffer, sizeof(BYTE));
- pTmpBuffer+=sizeof(BYTE);
- if(bMask & 0x01)
- {
- memcpy(&bLaps, pTmpBuffer, sizeof(BYTE));
- pTmpBuffer+=sizeof(BYTE);
- }
- if(bMask & 0x02)
- {
- memcpy(&bSpeed, pTmpBuffer, sizeof(BYTE));
- pTmpBuffer+=sizeof(BYTE);
- }
- if(bMask & 0x04)
- {
- memcpy(&bPosition, pTmpBuffer, sizeof(BYTE));
- pTmpBuffer+=sizeof(BYTE);
- }
- if(bMask & 0x08)
- {
- memcpy(&dwLastLapTime, pTmpBuffer, sizeof(DWORD));
- pTmpBuffer+=sizeof(DWORD);
- }
- if(bMask & 0x10)
- {
- memcpy(&iCarX, pTmpBuffer, sizeof(unsigned short));
- pTmpBuffer+=sizeof(unsigned short);
- }
- if(bMask & 0x20)
- {
- memcpy(&iCarY, pTmpBuffer, sizeof(unsigned short));
- pTmpBuffer+=sizeof(unsigned short);
- }
- if(bMask & 0x40)
- {
- memcpy(&bAngle, pTmpBuffer, sizeof(BYTE));
- pTmpBuffer+=sizeof(BYTE);
- }
- if(bMask & 0x80)
- {
- memcpy(&bCarState, pTmpBuffer, sizeof(BYTE));
- pTmpBuffer+=sizeof(BYTE);
- }
- m_bSendKeyboard = TRUE;
- }
- else
- {
- bMask = 0;
- bMask |= 0x10;
- bMask |= 0x20;
- bMask |= 0x80;
- memcpy(&iCarX, pTmpBuffer, sizeof(unsigned short));
- pTmpBuffer+=sizeof(unsigned short);
- memcpy(&iCarY, pTmpBuffer, sizeof(unsigned short));
- pTmpBuffer+=sizeof(unsigned short);
- memcpy(&bCarState, pTmpBuffer, sizeof(BYTE));
- pTmpBuffer+=sizeof(BYTE);
- if(bCarState == CARSTATE_RACECOMPLETED)
- {
- bMask |= 0x04;
- memcpy(&bPosition, pTmpBuffer, sizeof(BYTE));
- pTmpBuffer+=sizeof(BYTE);
- }
- else
- {
- bMask |= 0x40;
- memcpy(&bAngle, pTmpBuffer, sizeof(BYTE));
- pTmpBuffer+=sizeof(BYTE);
- }
- }
- pRaceTrack.SetCarInfo(bCarId, bMask, dwElapseTime,
- bLaps,
- bSpeed,
- bPosition,
- dwLastLapTime,
- iCarX,
- iCarY,
- bAngle,
- bCarState);
- }
- break;
- }
- return;
- }
- void cRaceXApp::AppInitialized()
- {
- // Hide the mouse cursor
- ShowCursor(FALSE);
- m_pSoundInterface.Initialize(GetMainWnd(), DSSCL_PRIORITY );
- if(m_Keyboard.Create() == FALSE)
- {
- DXTRACE_MSG("Failed To Initialize Keyboard Input");
- PostQuitMessage(0);
- }
- if(m_Mouse.Create() == FALSE)
- {
- DXTRACE_MSG("Failed To Initialize Keyboard Input");
- PostQuitMessage(0);
- }
- if(m_pMultiPlayer.Initialize() == FALSE)
- {
- DXTRACE_MSG("Failed To Initialize Multiplayer Support.");
- PostQuitMessage(0);
- }
- else
- {
- m_pMultiPlayer.SetHandler(this);
- m_pMultiPlayer.EnumServiceProviders();
- }
- m_iDifficultyLevel = m_pMultiPlayer.GetRegDWValue("DifficultyLevel");
- if(m_iDifficultyLevel == NULL)
- {
- m_iDifficultyLevel = 20;
- m_pMultiPlayer.SetRegDWValue("DifficultyLevel", (DWORD) m_iDifficultyLevel);
- }
- m_txDigital.Create();
- }
- void cRaceXApp::ExitApp()
- {
- m_surfCursor.Destroy();
- m_surfHelmet.Destroy();
- m_surfTitle.Destroy();
- m_surfCaret.Destroy();
- m_surfCarPannel.Destroy();
- m_surfTophy.Destroy();
-
- m_surfBigCars[0].Destroy();
- m_surfBigCars[1].Destroy();
- m_surfBigCars[2].Destroy();
- m_surfBigCars[3].Destroy();
- m_surfPanel.Destroy();
- m_surfPositions.Destroy();
- m_sptrCar.Destroy();
- pRaceTrack.Destroy(TRUE);
- m_Mouse.Destroy();
- m_Keyboard.Destroy();
- m_hcHit.Destroy();
- m_txDigital.Destroy();
- m_txDigitalSmall.Destroy();
- m_txVerdana.Destroy();
- STRVECTOR::iterator theIterator;
- for (theIterator = pTrackNames.begin(); theIterator != pTrackNames.end();
- theIterator++)
- {
- free((void*)*theIterator);
- }
- m_sndType.Destroy();
- m_sndChangeOption.Destroy();
- m_sndSelect.Destroy();
- m_pSoundInterface.Destroy();
- m_pMultiPlayer.Destroy();
- }
- BOOL cRaceXApp::CheckInput(string* sValue, int iMax)
- {
- // This is used to get text input from the screen
- static long lLastInput = 0;
- static long lLastKey = DIK_RETURN;
- if(GetTickCount() - lLastInput > 200 ||
- !m_Keyboard.CheckKey(lLastKey))
- {
- if(m_Keyboard.CheckKey(DIK_A))
- {
- *sValue += "A";
- lLastKey = DIK_A;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_B))
- {
- *sValue += "B";
- lLastKey = DIK_B;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_C))
- {
- *sValue += "C";
- lLastKey = DIK_C;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_D))
- {
- *sValue += "D";
- lLastKey = DIK_D;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_E))
- {
- *sValue += "E";
- lLastKey = DIK_E;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_F))
- {
- *sValue += "F";
- lLastKey = DIK_F;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_G))
- {
- *sValue += "G";
- lLastKey = DIK_G;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_H))
- {
- *sValue += "H";
- lLastKey = DIK_H;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_I))
- {
- *sValue += "I";
- lLastKey = DIK_I;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_J))
- {
- *sValue += "J";
- lLastKey = DIK_J;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_K))
- {
- *sValue += "K";
- lLastKey = DIK_K;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_L))
- {
- *sValue += "L";
- lLastKey = DIK_L;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_M))
- {
- *sValue += "M";
- lLastKey = DIK_M;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_N))
- {
- *sValue += "N";
- lLastKey = DIK_N;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_O))
- {
- *sValue += "O";
- lLastKey = DIK_O;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_P))
- {
- *sValue += "P";
- lLastKey = DIK_P;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_Q))
- {
- *sValue += "Q";
- lLastKey = DIK_Q;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_R))
- {
- *sValue += "R";
- lLastKey = DIK_R;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_S))
- {
- *sValue += "S";
- lLastKey = DIK_S;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_T))
- {
- *sValue += "T";
- lLastKey = DIK_T;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_U))
- {
- *sValue += "U";
- lLastKey = DIK_U;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_V))
- {
- *sValue += "V";
- lLastKey = DIK_V;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_X))
- {
- *sValue += "X";
- lLastKey = DIK_X;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_Y))
- {
- *sValue += "Y";
- lLastKey = DIK_Y;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_W))
- {
- *sValue += "W";
- lLastKey = DIK_W;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_Z))
- {
- *sValue += "Z";
- lLastKey = DIK_Z;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_SPACE))
- {
- *sValue += " ";
- lLastKey = DIK_SPACE;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- if(m_Keyboard.CheckKey(DIK_BACK))
- {
- if(sValue->length() > 0)
- {
- sValue->resize(sValue->size()-1);
- lLastKey = DIK_BACK;
- lLastInput = GetTickCount();
- m_sndType.Play();
- return TRUE;
- }
- }
- }
- return FALSE;
- }
- cMultiplayer* cRaceXApp::GetMultiplayer()
- {
- return &m_pMultiPlayer;
- }
- int cRaceXApp::GetDifficultyLevel()
- {
- return m_iDifficultyLevel;
- }