int main() { // Initialize our data Init(); // Below we do our basic game loop. This is what control the game primarily. // We only want the game to keep going as long as the character is alive. Of // course, in this tutorial the character can't die, but we set this up for later. // In the game loop we always check for input every frame, then we draw the map. // We don't draw the map every frame, but inside the Draw() function there is // a check to see if the draw flag is set. That is why we use the SetDrawFlag() // function to tell the map to draw. If we don't set that each frame, the map // will not draw, even though we call the Draw() flag. // Keep the game going while the player is alive while(g_Player.IsAlive()) { // If the user did some input, let's check it and handle it if(g_Input.CheckInput()) HandleGameInput(); // Let's draw the map when we need to draw (if the draw flag = true). g_Map.Draw(); } // Return a success with no problems return 1; }
BOOL Socket::HandleCommand() { switch (GetConnectionType()) { //handles all in-game connections that aren't handled with a function case ConnectionType::Disconnected: case ConnectionType::Game: return HandleGameInput(); case ConnectionType::Name: return HandleNameInput(); //login password prompt case ConnectionType::Password: return HandlePasswordInput(); //login new username case ConnectionType::Newname: return HandleNewnameInput(); //login new password case ConnectionType::Newpass: return HandleNewpassInput(); //login verify password case ConnectionType::Verpass: return HandleVerpassInput(); case ConnectionType::Gender: return HandleGenderInput(); } return true; }
void IrcBot::ReadHandler(const boost::system::error_code &error, std::size_t bytesRead) { if (shuttingDown) { return; } if (!error) { messageString = readBuffer.data(); std::cout << std::string(readBuffer.data(), bytesRead); HandlePing(messageString); // handle welcome message 001 if (messageString.find(serverWelcomeMessage) == 0)//if (messageString.find(":" + serverName + " 001") == 0) { Send(join); } HandleRequest(messageString); if (activeGame != NONE) { HandleGameInput(messageString); } readBuffer.fill('\0'); sock.async_read_some(buffer(readBuffer), [this](boost::system::error_code ec, std::size_t bytesRead) { ReadHandler(ec, bytesRead); }); } else { ConsoleMessage(error.message()); } }
WPARAM MainLoop() { MSG msg; // This is where we load our accelerators for keyboard shortcuts HACCEL hAccelTable = LoadAccelerators(g_hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1)); while(g_Player.IsAlive()) // Loop until the player is dead { // Check if there was a message if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) // If the message was to quit break; // Check if there was keyboard command - if not, process messages like normal if(!TranslateAccelerator(g_hWnd, hAccelTable, &msg)) { TranslateMessage(&msg); // Find out what the message does DispatchMessage(&msg); // Execute the message } // Here is where we handle the main game input HandleGameInput(); // Let's draw the map when we need to draw (if the draw flag == true). g_Map.Draw(); // Just like the g_Map.Draw() command, we will attempt to draw the menu, but it // will only be draw if it's draw flag is set to true. This is the main menu. g_Menu.Draw(); // Swap the backbuffers to display the bitmaps to the screen g_Buffer.SwapBackBuffer(FALSE); } // We want the Npcs to freely walk around so we need to move them every frame g_Map.MoveNpcs(); // Move the monsters randomly around the map g_Map.MoveMonsters(); } // If the player died because they were killed, let's display a death sound if(!g_Player.IsAlive()) { // We use PlaySound() to play our .wav files PlaySound("Death.wav", NULL, SND_FILENAME | SND_ASYNC); g_Menu.DrawMessageBox("You have perished!"); Sleep(1000); } // Clean up and free all allocated memory DeInit(); // Return from the program return(msg.wParam); }
int HandleInput(const SDL_Event& inputEvent, const int frameTicks) { int Result; Result = HandleGameInput(inputEvent, frameTicks); if(Result != 0) return Result; if(playingMode == constants::Playing) { Result = HandlePlayerInput(inputEvent, frameTicks); } return Result; }
void Game() { if((SDL_GetTicks() - g_Timer) >= FRAME_RATE) { printf("Game"); HandleGameInput(); force_down_counter++; /* (force_down_counter >= g_FocusBlockSpeed) { // Always check for collisions before moving anything if ( !CheckWallCollisions(g_FocusBlock, DOWN) && !CheckEntityCollisions(g_FocusBlock, DOWN) ) { g_FocusBlock->Move(DOWN); // move the focus block force_down_counter = 0; // reset our counter } } // Check to see if focus block's bottom has hit something. // If it has, we decrement our counter. if ( CheckWallCollisions(g_FocusBlock, DOWN) || CheckEntityCollisions(g_FocusBlock, DOWN) ) { slide_counter--; } // If there isn't a collision, we reset our counter. // This is in case the player moves out of a collision. else { slide_counter = SLIDE_TIME; } // If the counter hits zero, we reset it and call our // function that handles changing the focus block. if (slide_counter == 0) { slide_counter = SLIDE_TIME; HandleBottomCollision(); }*/ ClearScreen(); DrawBackground(); // Draw the focus block and next block. g_FocusBlock->Draw(g_Window); g_NextBlock->Draw(g_Window); // Draw the old squares. for (unsigned int i=0; i < g_OldSquares.size(); i++) { g_OldSquares[i]->Draw(g_Window); } // This will be passed to itoa() char temp[256]; std::string score = "Score: "; sprintf_s(temp,"%d",g_Score); //itoa(g_Score, temp, 10); // the 10 just tells itoa to use decimal notation score.append( temp ); std::string nextscore = "Needed Score: "; sprintf_s(temp,"%d",g_Level*POINTS_PER_LEVEL); nextscore.append(temp); std::string level = "Level: "; sprintf_s(temp,"%d",g_Level); level.append(temp); DisplayText(score, SCORE_RECT_X, SCORE_RECT_Y, 8, 0, 0, 0, 255, 255, 255); DisplayText(nextscore, NEEDED_SCORE_RECT_X, NEEDED_SCORE_RECT_Y, 8, 0, 0, 0, 255, 255, 255); DisplayText(level, LEVEL_RECT_X, LEVEL_RECT_Y, 8, 0, 0, 0, 255, 255, 255); SDL_UpdateRect(g_Window, 0, 0, 0, 0); g_Timer = SDL_GetTicks(); } }