void DrawCursorTile() { // Create a rect to specify what part of our bitmaps we want to draw RECT rPortion = {0, 0, TILE_WIDTH, TILE_HEIGHT}; // Here we update our cursor position and convert it to client // coordinates (our window coordinates), not the screen coordinates. GetCursorPos(&g_cursorPos); ScreenToClient(g_hWnd, &g_cursorPos); // Since exits down have a bitmap associated with them, we need // to tell this function it's okay if there isn't a valid cursor tile // only if the current type selected is exits. if(g_pCurrentMap->GetCurrentType() != EXIT_TYPE) if(!g_pCursorTile) return; // If the current type is a normal map tile, draw it with no transparency. // We line up the cursor bitmap so that it's dead center on the cursor. if(g_pCurrentMap->GetCurrentType() == TILE_TYPE) g_Buffer.DisplayBitmap(g_pCursorTile->GetBitmap(), g_cursorPos.x - TILE_WIDTH/2, g_cursorPos.y - TILE_HEIGHT/2, rPortion); // If we are wanting to insert an exit, just draw a red rectangle else if(g_pCurrentMap->GetCurrentType() == EXIT_TYPE) Rectangle(g_Buffer.GetHDC(), g_cursorPos.x - TILE_WIDTH/2, g_cursorPos.y - TILE_HEIGHT/2, g_cursorPos.x + TILE_WIDTH/2, g_cursorPos.y + TILE_HEIGHT/2); // Otherwise draw a transparent bitmap for the rest of the tile tiles (items, monsters, etc...) else g_Buffer.DisplayTransparentBitmap(g_pCursorTile->GetBitmap(), g_cursorPos.x - TILE_WIDTH/2, g_cursorPos.y - TILE_HEIGHT/2, rPortion); // If the left button is still help down if(g_bLButtonDown) { // Grab the index on our 2D map depending on our cursor position int mapIndexX = g_cursorPos.x / TILE_WIDTH; int mapIndexY = g_cursorPos.y / TILE_HEIGHT; // Insert the tile type into our map according to it's index g_pCurrentMap->InsertTile(g_pCursorTile, mapIndexX, mapIndexY); // If it's not a normal tile, don't allow multiple draws per click. // If you want to allow rapid drawing of other objects, delete this. if(g_pCurrentMap->GetCurrentType() != TILE_TYPE) g_bLButtonDown = 0; } }
void RenderScene() { // Make sure we have a current map pointer before we go shootin' blanks if(!g_pCurrentMap) return; // Here we set the portion of our bitmaps that we want to draw. RECT rPortion = {0, 0, TILE_WIDTH, TILE_HEIGHT}; // Next we draw the current map (Default is just all green grass tiles) g_pCurrentMap->Draw(); // Grab the size of the current tool bar type list (Not our map's placed tile lists) int size = g_pCurrentMap->GetCurrentTypeSize(); // Go through our tiles in the tool bar and draw them, but subtract the scroll bar position // from the size. This makes it so we only draw the tiles that can be seen in the tool bar. for(int i = 0; i < size - g_scrollBarPosY; i++) { // Depending on "i" and the scroll bar position, get the current tile's bitmap to draw HBITMAP bitmap = g_pCurrentMap->GetCurrentTypeTile(i + g_scrollBarPosY)->GetBitmap(); // If the tool bar is showing map tiles then draw the tiles with no transparency if(g_pCurrentMap->GetCurrentType() == TILE_TYPE) g_ToolBuffer.DisplayBitmap(bitmap, 0, TILE_WIDTH * i, rPortion); else // Draw the current tiles with a transparency (white) (i.e. items, monsters, etc...) g_ToolBuffer.DisplayTransparentBitmap(bitmap, 0, TILE_WIDTH * i, rPortion); } //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// DrawCursorTile(); // Draw the current cursor tile if chosen //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Swap the backbuffers to display the bitmaps to the screen g_Buffer.SwapBackBuffer(FALSE); g_ToolBuffer.SwapBackBuffer(TRUE); }