Yes I'm having trouble with my code. I don't understand why it is not displayed right. I've tryed sfml tutorials on youtube, but no help to me.
Beginner self thaugh programmer.
class Tile{
sf::Sprite spr;
public:
void LoadTile(sf::Texture& tex){
spr.setTexture(tex);
}
void draw(sf::RenderWindow* rw){
//spr.SetPosition(x,y);
(*rw).draw(spr);
}
sf::Vector2f getsize(){}
};
class Level{
std::vector<std::vector<Tile*> > map1;
int h,w;
public:
Level(int x,int y){
map1.resize(x);
for(int i=0;i<x;i++)
map1.at(i).resize(y,0);
this->h=x;
this->w=y;
}
void AddTile(int x,int y,Tile* tile){
map1[x][y]=tile;
}
Tile* GetTile(int x,int y){return map1[x][y];}
};
void LoadLevel(int*level){
Level*p=new Level(2,2);
Tile*tile;
int currentTile=0;
sf::Texture grass,brick;
grass.loadFromFile("321.jpg");
brick.loadFromFile("123.jpg");
for(int i=0;i<2;i++)
for(int j=0;j<2;j++){
currentTile= level[i+j];
std::cout<<currentTile;
if(currentTile==1){
tile=new Tile;
(*tile).LoadTile(brick);
}
else if(currentTile==0){
tile=new Tile;
(*tile).LoadTile(grass);}
(*p).AddTile(i,j,tile);
}
for(int i=0;i<2;i++)
for(int j=0;j<2;j++){
Tile* tile1 =(*p).GetTile(i,j);
tile1->draw(&window);
}
}
int main(){
int level[4]={0,1,0,1};
sf::RenderWindow window(sf::ViderMode(800,600)"game");
while(window.isOpen()){
sf::Event eve;
while(window.pollEvent(eve)){
if(eve.type==sf::Event::Closed)
window.close();
LoadLevel(level);
window.display();
}
}
std::cout<<"Hello World! "<<count;
return 0;