Hi all,
I'm doing a 3d pacman game for a university project which has to be written in c++ (3rd year and having never been taught any c++) My problem is that when I initialise the map array I cannot return the value back to the main method.
The values in the arrays are int's which will be used in constructing the maps (e.g 0 = wall 1 = nothing etc.)
When compiling, the line in the "getCell(x,y)" method gives the error which is "'map' undeclared (first use this function)" and if I put "this->map" it gives an "invalid use of 'this' in non-member function"
Any healp would be greatly appreciated.
My mapInit header:
//Header file for the map initialiser
#ifndef MAPINIT_H_
#define MAPINIT_H_
#include <windows.h> // Header File For Windows
#include <math.h> // Header File For Windows Math Library
#include <stdio.h> // Header File For Standard Input/Output
#include <stdarg.h> // Header File For Variable Argument Routines
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The Glaux Library
//Class mapInit begin
class mapInit
{
public:
unsigned int getCell(unsigned int x, unsigned int y);
void setMap( unsigned int mapSet );
private:
unsigned int map[22][19];
};
#endif
My mapInit class:
//Map initialization class
//Code begin
#include "mapInit.h"
void mapInit::setMap( unsigned int mapSet )
{
if ( mapSet == 1 )
{
unsigned int mapBuffer[22][19] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,6,6,6,6,6,9,9,9,9,9,9,6,6,6,6,6,6,0},
{0,6,0,0,0,0,0,0,6,0,6,0,0,0,0,0,0,6,0},
{0,6,6,8,8,0,6,6,6,0,6,6,6,0,6,6,6,6,0},
{0,0,6,0,6,0,6,0,0,0,0,0,6,0,8,0,6,0,0},
{0,7,6,0,6,6,6,6,6,2,6,6,6,8,8,0,6,7,0},
{0,6,0,0,6,0,0,0,6,0,6,0,0,0,8,0,0,6,0},
{0,6,8,8,6,6,6,6,6,0,6,6,6,6,6,6,6,6,0},
{0,0,0,0,6,0,1,0,0,0,0,0,1,0,6,0,0,0,0},
{0,0,0,0,6,0,1,1,1,12,1,1,1,0,9,0,0,0,0},
{0,0,0,0,6,0,1,0,0,0,0,0,1,0,9,0,0,0,0},
{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8,0,0,8,0,8,0},
{0,7,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,0},
{0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0} };
this->map[22][19] = mapBuffer[22][19];
}
}
unsigned int getCell(unsigned int x, unsigned int y)
{
return this->map[x][y];
}