Stunt Jumper Problem

Started by
7 comments, last by daviangel 17 years, 5 months ago
I have some knowledge to C++, yet still seem to go nowhere, since I only have one book. The blue book with Bloodshed C++. There is a game on there called stunt jumper, which I used to chop up and try and make my own side scrolling game. Well I did something wrong, and had to start over, while trying to compile I cannot seem to get past this error part! What I am trying to do is make a game like Hyper Iria(SNes) But! There is an error in the code, so I cannot start at all! What do I need to do to get past this error? It is near the bottom... (Original Code from the CD, I did nothing to it) //----------------------------------------------------------------- // Bitmap Object // C++ Source - Bitmap.cpp //----------------------------------------------------------------- //----------------------------------------------------------------- // Include Files //----------------------------------------------------------------- #include "Bitmap.h" //----------------------------------------------------------------- // Bitmap Constructor(s)/Destructor //----------------------------------------------------------------- Bitmap::Bitmap() : m_hBitmap(NULL), m_iWidth(0), m_iHeight(0) { } // Create a bitmap from a file Bitmap::Bitmap(HDC hDC, LPTSTR szFileName) : m_hBitmap(NULL), m_iWidth(0), m_iHeight(0) { Create(hDC, szFileName); } // Create a bitmap from a resource Bitmap::Bitmap(HDC hDC, UINT uiResID, HINSTANCE hInstance) : m_hBitmap(NULL), m_iWidth(0), m_iHeight(0) { Create(hDC, uiResID, hInstance); } // Create a blank bitmap from scratch Bitmap::Bitmap(HDC hDC, int iWidth, int iHeight, COLORREF crColor) : m_hBitmap(NULL), m_iWidth(0), m_iHeight(0) { Create(hDC, iWidth, iHeight, crColor); } Bitmap::~Bitmap() { Free(); } //----------------------------------------------------------------- // Bitmap Helper Methods //----------------------------------------------------------------- void Bitmap::Free() { // Delete the bitmap graphics object if (m_hBitmap != NULL) { DeleteObject(m_hBitmap); m_hBitmap = NULL; } } //----------------------------------------------------------------- // Bitmap General Methods //----------------------------------------------------------------- BOOL Bitmap::Create(HDC hDC, LPTSTR szFileName) { // Free any previous bitmap info Free(); // Open the bitmap file HANDLE hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return FALSE; // Read the bitmap file header BITMAPFILEHEADER bmfHeader; DWORD dwBytesRead; BOOL bOK = ReadFile(hFile, &bmfHeader, sizeof(BITMAPFILEHEADER), &dwBytesRead, NULL); if ((!bOK) || (dwBytesRead != sizeof(BITMAPFILEHEADER)) || (bmfHeader.bfType != 0x4D42)) { CloseHandle(hFile); return FALSE; } BITMAPINFO* pBitmapInfo = (new BITMAPINFO); if (pBitmapInfo != NULL) { // Read the bitmap info header bOK = ReadFile(hFile, pBitmapInfo, sizeof(BITMAPINFOHEADER), &dwBytesRead, NULL); if ((!bOK) || (dwBytesRead != sizeof(BITMAPINFOHEADER))) { CloseHandle(hFile); Free(); return FALSE; } // Store the width and height of the bitmap m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth; m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight; // Get a handle to the bitmap and copy the image bits PBYTE pBitmapBits; m_hBitmap = CreateDIBSection(hDC, pBitmapInfo, DIB_RGB_COLORS, (PVOID*)&pBitmapBits, NULL, 0); if ((m_hBitmap != NULL) && (pBitmapBits != NULL)) { SetFilePointer(hFile, bmfHeader.bfOffBits, NULL, FILE_BEGIN); bOK = ReadFile(hFile, pBitmapBits, pBitmapInfo->bmiHeader.biSizeImage, &dwBytesRead, NULL); if (bOK) return TRUE; } } // Something went wrong, so cleanup everything Free(); return FALSE; } BOOL Bitmap::Create(HDC hDC, UINT uiResID, HINSTANCE hInstance) { // Free any previous DIB info Free(); // Find the bitmap resource HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(uiResID), RT_BITMAP); if (hResInfo == NULL) return FALSE; // Load the bitmap resource HGLOBAL hMemBitmap = LoadResource(hInstance, hResInfo); if (hMemBitmap == NULL) return FALSE; // Lock the resource and access the entire bitmap image PBYTE pBitmapImage = (BYTE*)LockResource(hMemBitmap); if (pBitmapImage == NULL) { FreeResource(hMemBitmap); return FALSE; } // Store the width and height of the bitmap BITMAPINFO* pBitmapInfo = (BITMAPINFO*)pBitmapImage; m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth; m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight; // Get a handle to the bitmap and copy the image bits PBYTE pBitmapBits; m_hBitmap = CreateDIBSection(hDC, pBitmapInfo, DIB_RGB_COLORS, (PVOID*)&pBitmapBits, NULL, 0); if ((m_hBitmap != NULL) && (pBitmapBits != NULL)) { const PBYTE pTempBits = pBitmapImage + pBitmapInfo->bmiHeader.biSize + pBitmapInfo->bmiHeader.biClrUsed * sizeof(RGBQUAD); CopyMemory(pBitmapBits, pTempBits, pBitmapInfo->bmiHeader.biSizeImage); // Unlock and free the bitmap graphics object UnlockResource(hMemBitmap); FreeResource(hMemBitmap); return TRUE; } // Something went wrong, so cleanup everything UnlockResource(hMemBitmap); FreeResource(hMemBitmap); Free(); return FALSE; } BOOL Bitmap::Create(HDC hDC, int iWidth, int iHeight, COLORREF crColor) { // Create a blank bitmap m_hBitmap = CreateCompatibleBitmap(hDC, iWidth, iHeight); if (m_hBitmap == NULL) return FALSE; // Set the width and height m_iWidth = iWidth; m_iHeight = iHeight; // Create a memory device context to draw on the bitmap HDC hMemDC = CreateCompatibleDC(hDC); // Create a solid brush to fill the bitmap HBRUSH hBrush = CreateSolidBrush(crColor); // Select the bitmap into the device context HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, m_hBitmap); // Fill the bitmap with a solid color RECT rcBitmap = { 0, 0, m_iWidth, m_iHeight }; FillRect(hMemDC, &rcBitmap, hBrush); // Cleanup SelectObject(hMemDC, hOldBitmap); DeleteDC(hMemDC); DeleteObject(hBrush); return TRUE; } void Bitmap::Draw(HDC hDC, int x, int y, BOOL bTrans, COLORREF crTransColor) { DrawPart(hDC, x, y, 0, 0, GetWidth(), GetHeight(), bTrans, crTransColor); } void Bitmap::DrawPart(HDC hDC, int x, int y, int xPart, int yPart, int wPart, int hPart, BOOL bTrans, COLORREF crTransColor) { if (m_hBitmap != NULL) { // Create a memory device context for the bitmap HDC hMemDC = CreateCompatibleDC(hDC); // Select the bitmap into the device context HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, m_hBitmap); // Draw the bitmap to the destination device context if (bTrans) TransparentBlt(hDC, x, y, wPart, hPart, hMemDC, xPart, yPart, wPart, hPart, crTransColor); else BitBlt(hDC, x, y, wPart, hPart, hMemDC, xPart, yPart, SRCCOPY); // Restore and delete the memory device context SelectObject(hMemDC, hOldBitmap); DeleteDC(hMemDC); } }
Owner of Acht - Productions------------------------------http://www.acht-productions.inc5.com/
Advertisement
I spent about 30 seconds looking for the error 'near the bottom', and then gave up. Maybe others will be more patient, but you could make it a lot easier for us by posting the exact error and referring us directly to the line in question.

Also, use [ source ][ /source ] tags (without the spaces) to format your code. You can edit your original post using the 'edit' button.
Try the book author's forum here
http://www.michaelmorrison.com/mambo/index.php?option=com_simpleboard&Itemid=48&func=showcat&catid=35
I remember reading this book a while back and the author makes his win32 api code alot more complex than needs to be and some of the code(especially image bitmap loading) was pretty buggy.
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
Unfortunately no vendor is compliant to the standard so if you copy paste it into a compiler the author didnt use, it might not work. On top of that, authors love to put code on their CDs that doesn't work even if you use the same compiler as them.

However, don't you find it a little ridiculous that you are posting a huge chunk of code, without using source tags, and expecting people trying to help you to find the error for you AND fix it with only a vague description of where it is?
// Draw the bitmap to the destination device context
if (bTrans)
TransparentBlt(hDC, x, y, wPart, hPart, hMemDC, xPart, yPart, wPart,
hPart, crTransColor); <
// Draw the bitmap to the destination device context
if (bTrans)
TransparentBlt(hDC, x, y, wPart, hPart, hMemDC, xPart, yPart, wPart,
hPart, crTransColor); <--------------------THIS LINE COMES UP "ERROR"
else
BitBlt(hDC, x, y, wPart, hPart, hMemDC, xPart, yPart, SRCCOPY);
Owner of Acht - Productions------------------------------http://www.acht-productions.inc5.com/
Quote:Original post by bibliophile6
// Draw the bitmap to the destination device context
if (bTrans)
TransparentBlt(hDC, x, y, wPart, hPart, hMemDC, xPart, yPart, wPart,
hPart, crTransColor); <--------------------THIS LINE COMES UP "ERROR"
else
BitBlt(hDC, x, y, wPart, hPart, hMemDC, xPart, yPart, SRCCOPY);
To reiterate:

1. Use [ source ][ /source ] tags (without the spaces) to format your code. You can repost your code with these tags, or edit your previous posts (especially the first one) and add the tags so that your code is readable.

2. Post the exact error generated by your compiler.
    // Draw the bitmap to the destination device context    if (bTrans)      TransparentBlt(hDC, x, y, wPart, hPart, hMemDC, xPart, yPart, wPart,       hPart, crTransColor);                    <---------------Error Right here    else      BitBlt(hDC, x, y, wPart, hPart, hMemDC, xPart, yPart, SRCCOPY);


"Line 222 : TransparentBlt is undeclared, start with this function"
Owner of Acht - Productions------------------------------http://www.acht-productions.inc5.com/
The author includes a fix for your problem if you look under F.A.Q in the forum link I previously provided:
Why do I get a TransparentBlt error when compiling with Dev-C++?
Dev-C++ issues a compiler error for all of the examples that use the TransparentBlt() function. This problem has to do with the fact that the standard windows.h header file in Dev-C++ is set to target an older version of Windows that doesn't support TransparentBlt(). I included a fix for this problem in the ReadMe.txt file in the DevCPP example folder on the CD-ROM, but it's easy to miss that file. There are actually two ways to solve the problem. Solution 1 solves the problem permanently, while Solution 2 solves it on a project-by-project basis.
Maybe you need to spend some time looking at the post on those forums as I did when I was working through the same book about a year ago to save yourself and others some time.
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe

This topic is closed to new replies.

Advertisement