Here's the full code, sorry if it's a bit messy:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <fstream>
using namespace sf;
using namespace std;
int main()
{
///////////////////////////////BEGIN LOAD FUNCTION///////////////////////////////////
//Read *filename
//Char array "LEVEL" that will store the integers of file
char level[10][10];
//Read textfle (2D char array made up of a series of integers/letters)
ifstream file("level.txt");
//Store the array into a "temp holder" called tileNum
std::string line;
int height = 0;
while(std::getline(file, line))
{
for(int width = 0; width < 10; width++)
{
level[height][width] = line.at(width);
}
height++;
}
//Close file stream
file.close();
for(int y = 0; y < 10; y++)
{
for(int x = 0; x < 10; x++)
{
cout << level[y][x];
}
cout << endl;
}
/////////////////////////////END LOAD FUNCTION//////////////////////////////////////
///*
/////////////////////////////BEGIN DISPLAY FUNCION//////////////////////////////////
//Display using SFML
//Render Window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "The CodeWarrior");
//Create image
sf::Image blockImage;
sf::Image groundImage;
if(!blockImage.LoadFromFile("blocks.jpg"))
{
return EXIT_FAILURE;
}
if(!groundImage.LoadFromFile("ground.jpg"))
{
return EXIT_FAILURE;
}
//Create Sprite
sf::Sprite blockTile(blockImage);
sf::Sprite groundTile(groundImage);
//Game loop
while (App.IsOpened())
{
sf::Event Event;
while(App.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
{
App.Close();
}
}
//Clear window
App.Clear();
int num;
//Scroll through level and display corresponding image of tile
for(int y = 0; y < 10; y++)
{
for(int x = 0; x < 10; x++)
{
cout << level[y][x] << "LEVEL"; //Test to see what level[y][x] is outputting
cout << endl;
num = level[y][x];
cout << "LOL" << num << "LOL"; // Test to see what num is outputting
cout << endl;
if(num == 48)
{
blockTile.SetPosition(x*32, y*32);
App.Draw(blockTile);
}
else if(num == 49)
{
groundTile.SetPosition(x*32, y*32);
App.Draw(groundTile);
}
}
}
//Display sprites
App.Display();
}
return EXIT_SUCCESS;
//*/
}