Czy ktoś mógłby zerknąć na ten kod i powiedzieć co jest źle napisane? Program się kompiluje ale zaraz po uruchomieniu i naciśnięciu klawisza strzałki rozkłada się (wywala) na całej linii.
#include <SFML/Graphics.hpp>
#include "tilemap.hpp"
#include "fps.hpp"
#include "kolizja.h"
int main()
{
sf::RenderWindow window( sf::VideoMode( 800, 600 ), "Labirynt" );
sf::Texture backg;
sf::Texture kula;
sf::Texture brick[ 10 ];
backg.loadFromFile( "back.png" );
sf::Sprite Back( backg );
kula.loadFromFile( "kula.png" );
sf::Sprite Kula( kula );
brick[ 0 ].loadFromFile( "brick.png" );
brick[ 1 ].loadFromFile( "brick.png" );
brick[ 2 ].loadFromFile( "brick.png" );
brick[ 3 ].loadFromFile( "brick.png" );
sf::Sprite Brick_0( brick[ 0 ] );
float brx_0 = 352, bry_0 = 480;
int x = 400, y = 540;
const int level[ 25 ][ 20 ] =
{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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window.pollEvent( event ) )
{
if( event.type == sf::Event::Closed )
window.close();
else if( sf::Keyboard::isKeyPressed( sf::Keyboard::Escape ) )
{
window.close();
}
else if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) )
{
if( level[ x ][ y - 20 ] == 0 || level[ x ][ y - 20 ] == 2 )
y = 340;
}
else if( sf::Keyboard::isKeyPressed( sf::Keyboard::Down ) )
{
if( level[ x ][ y + 1 ] == 0 || level[ x ][ y + 1 ] == 2 )
y = 240;
}
fp.getFPS();
fp.update();
}
Back.setPosition( 0, 0 );
Kula.setPosition( x, y );
Brick_0.setPosition( brx_0, bry_0 );
window.clear();
window.draw( Back );
window.draw( Kula );
window.draw( Brick_0 );
window.draw( map );
window.display();
}
return 0;
}