Hi,
I'm in the middle of writing a game for part of my uni coursework using a directx wrapper, and it's giving me loads of errors like:
C:\My Documents\University\cmt3311\new\main.cpp(247) : error C2059: syntax error : 'constant'
C:\My Documents\University\cmt3311\new\main.cpp(248) : error C2228: left of '.levelData' must have class/struct/union type
and I can't understand it because i've defined the struct right at the top, but for some reason it's not recognising it. Can anyone give me some help? the source code is below.
Any help would be greatly appretiated.
Luke
// Include the directx 8 utility library:
#include <dxu.h>
#include <fstream.h>
#include "spriteanimation.h"
//#include "leveldata.h"
#define TITLE "New"
//--------------------------------------------------------
// Structs
struct levelObjects{
int objType;
int object; // Location of the object in the array, so I know which tile to move (updated along with the objType variable
// in both the target and source tile)
};
//--------------------------------------------------------
//--------------------------------------------------------
// Globals
DXUIMAGE pathImages[50];
SpriteAnim2 pathSprites[60][45];
SpriteAnim4 bully;
DXUIMAGE bullyImages[8];
DXUIMAGE objectImages[50];
SpriteAnim4 objectSprites[1000];
int pathData[60][45];
levelObjects levelData[60][45];
int screenX, screenY;
int playerX, playerY;
int tempObject;
int currentObject = 0;
int currentLevel = 0;
int gameState = 0;
int gameStateActive = 0;
char levelFile[20];
//--------------------------------------------------------
//--------------------------------------------------------
// Function prototypes
void LoadLevelImages();
void SetLevelSprites();
void InitialisePath();
void InitialiseObjects();
void ReadInLevel();
void RenderLevel();
//--------------------------------------------------------
// Main:
int APIENTRY WinMain(HINSTANCE hinstance,
HINSTANCE hPreInstance,
LPSTR lpCmdLine,int nCmdShow)
{
double renderTime = 0;
// Load the Direct3D COM and Build the current systems device list:
if ( !DXULoadDirectXGraphics() )
{
DXUDisplayLastError();
return -1;
}
// Set Window Title Name and window name
DXUSetWindowInfo(TITLE,"new");
// Create a WIN32 window:add 6 and 26 to account for window borders
if(!DXUCreateWindow(hinstance,0,0,640+6 ,480+26))
{
DXUDisplayLastError();
return -1;
}
// Initialise Windowed Graphics:
// Note: Default Full Screen Mode is ( 640x480x16 )
if (!DXUInitGraphics())
{
DXUDisplayLastError();
return -1;
}
// DXUToggleFullscreen();
// Initialise input
DXUInitInput();
// initialise keyboard input
DXUInitKeyboard();
// Main game loop:
while (DXUProcessMessages()) // Process The system Messages
{
DXUReadKeyboard();
if ( DXUIsTimeToRender() )
{
if( gameState == 0 )
{
gameState = 1;
}
if( gameState == 1 )
{
gameState = 2;
}
if( gameState == 2 )
{
if( gameStateActive == 0 )
{
ReadInLevel();
LoadLevelImages();
SetLevelSprites();
gameStateActive = 1;
}
}
// press escape key and exit
if ( dxuKeyState[DIK_ESCAPE] )
DXUDestroyWindow();
// Double Buffering:
DXURenderPrepare();
renderTime += DXUGetSecsPerFrame();
/*DXUDrawSpriteFast(&sprScene);
DXUDrawSprite(&sprPang);*/
RenderLevel();
DXURenderFinish();
}
}
// Do not forget to release everything:
// Program may crash without releasing:
DXUReleaseKeyboard();
DXUCloseInput();
DXUReleaseGraphics();
DXUUnloadDirectXGraphics();
return DXUGetLastMessage()->wParam;
}
void LoadLevelImages()
{
// Depending on which level the player is currently on the images will change
if ( currentLevel > 0 && currentLevel < 11 )
{
DXULoadImage(&pathImages[0],"bmp/aEmpty1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[1],"bmp/aPath1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[2],"bmp/aPath2.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[3],"bmp/aPath3.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[4],"bmp/aHoleFilled1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[5],"bmp/aHole1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[6],"bmp/aBlock1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[7],"bmp/aBlock2.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[8],"bmp/aBlock3.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[9],"bmp/aEntrance1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[10],"bmp/aEntrance2.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[11],"bmp/aEntrance3.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[12],"bmp/aEntrance4.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[13],"bmp/aExit1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[14],"bmp/aExit2.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[15],"bmp/aExit3.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[16],"bmp/aExit4.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[17],"bmp/aTele1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[18],"bmp/aTele2.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[19],"bmp/aTele3.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&pathImages[20],"bmp/aTele4.bmp",DXUCK_NOCOLOURKEY);
// Object Tiles, won't be in path array in the game
DXULoadImage(&objectImages[1],"bmp/aArrowRight1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[2],"bmp/aArrowDown1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[3],"bmp/aArrowLeft1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[4],"bmp/aArrowUp1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[5],"bmp/aArrowRightHit1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[6],"bmp/aArrowDownHit1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[7],"bmp/aArrowLeftHit1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[8],"bmp/aArrowUpHit1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[9],"bmp/aSlipRight1.bmp",RGB(255,0,255));
DXULoadImage(&objectImages[10],"bmp/aSlipDown1.bmp",RGB(255,0,255));
DXULoadImage(&objectImages[11],"bmp/aSlipLeft1.bmp",RGB(255,0,255));
DXULoadImage(&objectImages[12],"bmp/aSlipUp1.bmp",RGB(255,0,255));
DXULoadImage(&objectImages[13],"bmp/aSlipHitRight1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[14],"bmp/aSlipHitDown1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[15],"bmp/aSlipHitLeft1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[16],"bmp/aSlipHitUp1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[17],"bmp/aHoleFiller1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[18],"bmp/aBombBlock1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[19],"bmp/aTurnTable1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[20],"bmp/aCrumbleBlock1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[21],"bmp/aTeleBlock1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[22],"bmp/aTeleBlock2.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[23],"bmp/aTeleBlock3.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[24],"bmp/aTeleBlock4.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[25],"bmp/a10Fuel1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[26],"bmp/a20Fuel1.bmp",DXUCK_NOCOLOURKEY);
DXULoadImage(&objectImages[27],"bmp/a50Fuel1.bmp",DXUCK_NOCOLOURKEY);
}
DXULoadImage(&bullyImages[0],"bmp/aBullyRight1.bmp",DXURGB(255,0,255));
DXULoadImage(&bullyImages[1],"bmp/aBullyDown1.bmp",DXURGB(255,0,255));
DXULoadImage(&bullyImages[2],"bmp/aBullyLeft1.bmp",DXURGB(255,0,255));
DXULoadImage(&bullyImages[3],"bmp/aBullyUp1.bmp",DXURGB(255,0,255));
}
void SetLevelSprites()
{
int arrayx, arrayy;
for( arrayx = 0; arrayx < 60; arrayx++ )
{
for( arrayy = 0; arrayy < 45; arrayy++ )
{
if( pathData[arrayx][arrayy] > 0 && pathData[arrayx][arrayy] < 21 )
pathSprites[arrayx][arrayy].SetSpriteAnim( pathImages[pathData[arrayx][arrayy]], arrayx*32-screenX, arrayy*32-screenY, 64, 32 );
if( levelData[arrayx][arrayy].objType > 0 && levelData[arrayx][arrayy].objType < 28 )
{
tempObject = levelData[arrayx][arrayy].objType;
objectSprites[currentObject].SetSpriteAnim( objectImages[tempObject], arrayx*32-screenX, arrayy*32-screenY. 64, 32 );
levelData[arrayx][arrayy].object = currentObject;
levelData[arrayx][arrayy].steps = 4;
levelData[arrayx][arrayy].step = 1;
levelData[arrayx][arrayy].velocityX = 0;
levelData[arrayx][arrayy].velocityY = 0;
levelData[arrayx][arrayy].moving = false;
currentObject++;
}
}
}
DXULoadImage(&bullyImages[0],"bmp/aBullyDown1.bmp",DXUCKRGB(255,0,255));
bully.SetSpriteAnim( bullyImages[0], playerX*32-screenX, playerY*32-screenY, 64, 64 );
}
void ReadInLevel()
{
InitialisePath();
InitialiseObjects();
strcpy(levelFile,"level1.lev");
// Set the level data, reads in from file
ifstream inFile;
inFile.open( levelFile, ios::in | ios::binary );
char columnBuffer[45];
for ( int arrayx = 0; arrayx < 60; arrayx++ )
{
inFile.read(columnBuffer,45);
for ( int fillBuffer = 0; fillBuffer < 45; fillBuffer++ )
{
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
// Organise the tiles, which are path tiles and which are object tiles?
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
if ( int(columnBuffer[fillBuffer]) < 21 )
pathData[arrayx][fillBuffer] = int(columnBuffer[fillBuffer]);
else if ( int(columnBuffer[fillBuffer]) > 20 && int(columnBuffer[fillBuffer]) < 48 )
{
pathData[arrayx][fillBuffer] = 1;
levelData[arrayx][fillBuffer].objType = int(columnBuffer[fillBuffer]) - 20;
}
}
}
inFile.close();
// Set the screen position
screenX = 640;
screenY = 480;
playerX = 26;
playerY = 21;
}
void InitialisePath()
{
for( arrayx = 0; arrayx < 60; arrayx++ )
{
for( arrayy = 0; arrayy < 45; arrayy++ )
{
pathData[arrayx][arrayy] = 0;
}
}
}
void InitialiseObects()
{
for( arrayx = 0; arrayx < 60; arrayx++ )
{
for( arrayy = 0; arrayy < 45; arrayy++ )
{
levelData[arrayx][arrayy].objType = 0;
levelData[arrayx][arrayy].object = -1;
}
}
}
void RenderLevel()
{
for( arrayx = 0; arrayx < 60; arrayx++ )
{
for( arrayy = 0; arrayy < 45; arrayy++ )
{
if( levelData[arrayx][arrayy].object > -1 )
objectSprites[levelData[arrayx][arrayy].object].RenderSprite();
pathSprites[arrayx][arrayy].RenderSprite();
}
}
}