Subversion Repositories sssnakesss

Compare Revisions

Ignore whitespace Rev 4 → Rev 7

/src/sssnakesss.cpp
2,7 → 2,10
#include "SDL/SDL_image.h"
#include "SDL/SDL_opengl.h"
 
#include <dirent.h>
#include <iostream>
#include <vector>
#include <map>
 
using namespace std;
 
77,6 → 80,17
 
void SSSNAKESSS::initData()
{
string dataDir = "data/";
string graphicsDir = dataDir + "graphics/";
vector<string> graphicsList = listDir(graphicsDir);
for (unsigned int i = 0; i < graphicsList.size(); i++)
{
string file = graphicsList[i];
string fullfilename = graphicsDir + file;
textures[file] = new Texture(fullfilename);
}
}
 
void SSSNAKESSS::run()
117,3 → 131,26
void SSSNAKESSS::end()
{
}
 
vector<string> SSSNAKESSS::listDir(string dirName)
{
vector<string> files;
DIR *dp = opendir(dirName.c_str());
if (dp != NULL)
{
dirent *ep;
while ((ep = readdir(dp)))
{
string n = ep->d_name;
if (n != "." && n != "..")
{
files.push_back(n);
}
}
closedir(dp);
}
 
return files;
}
/src/texture.cpp
102,3 → 102,11
glEnd();
}
}
 
void drawTexture(Texture *texture, int x, int y)
{
if (texture)
{
texture->draw(x, y);
}
}
/include/sssnakesss.hpp
20,11 → 20,15
void draw();
void end();
vector<string> listDir(string dir);
private:
bool running;
SDL_Surface *screen;
map<string, Texture *> textures;
};
 
#endif // SSSNAKESSS_HPP
/include/texture.hpp
19,4 → 19,6
int halfHeight;
};
 
void drawTexture(Texture *texture, int x, int y);
 
#endif // TEXTURE_HPP