Subversion Repositories sssnakesss

Compare Revisions

Ignore whitespace Rev 4 → Rev 10

/tmake.lua
2,7 → 2,7
Language("C++")
 
function build()
Set("Sources", Srcs("main.cpp", "sssnakesss.cpp", "texture.cpp"))
Set("Sources", Srcs("main.cpp", "sssnakesss.cpp", "texture.cpp", "point.cpp", "snake.cpp"))
Set("Libraries", Libs("SDL", "SDL_image", "SDL_mixer", "SDL_ttf", "GL"))
Set("Includes", Incs("SDL", "SDL_image", "SDL_mixer", "SDL_ttf"))
 
/include/point.hpp
0,0 → 1,13
#ifndef POINT_HPP
#define POINT_HPP
 
class Point
{
public:
Point(int x, int y);
 
int X;
int Y;
};
 
#endif // POINT_HPP
/include/sssnakesss.hpp
1,8 → 1,6
#ifndef SSSNAKESSS_HPP
#define SSSNAKESSS_HPP
 
struct SDL_Surface;
 
class SSSNAKESSS
{
public:
20,11 → 18,16
void draw();
void end();
vector<string> listDir(string dir);
private:
bool running;
SDL_Surface *screen;
map<string, Texture *> textures;
Snake *snake;
};
 
#endif // SSSNAKESSS_HPP
/include/snake.hpp
0,0 → 1,20
#ifndef SNAKE_HPP
#define SNAKE_HPP
 
class Snake
{
public:
Snake();
void nextPoint(Point newPoint);
 
// Stuff that should be private
vector<Point> points; // list of points snake occupies
 
// Colour Values
int R;
int G;
int B;
};
 
#endif // SNAKE_HPP
/include/texture.hpp
19,4 → 19,6
int halfHeight;
};
 
void drawTexture(Texture *texture, int x, int y);
 
#endif // TEXTURE_HPP
/src/sssnakesss.cpp
2,10 → 2,15
#include "SDL/SDL_image.h"
#include "SDL/SDL_opengl.h"
 
#include <dirent.h>
#include <iostream>
#include <vector>
#include <map>
 
using namespace std;
 
#include "point.hpp"
#include "snake.hpp"
#include "texture.hpp"
#include "sssnakesss.hpp"
 
33,6 → 38,8
initData();
snake = new Snake;
return true;
}
 
77,6 → 84,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()
88,6 → 106,8
checkEvents();
update();
draw();
SDL_GL_SwapBuffers();
}
}
 
112,8 → 132,36
 
void SSSNAKESSS::draw()
{
//drawTexture(textures["food.png"], 20, 20);
}
 
void SSSNAKESSS::end()
{
delete snake;
SDL_FreeSurface(screen);
SDL_Quit();
}
 
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
11,7 → 11,7
{
loaded = false;
GLenum textureFormat = GL_RGB;
GLenum textureFormat = GL_RGBA;
SDL_Surface *surface = IMG_Load(filename.c_str());
if (surface)
102,3 → 102,11
glEnd();
}
}
 
void drawTexture(Texture *texture, int x, int y)
{
if (texture)
{
texture->draw(x, y);
}
}
/src/snake.cpp
0,0 → 1,15
#include <vector>
 
using namespace std;
 
#include "point.hpp"
#include "snake.hpp"
 
Snake::Snake()
{
}
 
void Snake::nextPoint(Point newPoint)
{
points.push_back(newPoint);
}
/src/main.cpp
1,3 → 1,17
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_opengl.h"
 
#include <dirent.h>
#include <iostream>
#include <vector>
#include <map>
 
using namespace std;
 
#include "point.hpp"
#include "snake.hpp"
#include "texture.hpp"
#include "sssnakesss.hpp"
 
int main(int argc, char *argv[])
/src/point.cpp
0,0 → 1,7
#include "point.hpp"
 
Point::Point(int x, int y)
{
X = x;
Y = y;
}
/history.txt
0,0 → 1,0
18/24/10 23:29 - Freddie: I think a point struct is needed, so I made one (sort of). Rather than building the sname properties into sssnakesss.cpp I think we should have a vector of class snake. I'm happy to write this class entirley, just want a Go-Ahead. In other news, if I am creating an instance class/struct, do you use class_name::func_name or class_name.func_name? From your code I get the impression it is the same as Static, but this seems wrong/silly. Enjoy. Oh, yeah - lets keep this going, so we know what is happening easily and can explainface stuffs.