Original Post
I have a weird problem, I had my application up and running, changed a few things, saw it didn't work, changed back and saw it still didn't work... I really don't see where the error should be. The application compiles fine, but won't display the map anymore, the has to be something wrong with this file: I think the error should be somewhere in the DisplayWorld() or InitWorld(), but I really can't find it. Maybe it is one of those stupid errors that you just don't see anymore after you have looked over it 100s of times. If the error is not here, I have made the full source code available here. Please give me some pointers as to how I could possibly fixe my problem, Joshua
#include <SDL/SDL_image.h>
#include <SDL/SDL.h>
#include <fstream>
#include <cstring>
#include <sstream>
#include "world.h"
#include "gamedata.h"
#include "log.h"
using namespace std;
#define WORLD_W 40
#define WORLD_H 30
WORLD world[40][30];
bool InitWorld()
{
SDL_Surface *grass = IMG_Load("map.gif");
SDL_Surface *water = IMG_Load("water.gif");
SDL_Surface *tree1 = IMG_Load("tree1.gif");
SDL_Surface *tree2 = IMG_Load("tree2.gif");
SDL_Surface *warp = IMG_Load("warp.gif");
ifstream file_in(gamedata.Map_Name.c_str());
if(!file_in)
return false;
int x = 0;
int y = 0;
char tile;
while(y != WORLD_H)
{
file_in >> tile;
switch(tile)
{
case '0':
world[x][y].image = grass;
world[x][y].value = 0;
break;
case '1':
world[x][y].image = water;
world[x][y].value = 1;
break;
case '2':
world[x][y].image = tree1;
world[x][y].value = 1;
break;
case '3':
world[x][y].image = tree2;
world[x][y].value = 1;
break;
case '4':
world[x][y].image = warp;
world[x][y].value = 0;
gamedata.wX = x * 20;
gamedata.wY = y * 20;
break;
default:
file_in.close();
return false;
break;
}
world[x][y].x = x*20;
world[x][y].y = y*20;
x++;
if(x == WORLD_W)
{
x = 0;
y++;
}
}
file_in.close();
logfile.Write("Loaded " + gamedata.Map_Name + " into the system");
return true;
}
void DisplayWorld()
{
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, gamedata.screen, ▭);
}
}
logfile.Write("Displayed " + gamedata.Map_Name + " onto the screen");
}
string ToString(int number)
{
stringstream temp;
temp << number;
return temp.str();
}
void ChangeWorld(int x)
{
string number = ToString(x);
string world = "worlds/world" + number;
gamedata.Map_Name = world + ".txt";
logfile.Write("--------------------------------");
logfile.Write("Changed worlds to: " + gamedata.Map_Name);
logfile.Write("--------------------------------");
InitWorld();
DisplayWorld();
}