Hello everyone
i am new to forums and i am posting this thread because i have a problem...
the problem is that visual c++ 2010 express says i cant create an abstract object... i created a class (below) which inherits sf::drawable and uses virtual void draw()... function...
heres the source code of the class:
basically i am trying to create a game map...
class Tile:public sf::Drawable
{
sf::Texture t;
sf::Sprite s;
int __walkable,__gate;
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
target.draw(s,states);
}
public:
void LoadTex(std::string __str)
{
t.loadFromFile(__str);
s.setTexture(t);
}
void SetPos(sf::Vector2f __v)
{
s.setPosition(__v);
}
void SetPos(float x,float y)
{
s.setPosition(x,y);
}
void SetWalkable(int __w)
{
__walkable = __w;
}
int GetWalkable()
{
return __walkable;
}
void SetGate(int __g)
{
__gate = __g;
}
int GetGate()
{
return __gate;
}
sf::FloatRect GetRectBounds()
{
return s.getGlobalBounds();
}
};
class WorldMap:public sf::Drawable
{
std::list<Tile> _map;
std::string MapDB,mapfiles[3];
void Draw(sf::RenderTarget& target, sf::RenderStates states) const
{
for(std::list<Tile>::const_iterator it = _map.begin();it != _map.end();it++)
{
target.draw(*it,states);
}
}
public:
WorldMap()
{
MapDB = "Assets/Maps/_map.db";
}
int LoadMap(int id)
{
_map.clear();
Strings str;
sqlite3_stmt *stmt;
sqlite3 *db;
sqlite3_open(MapDB.c_str(),&db);
int i = 1,type,grid;
sf::Vector2f pos(35,35);
SetMapFiles(id);
while(true)
{
str = "SELECT * FROM Map";
str += id;
str += " WHERE id = ";
str += i;
res = sqlite3_prepare_v2(db,str.GetChar(),strlen(str.GetChar()),&stmt,NULL);
if(res != SQLITE_OK) break;
sqlite3_step(stmt);
type = sqlite3_column_int(stmt,0);
grid = sqlite3_column_int(stmt,1);
if(type == MAP_TYPE_WALKABLE)
{
Tile tile;
tile.SetPos(pos);
tile.LoadTex(mapfiles[0]);
tile.SetGate(0);
tile.SetWalkable(1);
tile.SetPos(pos.x*i,pos.y*grid);
_map.push_back(tile);
}
if(type == MAP_TYPE_NON_WALKABLE)
{
Tile tile;
tile.SetPos(pos);
tile.LoadTex(mapfiles[1]);
tile.SetGate(0);
tile.SetWalkable(0);
tile.SetPos(pos.x*i,pos.y*grid);
_map.push_back(tile);
}
if(type == MAP_TYPE_GATE)
{
Tile tile;
tile.SetPos(pos);
tile.LoadTex(mapfiles[2]);
tile.SetGate(1);
tile.SetWalkable(1);
tile.SetPos(pos.x*i,pos.y*grid);
_map.push_back(tile);
}
i++;
}
return 1;
}
void SetMapFiles(int id)
{
if(id == 1)
{
mapfiles[0] = "Assets/Maps/1-1.png";
mapfiles[1] = "Assets/Maps/1-2.png";
mapfiles[2] = "Assets/Maps/1-3.png";
}
}
};
please help me... if u need complete source code i can email you or something... but i would like to not give out my source just yet
thanks
regards, elec