#include "world.h"
#include <SDL/SDL_image.h>
#define WORLD_W 40
#define WORLD_H 30
bool InitWorld()
{
SDL_Surface *temp = IMG_Load("map.gif");
for(int j = 0; j < WORLD_H; j++)
{
for(int i = 0; i < WORLD_W; i++)
{
world[j].image = temp;
world[j].value = 0;
world[j].x = i * 20;
world[j].y = j * 20;
}
}
return true;
}
void DisplayWorld(SDL_Surface *screen)
{
for(int j = 0; j < WORLD_H; j++)
{
for(int i = 0; i < WORLD_W; i++)
{
SDL_Rect rect;
rect.x = world[j].x;
rect.y = world[j].y;
SDL_BlitSurface(world[j].image, NULL, screen, &rect);
}
}
}
void Water()
{
SDL_Surface *temp = IMG_Load("water.gif");
for(int j = 20; j < 25; j++)
{
for(int i = 15; i < 25; i++)
{
world[j].image = temp;
world[j].value = 1;
}
}
}
void EraseTrace(int x, int y, SDL_Surface *screen)
{
SDL_Surface *erase = IMG_Load("map.gif");
SDL_Rect rect;
rect.x = x;
rect.y = y;
SDL_BlitSurface(erase, NULL, screen, &rect);
}
Linker Error?!
Hi all, I got this very weird problem.
This is my source file:
and these are my errors:
[Linker error] undefined reference to `world' (x10 or more)
world.cpp C:\WINDOWS\Desktop\Joshua\RPG\world.o(.text+0x13d) more undefined references to `world' follow
Anyone know what is causing these problems?
Assuming you're still working on the same thing as your last thread, it sounds like you declared a global variable extern in your header without actually defining it anywhere.
If you declare a global extern in a header file, in one source file you need to define the variable. So if you have extern WORLD world[40][30]; in your header, in one source file put WORLD world[40][30]; at namespace scope.
If you declare a global extern in a header file, in one source file you need to define the variable. So if you have extern WORLD world[40][30]; in your header, in one source file put WORLD world[40][30]; at namespace scope.
Where is the definition for world?
I assume you have an extern whatever world; in world.h, otherwise the code would not compile, but that's only a declaration.
See [orgfiles] for a potential explanation.
In the meantime, post your world.h file.
I assume you have an extern whatever world; in world.h, otherwise the code would not compile, but that's only a declaration.
See [orgfiles] for a potential explanation.
In the meantime, post your world.h file.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement