Zacząłem taki mały projekt:
#include
#include
using namespace sf;
enum klocki {N,Z};
klocki mapa [5][5]={
{N,N,N,N,N},
{N,Z,Z,Z,N},
{Z,Z,Z,Z,Z},
{N,N,N,Z,Z},
{N,N,N,N,Z}
};
class klocek {
public:
Image i;
Sprite s;
klocek();
};
klocek::klocek(){
i.SetSmooth(false);
s.SetImage(i);
}
klocek green, blue;
list bricks;
void mapLoad(){
for (int y=0; y<5; y++) {
for (int x=0; x<5; x++) {
if (mapa[y][x]==N) {
blue.s.SetPosition(x*100,y*100);
bricks.push_back(blue.s);
}
if (mapa[y][x]==Z) {
green.s.SetPosition(x*100,y*100);
bricks.push_back(green.s);
}
}
}
}
int main()
{
RenderWindow App(VideoMode(0, 0), "SFML Graphics");
App.Create(VideoMode::GetMode(0), "SFML Window", Style::Fullscreen);
green.i.LoadFromFile("//green.jpg");
blue.i.LoadFromFile("//blue.jpg");
// Start game loop
while (App.IsOpened())
{
// Process events
Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == Event::Closed || Event.Type == Event::KeyPressed && Event.Key.Code == Key::Escape)
App.Close();
}
mapLoad();
// Clear screen
App.Clear();
// Draw apredefined shape
for(list::iterator i=bricks.begin();i!=bricks.end();i++){
App.Draw(*i);
}
// Finally, display the rendered frame on screen
App.Display();
}
return EXIT_SUCCESS;
}
Powinno to coś wyświetlać siatkę 5x5 złożoną z kwadratów. Żeby zaoszczędzić sobie pisania zrobiłem konstruktor:
klocek::klocek(){
i.SetSmooth(false);
s.SetImage(i);
}
Czy ktoś mógłby mnie oświecić czemu ten konstruktor się nie wykonuje?