Just for your info, VS.NET 2002 complained about only const static integral data members is allowed to be initialized inside a class or struct. It is easily fixed though (if anybody else has this problem):
Code:
// Change this in Item.h
class Item : public GraphicObject {
protected:
int points;
int lifeTime;
int creationTime;
const static float len = 1.0f / (2*(WIDTH+5)); // 1/2 length of drawable width/height
public:
Item() { init(); }
Item(Point2i p) { setPos(p.x, p.y); init(); }
Item(int x, int y) { setPos(x, y); init(); }
~Item() {}
void init() { points = 0; }
void setPoints(int p) { points = p; }
int getPoint() { return points; }
virtual void draw();
};
// to
class Item : public GraphicObject {
protected:
int points;
int lifeTime;
int creationTime;
const float len; // 1/2 length of drawable width/height
public:
Item():len(1.0f / (2*(WIDTH+5))) { init(); }
Item(Point2i p):len(1.0f / (2*(WIDTH+5))) { setPos(p.x, p.y); init(); }
Item(int x, int y):len(1.0f / (2*(WIDTH+5))) { setPos(x, y); init(); }
~Item() {}
void init() { points = 0; }
void setPoints(int p) { points = p; }
int getPoint() { return points; }
virtual void draw();
};
And
Code:
// In file SnakeBit.h change
class SnakeBit : public GraphicObject {
SnakeBit* next;
const static float len = 1.0f / (2*WIDTH); // 1/2 length of drawable width/height
public:
SnakeBit() { next = NULL; }
SnakeBit(const Point2i p) { setPos(p.x, p.y); next = NULL; }
SnakeBit(int x, int y) { setPos(x, y); next = NULL; }
~SnakeBit() {}
SnakeBit* getNext() { return next; }
void setNext(SnakeBit* n) { next = n; }
void moveVertical(int amount) { pos.y += amount; }
void moveHorizontal(int amount) { pos.x += amount; }
virtual void draw();
};
// to
class SnakeBit : public GraphicObject {
SnakeBit* next;
const float len; // 1/2 length of drawable width/height
public:
SnakeBit():len(1.0f / (2*WIDTH)) { next = NULL; }
SnakeBit(const Point2i p):len(1.0f / (2*WIDTH)) { setPos(p.x, p.y); next = NULL; }
SnakeBit(int x, int y):len(1.0f / (2*WIDTH)) { setPos(x, y); next = NULL; }
~SnakeBit() {}
SnakeBit* getNext() { return next; }
void setNext(SnakeBit* n) { next = n; }
void moveVertical(int amount) { pos.y += amount; }
void moveHorizontal(int amount) { pos.x += amount; }
virtual void draw();
};
This was the only way I could get the game running (if I copied it correctly ) but otherwise it is nice!