Game Design Music and Art

compiling – gaurdianAQ

gaurdianAQ

Member

Posts: 106
From:
Registered: 01-15-2007
ok I took a course on how to program games in c++ and I copied the code exactly from my course and changed all of the names and stuff but I get like 100 errors and they are all the same thing missing struct/class or something like that yet I used the exact same thing at my course and it worked fine it says that for every line the way I am doing it is I have a header file and it declares a bunch of variables in a structure called sprite I will just show you the code oh I am using Visual Studio Professional

#include "sprite.h"
#include "Resource.h"
#include <math.h>

extern HDC OffScreenDC;

Sprite Ship;

void ShipSet()
{
HDC htempDC;
HMODULE ProgramModule;

BITMAP bmtemp;

htempDC = GetDC(0);
ProgramModule = GetModuleHandle(NULL);

//Initializing Ship!!!!!!!!!!!!!!!!!!!!!!!
Ship.picBMP = (HBITMAP)LoadImage(ProgramModule, (char*)IDB_SHIPPIC, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
Ship.hsourceDC = CreateCompatibleDC(htempDC);
SelectObject(Ship.hsourceDC, Ship.picBMP);
//Ship MASK!!!!!!!!!!!!!!!!!!!!!!!!!!!
Ship.picMASK = (HBITMAP)LoadImage(ProgramModule, (char*)IDB_SHIPMASK, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
Ship.hmaskDC = CreateCompatibleDC(htempDC);
SelectObject(Ship.hmaskDC, Ship.picMASK);

GetObject(Ship.picBMP, sizeof BITMAP, (void*)&bmtemp);

//sets all the cell sections of the animation cycle
Ship.WIDTH = bmtemp.bmWidth;
Ship.HEIGHT = bmtemp.bmHeight
ReleaseDC(0, htempDC);

Ship.Position.x = 250;
Ship.Position.y = 420;

Ship.Speed.x = 0;
Ship.Speed.y = 0;

if (Ship.WIDTH > Ship.HEIGHT)
Ship.Radius = Ship.HEIGHT / 2;
else
Ship.Radius = Ship.WIDTH / 2;
}

void ShipDraw()
{
//draws the Ship to the back buffer
BitBlt (OffScreenDC, Ship.Position.x, Ship.Position.y, 26, 34, Ship.hmaskDC, 0, 0, SRCAND);
BitBlt (OffScreenDC, Ship.Position.x, Ship.Position.y, 26, 34, Ship.hsourceDC, 0, 0, SRCPAINT);

}


right now it says missing stadfx or something like that but I don't use that in my other game only in the main file here is the header file code

#include <windows.h>
#define NORMAL 0
#define EXPLODING 2
struct Sprite
{
HBITMAP picBMP;
HDC hsourceDC;
HBITMAP picMASK;
HDC hmaskDC;
POINT Position;
POINT Speed;
int WIDTH;
int HEIGHT;
long Radius;
int State;
int CountDown;
};
void ShipSet();
void ShipDraw();

and here is the main window code which Visual Studio puts in

// Space Blitz.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "Space Blitz.h"
#include "sprite.h"
#include "Resource.h"
#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
ShipSet();

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_SPACEBLITZ, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SPACEBLITZ));

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}

//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SPACEBLITZ));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_SPACEBLITZ);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
ShipDraw();
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}


sorry if this is to much code I do not know of anyway to shorten it so I don't expect a fast reply oh one other thing is the other game was made in an older version of visual studio 2003 to be exact the one I have is 2005 if any of you are familiar with it I took the Real Programming For Kids course.... of I think it is a compiling setting that I need to change because in the course we changed a compiling setting but I don't know how to do it in 2005 right now I am just trying to draw it on the screen

[This message has been edited by gaurdianAQ (edited July 27, 2007).]

[This message has been edited by gaurdianAQ (edited July 27, 2007).]

[This message has been edited by gaurdianAQ (edited July 27, 2007).]

gaurdianAQ

Member

Posts: 106
From:
Registered: 01-15-2007
there fixed the code boxes
Briant

Member

Posts: 742
From: Stony Plain, Alberta, Canada
Registered: 01-20-2001
Post some of the compiler errors as well, please.

------------------
Brian

"OOP programmers have a lot of class"

Check out this webhost! Fantastic prices, features and support!

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
Part of the problem is Visual Studio defaults projects to using something called pre-compiled headers. This is your StdAfx.cpp and StdAfx.h. It's a way to speed up incremental compiles by having standard headers already pre-compiled. No need to get into the in's and out's of it for this thread.

So, you'll notice the one file you have has: #include "stdafx.h" You can add this to the top of your other C/CPP files inside your project. Since your project defaults each code file to use pre-compiled headers, it is REQUIRED to have that line at the very tippy top of EVERY source file.

This leaves you with two options.

1) Add: include "stdafx.h" to each C/CPP file in your project. This is not for the header file. Keep in mind, other than comments, that include MUST be the first line in the file.

2) The other option is turn of pre-compiled headers. From within the Solution Explorer, right-click on your file. Again, not the H file, but the CPP file. Select Properties. Somewhere in there is an option to turn pre-compiled headers on/off. I'm not in front of Visual Studio, so I don't recall the exact location. It's probably under C++/General/Pre-Compiled Headers.

That should at least help you resolve this issue.

gaurdianAQ

Member

Posts: 106
From:
Registered: 01-15-2007
thats it thats what they told us to do
gaurdianAQ

Member

Posts: 106
From:
Registered: 01-15-2007
1>------ Build started: Project: Space Blitz, Configuration: Debug Win32 ------
1>Compiling...
1>sprite.cpp
1>c:\users\gaurdianaq\documents\visual studio 2005\projects\space blitz\space blitz\sprite.cpp(20) : error C2664: 'LoadImageW' : cannot convert parameter 2 from 'char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\gaurdianaq\documents\visual studio 2005\projects\space blitz\space blitz\sprite.cpp(24) : error C2664: 'LoadImageW' : cannot convert parameter 2 from 'char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\gaurdianaq\documents\visual studio 2005\projects\space blitz\space blitz\sprite.cpp(33) : error C2146: syntax error : missing ';' before identifier 'ReleaseDC'
1>Build log was saved at "file://c:\Users\gaurdianAQ\Documents\Visual Studio 2005\Projects\Space Blitz\Space Blitz\Debug\BuildLog.htm"

now I am getting these errors lol any idea I am pretty sure it is the same in my other code lol

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
Those calls with the 'W' mean you have Unicode set. Right-click your Project in Solution Explorer and select Properties. Click Configuration Properties/General and select Character Set to Not Set.

The last error is because of a missing semi-colon:
Ship.HEIGHT = bmtemp.bmHeight should have a semi-colon at the end.

gaurdianAQ

Member

Posts: 106
From:
Registered: 01-15-2007
k
gaurdianAQ

Member

Posts: 106
From:
Registered: 01-15-2007
I got the program working but all I get now is a black screen here is the updated code

#include "sprite.h"
#include "background.h"
#include "Resource.h"
#include <math.h>

extern HDC OffScreenDC;

Sprite Ship;

void ShipSet()
{
HDC htempDC;
HMODULE ProgramModule;

BITMAP bmtemp;

htempDC = GetDC(0);
ProgramModule = GetModuleHandle(NULL);

//Initializing Ship!!!!!!!!!!!!!!!!!!!!!!!
Ship.picBMP = (HBITMAP)LoadImage(ProgramModule, (char*)IDB_SHIPPIC, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
Ship.hsourceDC = CreateCompatibleDC(htempDC);
SelectObject(Ship.hsourceDC, Ship.picBMP);
//Ship MASK!!!!!!!!!!!!!!!!!!!!!!!!!!!
Ship.picMASK = (HBITMAP)LoadImage(ProgramModule, (char*)IDB_SHIPMASK, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
Ship.hmaskDC = CreateCompatibleDC(htempDC);
SelectObject(Ship.hmaskDC, Ship.picMASK);

GetObject(Ship.picBMP, sizeof BITMAP, (void*)&bmtemp);

//sets all the cell sections of the animation cycle
Ship.WIDTH = bmtemp.bmWidth;
Ship.HEIGHT = bmtemp.bmHeight;
ReleaseDC(0, htempDC);

Ship.Position.x = 250;
Ship.Position.y = 420;

Ship.Speed.x = 0;
Ship.Speed.y = 0;

if (Ship.WIDTH > Ship.HEIGHT)
Ship.Radius = Ship.HEIGHT / 2;
else
Ship.Radius = Ship.WIDTH / 2;
}

void ShipDraw()
{
//draws the Ship to the back buffer
BitBlt (OffScreenDC, Ship.Position.x, Ship.Position.y, 0, 0, Ship.hmaskDC, 0, 0, SRCAND);
BitBlt (OffScreenDC, Ship.Position.x, Ship.Position.y, 0, 0, Ship.hsourceDC, 0, 0, SRCPAINT);

}


#include "background.h"
#include "Resource.h"

HDC OffScreenDC;
void ScreenSet()
{
HDC htempDC;
HBITMAP OffScreenBMP;
htempDC = GetDC(0);

//Initializing Buffer!!!!!!!!!!!!!!!!!!!!!!
OffScreenDC = CreateCompatibleDC(htempDC);
OffScreenBMP = CreateCompatibleBitmap(htempDC, 800, 600);
SelectObject(OffScreenDC, OffScreenBMP);
ReleaseDC(0, htempDC);

}

//draws from the back buffer to the front buffer
void ScreenDraw(HWND hWnd)
{
HDC ScreenDC;
ScreenDC = GetDC(hWnd);
BitBlt (ScreenDC, 0, 0, 800, 600, OffScreenDC, 0, 0, SRCCOPY);
}



#include <windows.h>
struct Sprite
{
HBITMAP picBMP;
HDC hsourceDC;
HBITMAP picMASK;
HDC hmaskDC;
POINT Position;
POINT Speed;
int WIDTH;
int HEIGHT;
long Radius;
int State;
int CountDown;
};
void ShipSet();
void ShipDraw();


// Evan_Kenny.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "Space Blitz.h"
#include "sprite.h"
#include "background.h"
#include "Resource.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
extern Sprite Ship;

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
//calls the object setting functions
ShipSet();
ScreenSet();
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_SPACEBLITZ, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SPACEBLITZ);

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}

//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SPACEBLITZ);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCTSTR)IDC_SPACEBLITZ;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, 800, 600, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}
//sets the timer
SetTimer (hWnd, 1, 100, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
ShipDraw();
ScreenDraw(hWnd);
EndPaint(hWnd, &ps);
break;
//Checks for keyboard input
case WM_KEYDOWN:
switch (wParam)
{
//checks for left key
case VK_LEFT:
Ship.Speed.x = -20;
break;
//checks the right key
case VK_RIGHT:
Ship.Speed.x = 20;
break;
//checks for the up key
case VK_UP:
Ship.Speed.y = -20;
break;
//checks for down key
Ship.Speed.y = 20;
break;
}
break;
//checks to see if the keys have been released
case WM_KEYUP:
switch (wParam)
{
case VK_LEFT:
Ship.Speed.x = 0;
break;
case VK_RIGHT:
Ship.Speed.x = 0;
break;
case VK_UP:
Ship.Speed.y = 0;
break;
case VK_DOWN:
Ship.Speed.y = 0;

}
break;
//events that happen as the timer clicks
case WM_TIMER:
PostMessage(hWnd, WM_PAINT, 0, 0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Message handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}



#include <windows.h>
struct BackGround
{
HBITMAP picBMP;
HDC hsourceDC;
POINT Position;
int Width;
int Height;
};
void ScreenSet();
void ScreenDraw(HWND hWnd);

once again sorry for so much code but its c++ you know lol

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
Hey, call screenDraw() before the shipDraw()

------------------
Psa 32:5 I acknowledged my sin unto thee, and mine iniquity have I not hid. I said, I will confess my transgressions unto the LORD; and thou forgavest the iniquity of my sin. Selah.

[VoHW] (Help needed) [Blog] (Contact) - Truedisciple (mp3)

gaurdianAQ

Member

Posts: 106
From:
Registered: 01-15-2007
hey I had it like that with the other program that worked and I still can't get the ship to draw
Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
Well, that sounds strange because if the ship is drawn first and then screen filled it should be left in background (under the fill).
But first I would make sure the WM_PAINT is invoked.

I also noticed there is function called "_tWinMain" (notice the _t?). I havent seen that before but just WinMain().

------------------
Psa 32:5 I acknowledged my sin unto thee, and mine iniquity have I not hid. I said, I will confess my transgressions unto the LORD; and thou forgavest the iniquity of my sin. Selah.

[VoHW] (Help needed) [Blog] (Contact) - Truedisciple (mp3)