Alright, during the course of programming the game i am working on, I have come to a major problem. For whatever reason, it is no longer allowing me to initialize classes. It acts like it has no idea what the class tag is. I'm pretty sure it is not the headers, becuase i have used classes with all the prebuilt headers that are in this game except one, windowsx.h but i tested it and that is not the problem.
i have tried to create the class in both the header i made and in the main source, and both come up with the same message.
main source:
my header (which has the class in it right now):Code:#include <windows.h>
#include <windowsx.h>
#include "sidescrolling.h"
static char g_szClassName[] = "MyWindowClass";
static HINSTANCE g_hInst = NULL;
const UINT idTimer1 = 1;
UINT nTimerDelay = 10;
HBITMAP hbmPlayer, hbmPlayerMask, hbmTerrorist, hbmTerroristMask, hbmBullet, hbmBulletMask;
BITMAP bm, bmT, bmBullet;
int playerx, playery, terrorist1x, terrorist1y, bulletx, bullety;
int playerhealth = 100;
int terroristhealth = 50;
int Jumping = 0;
HWND hwnd, JumpThreadID, TerroristThreadID;
void ErasePlayer(HDC hdc)
{
RECT rc;
rc.left = playerx + 11;
rc.top = playery;
rc.right = playerx + bm.bmWidth - 12;
rc.bottom = playery + bm.bmHeight + 1;
FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
}
void DrawPlayer(HDC hdc)
{
HDC hdcMemory;
hdcMemory = CreateCompatibleDC(hdc);
SelectObject(hdcMemory, hbmPlayerMask);
BitBlt(hdc, playerx, playery, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCAND);
SelectObject(hdcMemory, hbmPlayer);
BitBlt(hdc, playerx, playery, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCPAINT);
DeleteDC(hdcMemory);
}
void UpdatePlayer(HWND hwnd)
{
RECT rc;
GetClientRect(hwnd, &rc);
if(playerx < 0){
playerx = 0;
}
else if(playerx + bm.bmWidth > rc.right){
playerx = rc.right - bm.bmWidth;
}
if(playery < 0){
playery = 0;
}
else if(playery + bm.bmHeight > rc.bottom){
playery = rc.bottom - bm.bmHeight;
}
}
void EraseTerrorist(HDC hdc)
{
RECT rc;
rc.left = terrorist1x + 10;
rc.top = terrorist1y + 8;
rc.right = terrorist1x + bm.bmWidth - 11;
rc.bottom = terrorist1y + bm.bmHeight - 6;
FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
}
void DrawTerrorist(HDC hdc)
{
HDC hdcMemory;
hdcMemory = CreateCompatibleDC(hdc);
SelectObject(hdcMemory, hbmTerroristMask);
BitBlt(hdc, terrorist1x, terrorist1y, bmT.bmWidth, bmT.bmHeight, hdcMemory, 0, 0, SRCAND);
SelectObject(hdcMemory, hbmTerrorist);
BitBlt(hdc, terrorist1x, terrorist1y, bmT.bmWidth, bmT.bmHeight, hdcMemory, 0, 0, SRCPAINT);
DeleteDC(hdcMemory);
}
void UpdateTerrorist(HWND hwnd)
{
RECT rc;
GetClientRect(hwnd, &rc);
if(terrorist1x < 0){
terrorist1x = 0;
}
else if(terrorist1x + bmT.bmWidth > rc.right){
terrorist1x = rc.right - bmT.bmWidth;
}
if(terrorist1y < 0){
terrorist1y = 0;
}
else if(terrorist1y + bmT.bmHeight > rc.bottom){
terrorist1y = rc.bottom - bmT.bmHeight;
}
}
void PlayerJump() {
int oldy = playery;
HDC hdcWindow = GetDC(hwnd);
while(playery > oldy - 80) {
playery -= 8;
ErasePlayer(hdcWindow);
UpdatePlayer(hwnd);
DrawPlayer(hdcWindow);
Sleep(16);
}
while(playery < oldy) {
playery += 8;
ErasePlayer(hdcWindow);
UpdatePlayer(hwnd);
DrawPlayer(hdcWindow);
Sleep(8);
}
Jumping = 0;
ReleaseDC(hwnd, hdcWindow);
TerminateThread(JumpThreadID, 0);
return;
}
void LoadTerrorist() {
hbmTerrorist = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_TERRORIST));
GetObject(hbmTerrorist, sizeof(bmT), &bmT);
hbmTerroristMask = CreateBitmap(bmT.bmWidth, bmT.bmHeight, 1, 1, NULL);
HDC hdcSrc = CreateCompatibleDC(NULL);
HDC hdcDst = CreateCompatibleDC(NULL);
HBITMAP hbmSrcT = SelectBitmap(hdcSrc, hbmTerrorist);
HBITMAP hbmDstT = SelectBitmap(hdcDst, hbmTerroristMask);
COLORREF clrTopLeft = GetPixel(hdcSrc, 0, 0);
COLORREF clrSaveBk = SetBkColor(hdcSrc, clrTopLeft);
BitBlt(hdcDst, 0, 0, bmT.bmWidth, bmT.bmHeight, hdcSrc, 0, 0, SRCCOPY);
COLORREF clrSaveDstText = SetTextColor(hdcSrc, RGB(255,255,255));
SetBkColor(hdcSrc, RGB(0,0,0));
BitBlt(hdcSrc, 0, 0, bmT.bmWidth, bmT.bmHeight, hdcDst, 0, 0, SRCAND);
SetTextColor(hdcDst, clrSaveDstText);
SetBkColor(hdcSrc, clrSaveBk);
SelectBitmap(hdcSrc, hbmSrcT);
SelectBitmap(hdcDst, hbmDstT);
DeleteDC(hdcSrc);
DeleteDC(hdcDst);
}
void TerroristAI() {
int attacking = 0;
HDC hdc = GetDC(hwnd);
for(;;) {
if(terroristhealth <= 0) {
break;
}
if(terrorist1x - playerx <= 160) {
attacking = 1;
}
if(attacking == 1) {
if(terrorist1x > playerx) {
terrorist1x -= 5;
}
else if(terrorist1x < playerx) {
terrorist1x += 5;
}
Sleep(75);
//Sleep(1000);
EraseTerrorist(hdc);
UpdateTerrorist(hwnd);
DrawTerrorist(hdc);
}
}
attacking = 0;
ReleaseDC(hwnd, hdc);
TerminateThread(TerroristThreadID, 0);
}
void LoadBullet() {
hbmBullet = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_BULLET));
GetObject(hbmBullet, sizeof(bmBullet), &bmBullet);
hbmBulletMask = CreateBitmap(bmBullet.bmWidth, bmBullet.bmHeight, 1, 1, NULL);
HDC hdcSrc = CreateCompatibleDC(NULL);
HDC hdcDst = CreateCompatibleDC(NULL);
HBITMAP hbmSrcT = SelectBitmap(hdcSrc, hbmBullet);
HBITMAP hbmDstT = SelectBitmap(hdcDst, hbmBulletMask);
COLORREF clrTopLeft = GetPixel(hdcSrc, 0, 0);
COLORREF clrSaveBk = SetBkColor(hdcSrc, clrTopLeft);
BitBlt(hdcDst, 0, 0, bmBullet.bmWidth, bmBullet.bmHeight, hdcSrc, 0, 0, SRCCOPY);
COLORREF clrSaveDstText = SetTextColor(hdcSrc, RGB(255,255,255));
SetBkColor(hdcSrc, RGB(0,0,0));
BitBlt(hdcSrc, 0, 0, bmBullet.bmWidth, bmBullet.bmHeight, hdcDst, 0, 0, SRCAND);
SetTextColor(hdcDst, clrSaveDstText);
SetBkColor(hdcSrc, clrSaveBk);
SelectBitmap(hdcSrc, hbmSrcT);
SelectBitmap(hdcDst, hbmDstT);
DeleteDC(hdcSrc);
DeleteDC(hdcDst);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdcWindow;
switch(Message)
{
case WM_CREATE:
/*
hbmPlayer = LoadBitmap(g_hInst, "BALLBMP");
hbmPlayerMask = LoadBitmap(g_hInst, "MASKBMP");
if(!hbmPlayer || !hbmPlayerMask){
MessageBox(hwnd, "Load of resources failed.", "Error", MB_OK | MB_ICONEXCLAMATION);
return -1;
}
GetObject(hbmPlayer, sizeof(bm), &bm);
*/
SetTimer(hwnd, idTimer1, nTimerDelay, NULL);
playerx = 32;
playery = 230;
terrorist1x = 240;
terrorist1y = 230;
bulletx = 0;
bullety = 0;
hbmPlayer = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_SEAL));
GetObject(hbmPlayer, sizeof(bm), &bm);
hbmPlayerMask = CreateBitmap(bm.bmWidth,bm.bmHeight,1,1,NULL);
HDC hdcSrc = CreateCompatibleDC(NULL);
HDC hdcDst = CreateCompatibleDC(NULL);
HBITMAP hbmSrcT = SelectBitmap(hdcSrc,hbmPlayer);
HBITMAP hbmDstT = SelectBitmap(hdcDst,hbmPlayerMask);
COLORREF clrTopLeft = GetPixel(hdcSrc,0,0);
COLORREF clrSaveBk = SetBkColor(hdcSrc,clrTopLeft);
BitBlt(hdcDst,0,0,bm.bmWidth,bm.bmHeight,hdcSrc,0,0,SRCCOPY);
COLORREF clrSaveDstText = SetTextColor(hdcSrc,RGB(255,255,255));
SetBkColor(hdcSrc,RGB(0,0,0));
BitBlt(hdcSrc,0,0,bm.bmWidth,bm.bmHeight,hdcDst,0,0,SRCAND);
SetTextColor(hdcDst,clrSaveDstText);
SetBkColor(hdcSrc,clrSaveBk);
SelectBitmap(hdcSrc,hbmSrcT);
SelectBitmap(hdcDst,hbmDstT);
DeleteDC(hdcSrc);
DeleteDC(hdcDst);
LoadBullet();
LoadTerrorist();
TerroristThreadID = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)TerroristAI, NULL, 0, NULL);
break;
/*
case WM_TIMER:
if(hbmPlayer && hbmPlayerMask)
{
hdcWindow = GetDC(hwnd);
ErasePlayer(hdcWindow);
UpdatePlayer(hwnd);
DrawPlayer(hdcWindow);
ReleaseDC(hwnd, hdcWindow);
}
break;
*/
case WM_PAINT:
if(hbmPlayer && hbmPlayerMask)
{
hdcWindow = BeginPaint(hwnd, &ps);
DrawPlayer(hdcWindow);
DrawTerrorist(hdcWindow);
EndPaint(hwnd, &ps);
}
break;
case WM_KEYDOWN:
switch(wParam) {
case VK_LEFT:
playerx -= 5;
hdcWindow = GetDC(hwnd);
ErasePlayer(hdcWindow);
UpdatePlayer(hwnd);
DrawPlayer(hdcWindow);
ReleaseDC(hwnd, hdcWindow);
break;
case VK_RIGHT:
playerx += 5;
hdcWindow = GetDC(hwnd);
ErasePlayer(hdcWindow);
UpdatePlayer(hwnd);
DrawPlayer(hdcWindow);
ReleaseDC(hwnd, hdcWindow);
break;
case VK_UP:
if(Jumping == 0) {
JumpThreadID = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PlayerJump, NULL, 0, NULL);
Jumping = 1;
}
break;
/*
case VK_DOWN:
playery += 5;
hdcWindow = GetDC(hwnd);
ErasePlayer(hdcWindow);
UpdatePlayer(hwnd);
DrawPlayer(hdcWindow);
ReleaseDC(hwnd, hdcWindow);
break;
*/
case VK_SPACE:
break;
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
KillTimer(hwnd, idTimer1);
DeleteObject(hbmPlayer);
DeleteObject(hbmPlayerMask);
DeleteObject(hbmTerrorist);
DeleteObject(hbmTerroristMask);
DeleteObject(hbmBullet);
DeleteObject(hbmBulletMask);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndClass;
MSG Msg;
g_hInst = hInstance;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = g_hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&WndClass))
{
MessageBox(0, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Side Scrolling Shooter",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 320,
NULL, NULL, g_hInst, NULL);
if(hwnd == NULL)
{
MessageBox(0, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
Code:#define IDB_SEAL 103
#define IDB_TERRORIST 105
#define IDB_BULLET 107
class Bullets {
private:
struct General {
int x;
int y;
int inuse;
};
public:
General B1, B2, B3, B4, B5, B6, B7, B8, B9, B10;
} PlayerBullets, TerroristBullets;
resource:
the error message:Code:#include "sidescrolling.h"
IDB_SEAL BITMAP "SEAL.bmp"
IDB_TERRORIST BITMAP "Terrorist1.bmp"
IDB_BULLET BITMAP "bullet.bmp"
for some background, this is the start of an army side scrolling shooter.Quote:
In file included from scrollingtest.c
parser error before "Bullets"
syntax error before '{' token
parser error before '}' token
[Warning] data definition has no type or storage class
[Build Error] [sidescrollingtest.o] Error 1
if any other info is needed, please ask.
Thanks in advance.