pekfos |
» 2025-07-13 22:28:17 Jeśli chcesz. |
|
tBane Temat założony przez niniejszego użytkownika |
» 2025-07-13 23:03:25 Ok. Dziękuję :-) |
|
tBane Temat założony przez niniejszego użytkownika |
» 2025-07-14 12:08:54 Ja to tak zrobiłem. Na razie sa sprajty ale zastąpie je niebawem sf::VertexArray. #ifndef map_hpp #define map_hpp
class Map { public: sf::Vector2f position; std::vector < int > terrain_types; std::vector < int > terrain_values; sf::Vector2i size; std::vector < sf::Sprite > sprites; sf::Texture tileset; Map() { size = sf::Vector2i( 24, 12 ); for( int y = 0; y <= size.y; y++ ) { for( int x = 0; x <= size.x; x++ ) { terrain_types.push_back( int( 0 ) ); terrain_values.push_back( int( 1 ) ); } } position.x =( view.getSize().x - size.x * 32 ) / 2; position.y =( view.getSize().y - size.y * 32 ) / 2; tileset = sf::Texture(); tileset.loadFromFile( "tex\\set_0.png" ); for( int y = 0; y < size.y; y++ ) { for( int x = 0; x < size.x; x++ ) { std::cout << terrain_values[ y * size.x + x ]; } std::cout << "\n"; } std::cout << "\n"; for( int y = 0; y < size.y; y++ ) { for( int x = 0; x < size.x; x++ ) { int index = getTileIndex( x, y ); sf::Sprite spr = sf::Sprite(); spr.setTexture( tileset ); spr.setTextureRect( sf::IntRect( index * 64, terrain_types[ y * size.x + x ] * 64, 64, 64 ) ); spr.setScale( 0.5f, 0.5f ); spr.setPosition( position.x + x * 32, position.y + y * 32 ); sprites.push_back( spr ); } } } ~Map() { } int getTileIndex( int x, int y ) { return getTileValue( x, y ) |( getTileValue( x + 1, y ) << 1 ) |( getTileValue( x, y + 1 ) << 2 ) |( getTileValue( x + 1, y + 1 ) << 3 ); } int getTileValue( int x, int y ) { return terrain_values[ y * size.x + x ]; } void editTile( int x, int y, int terrain_type, int terrain_value ) { terrain_types[ y * size.x + x ] = terrain_type; terrain_values[ y * size.x + x ] = terrain_value; for( int yy = y - 1; yy <= y + 1; yy++ ) { for( int xx = x - 1; xx <= x + 1; xx++ ) { if( xx >= size.x || yy >= size.y || xx < 0 || yy < 0 ) continue; int index = getTileIndex( xx, yy ); sprites[ yy * size.x + xx ].setTextureRect( sf::IntRect( index * 64, terrain_types[ yy * size.x + xx ] * 64, 64, 64 ) ); } } } void editTile( sf::Vector2f mopusePosition, int terrain_type, int terrain_value ) { int x =( worldMousePosition.x + 16 - position.x ) / 32; int y =( worldMousePosition.y + 16 - position.y ) / 32; terrain_types[ y * size.x + x ] = terrain_type; terrain_values[ y * size.x + x ] = terrain_value; for( int yy = y - 1; yy <= y + 1; yy++ ) { for( int xx = x - 1; xx <= x + 1; xx++ ) { if( xx >= size.x || yy >= size.y || xx < 0 || yy < 0 ) continue; int index = getTileIndex( xx, yy ); sprites[ yy * size.x + xx ].setTextureRect( sf::IntRect( index * 64, terrain_types[ yy * size.x + xx ] * 64, 64, 64 ) ); } } } void draw() { for( auto & tile: sprites ) { window->draw( tile ); } } };
Map * mapa = nullptr;
#endif |
|
tBane Temat założony przez niniejszego użytkownika |
» 2025-07-14 16:09:54 Dodałem kolejny typ terenu. I chyba wszystko jest ok. Ocenicie mój program ? https://github.com/tBane1995/Auto-Tiledhttps://github.com/tBane1995/Auto-Tiled/releases/tag/v0.1ps. Jak wrzucać relese na Github bez tagu ? screenshot z programu: kod mapy:#ifndef map_hpp #define map_hpp
class Map { public: sf::Vector2f position; std::vector < int > terrain_types; std::vector < int > terrain_values; sf::Vector2i size; std::vector < sf::Sprite > sprites; sf::Texture tileset; Map() { size = sf::Vector2i( 24, 12 ); for( int y = 0; y <= size.y; y++ ) { for( int x = 0; x <= size.x; x++ ) { terrain_types.push_back( int( 0 ) ); terrain_values.push_back( int( 1 ) ); } } position.x =( view.getSize().x - size.x * 32 ) / 2; position.y =( view.getSize().y - size.y * 32 ) / 2; tileset = sf::Texture(); tileset.loadFromFile( "tex\\set_0.png" ); for( int y = 0; y < size.y; y++ ) { for( int x = 0; x < size.x; x++ ) { std::cout << terrain_values[ y * size.x + x ]; } std::cout << "\n"; } std::cout << "\n"; for( int y = 0; y < size.y; y++ ) { for( int x = 0; x < size.x; x++ ) { int index = getTileIndex( x, y ); sf::Sprite spr = sf::Sprite(); spr.setTexture( tileset ); spr.setTextureRect( sf::IntRect( index * 64, terrain_types[ y * size.x + x ] * 64, 64, 64 ) ); spr.setScale( 0.5f, 0.5f ); spr.setPosition( position.x + x * 32, position.y + y * 32 ); sprites.push_back( spr ); } } } ~Map() { } int getTileIndex( int x, int y ) { int ttype = terrain_types[ y * size.x + x ]; return getTileValue( x, y, ttype ) |( getTileValue( x + 1, y, ttype ) << 1 ) |( getTileValue( x, y + 1, ttype ) << 2 ) |( getTileValue( x + 1, y + 1, ttype ) << 3 ); } int getTileValue( int x, int y, int terrain_type ) { return( terrain_type == terrain_types[ y * size.x + x ] ) ? terrain_values[ y * size.x + x ] : 0; } void editTile( int x, int y, int terrain_type, int terrain_value ) { terrain_types[ y * size.x + x ] = terrain_type; terrain_values[ y * size.x + x ] = terrain_value; for( int yy = y - 1; yy <= y + 1; yy++ ) { for( int xx = x - 1; xx <= x + 1; xx++ ) { if( xx >= size.x || yy >= size.y || xx < 0 || yy < 0 ) continue; int index = getTileIndex( xx, yy ); sprites[ yy * size.x + xx ].setTextureRect( sf::IntRect( index * 64, terrain_types[ yy * size.x + xx ] * 64, 64, 64 ) ); } } } void editTile( sf::Vector2f mopusePosition, int terrain_type, int terrain_value ) { int x =( worldMousePosition.x + 16 - position.x ) / 32; int y =( worldMousePosition.y + 16 - position.y ) / 32; terrain_types[ y * size.x + x ] = terrain_type; terrain_values[ y * size.x + x ] = terrain_value; for( int yy = y - 1; yy <= y + 1; yy++ ) { for( int xx = x - 1; xx <= x + 1; xx++ ) { if( xx >= size.x || yy >= size.y || xx < 0 || yy < 0 ) continue; int index = getTileIndex( xx, yy ); sprites[ yy * size.x + xx ].setTextureRect( sf::IntRect( index * 64, terrain_types[ yy * size.x + xx ] * 64, 64, 64 ) ); } } } void draw() { for( auto & tile: sprites ) { window->draw( tile ); } } };
Map * mapa = nullptr;
#endif |
|
pekfos |
» 2025-07-14 17:46:00 ps. Jak wrzucać relese na Github bez tagu ? Tag to jest wydanie w systemie kontroli wersji - zamrożona wersja źródeł dla danej wersji. "Release" to dodatek githuba na wierzchu tego. |
|
tBane Temat założony przez niniejszego użytkownika |
» 2025-07-14 18:13:00 Ok. W takim razie nie będe wrzucał releasów chyba :-) A program jak wypadł ? Chyba źle przypisuje zielone kafelki. Zobaczyłbyś na kod ? // editOgólnie da się już tworzyć dobre mapy, ale nadal mam jakiegoś buga. Da sie to oczywiście "zarysować" poprawnie ale czasem coś takiego się trafia.. // edit2Tutaj tekstura jakby co  |
|
pekfos |
» 2025-07-14 22:34:33 Taki zbiór tekstur zakłada że każde sąsiedztwo 2x2 ma maksymalnie 2 różne tereny, a ten przykład raczej tego nie spełnia. |
|
tBane Temat założony przez niniejszego użytkownika |
» 2025-07-14 22:38:03 Mhm.. w takim razie jak dodać kolejny rodzaj terenu?
// edit Najważniejsze to żeby kształt terenu się zgadzał. Kolor stawiam na drugim miejscu.. |
|
1 2 3 4 « 5 » 6 7 8 |