A while ago I made the decision to stop developing my MOD unrealspawn. however I considered the coding to be a nice hobby.
So I decided to pick up C++ and make some 2d game/simulation.
I started a project and got some problems, hopefully someone can help me.
I am working a simulation/game that consists out of a 2d dimensional grid. the grid is filled with objects that make up the elements for the game.
so far I created two classes
the world class:
the world class can be seen as the 2d sheet with grids. at start of the program one world object must be created.
this object will contain information like what objects are on the grid
the groundtile class:
the groundtile class is like a square that is placed on the grid of the world
below is my code, not all of it but the code that is relevant for now
Code: Select all
//world class is the 2d map that contains all the tiles and objects
class world
{
//function and variables under public can be called outside of the class
public:
//size of screen
int screensize;
//amount of squares on an axes in the screen
int amountofgrids;
int gridsize;
int gridposition[20];
void calculategridsize()
{
screensize=500;
amountofgrids=100;
gridsize = screensize/amountofgrids;
}
void createbackgroundtiles()
{
// creates a new tile
groundtile* bravenewgroundtile = new groundtile();
bravenewgroundtile->colorblue=0;
bravenewgroundtile->colorgreen=0;
bravenewgroundtile->colorred=0;
bravenewgroundtile->varredmin=255;
bravenewgroundtile->varredmax=255;
bravenewgroundtile->vargreenmin=255;
bravenewgroundtile->vargreenmax=255;
bravenewgroundtile->varbluemin=255;
bravenewgroundtile->varbluemax=255;
bravenewgroundtile->createself();
}
//only functions inside this class can acces the functions and variables under private
private:
};
// creates a new world
world* bravenewworld = new world();
//bravenewworld->calculategridsize();
//bravenewworld->createbackgroundtiles();
//groundtile class are the background tiles that are on the grid of the world
class groundtile
{
//function and variables under public can be called outside of the class
public:
//position variables
int tileposx,tileposy;
//color variables
int colorred, colorgreen, colorblue;
int varredmin,vargreenmin,varbluemin;
int varredmax,vargreenmax,varbluemax;
void createself()
{
totalred = decidecolor(varredmin,colorred,varredmax);
totalgreen = decidecolor(vargreenmin,colorgreen,vargreenmax);
totalblue = decidecolor(varbluemin,colorblue,varbluemax);
drawsquare(bravenewworld->gridsize,bravenewworld->gridsize,totalred,totalgreen,totalblue);
}
//only functions inside this class can acces the functions and variables under private
private:
int totalred,totalgreen,totalblue;
};
I created one object of the class world, so far no problem.
but I can not create an object of the class groundtile.
see function createbackgroundtiles() in the class world.
why is this?
I get these errors:
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(54): error C2065: 'groundtile' : undeclared identifier
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(54): error C2065: 'bravenewgroundtile' : undeclared identifier
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(54): error C2061: syntax error : identifier 'groundtile'
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(55): error C2065: 'bravenewgroundtile' : undeclared identifier
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(55): error C2227: left of '->colorblue' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(56): error C2065: 'bravenewgroundtile' : undeclared identifier
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(56): error C2227: left of '->colorgreen' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(57): error C2065: 'bravenewgroundtile' : undeclared identifier
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(57): error C2227: left of '->colorred' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(58): error C2065: 'bravenewgroundtile' : undeclared identifier
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(58): error C2227: left of '->varredmin' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(59): error C2065: 'bravenewgroundtile' : undeclared identifier
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(59): error C2227: left of '->varredmax' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(60): error C2065: 'bravenewgroundtile' : undeclared identifier
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(60): error C2227: left of '->vargreenmin' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(61): error C2065: 'bravenewgroundtile' : undeclared identifier
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(61): error C2227: left of '->vargreenmax' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(62): error C2065: 'bravenewgroundtile' : undeclared identifier
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(62): error C2227: left of '->varbluemin' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(63): error C2065: 'bravenewgroundtile' : undeclared identifier
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(63): error C2227: left of '->varbluemax' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(64): error C2065: 'bravenewgroundtile' : undeclared identifier
1>c:\users\daniel\desktop\overige\coding\tutorial_sdl\sdl_project\sdl_project\main.cpp(64): error C2227: left of '->createself' must point to class/struct/union/generic type
1> type is ''unknown-type''