A
Alvin
I'm making a very simple game in SDL, and I'm not asking for SDL help I
hope - this looks like something C++ related, so I'll ask here.
I have a class for a simple block, or tile, in the game, which can be
either on or off. I'm having trouble with the constructor though.
class block
{
private:
SDL_Surface *screen;
SDL_Surface *surface;
Uint32 selcol;
Uint32 offcol;
bool on;
public:
block(SDL_Surface *);
bool blit(int, int);
void enabled(bool);
} ;
/* ... */
block::block(SDL_Surface *mscreen)
{
screen = mscreen;
surface = SDL_CreateRGBSurface(screentype, blockw, blockh, bpp,
screen->format->Rmask, screen->format->Gmask,
screen->format->Bmask,
screen->format->Amask);
selcol = SDL_MapRGB(screen->format, selcolr, selcolg, selcolb);
offcol = SDL_MapRGB(screen->format, offcolr, offcolg, offcolb);
/* default is off */
on = false;
SDL_FillRect(surface, NULL, offcol);
}
I'm calling it from my `game' class:
class game
{
private:
SDL_Surface *screen;
Uint32 bgcol;
block grid[w][h];
bool blitblock(int, int);
public:
game();
} ;
I don't think details matter too much, but with my game constructor,
which follows:
game::game()
{
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("couldn't initialise SDL: %s\n", SDL_GetError());
exit(1);
}
screen = SDL_SetVideoMode(screenw, screenh, bpp, screentype);
for(int i = 0; i < w; i++)
for(int j = 0; j < h; j++)
grid[j] = block(screen);
}
I get the following error from g++:
g++ ./block.cpp ./game.cpp -c -lSDL -Wall
../game.cpp: In constructor `game::game()':
../game.cpp:4: error: no matching function for call to `block::block()'
../lgt.h:36: note: candidates are: block::block(const block&)
../lgt.h:45: note: block::block(SDL_Surface*)
I hope this is enough information - it's probably something really
stupid, too. The only thing I can think of is that I can't call the
constructor like I am for my block array.
Thanks,
Alvin
hope - this looks like something C++ related, so I'll ask here.
I have a class for a simple block, or tile, in the game, which can be
either on or off. I'm having trouble with the constructor though.
class block
{
private:
SDL_Surface *screen;
SDL_Surface *surface;
Uint32 selcol;
Uint32 offcol;
bool on;
public:
block(SDL_Surface *);
bool blit(int, int);
void enabled(bool);
} ;
/* ... */
block::block(SDL_Surface *mscreen)
{
screen = mscreen;
surface = SDL_CreateRGBSurface(screentype, blockw, blockh, bpp,
screen->format->Rmask, screen->format->Gmask,
screen->format->Bmask,
screen->format->Amask);
selcol = SDL_MapRGB(screen->format, selcolr, selcolg, selcolb);
offcol = SDL_MapRGB(screen->format, offcolr, offcolg, offcolb);
/* default is off */
on = false;
SDL_FillRect(surface, NULL, offcol);
}
I'm calling it from my `game' class:
class game
{
private:
SDL_Surface *screen;
Uint32 bgcol;
block grid[w][h];
bool blitblock(int, int);
public:
game();
} ;
I don't think details matter too much, but with my game constructor,
which follows:
game::game()
{
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("couldn't initialise SDL: %s\n", SDL_GetError());
exit(1);
}
screen = SDL_SetVideoMode(screenw, screenh, bpp, screentype);
for(int i = 0; i < w; i++)
for(int j = 0; j < h; j++)
grid[j] = block(screen);
}
I get the following error from g++:
g++ ./block.cpp ./game.cpp -c -lSDL -Wall
../game.cpp: In constructor `game::game()':
../game.cpp:4: error: no matching function for call to `block::block()'
../lgt.h:36: note: candidates are: block::block(const block&)
../lgt.h:45: note: block::block(SDL_Surface*)
I hope this is enough information - it's probably something really
stupid, too. The only thing I can think of is that I can't call the
constructor like I am for my block array.
Thanks,
Alvin