diff --git a/bin/resources/levels/levelTest_buttons.bmp b/bin/resources/levels/levelTest_buttons.bmp new file mode 100644 index 00000000..3cbff757 Binary files /dev/null and b/bin/resources/levels/levelTest_buttons.bmp differ diff --git a/src/lib-tempo/include/tempo/component/ComponentStage.hpp b/src/lib-tempo/include/tempo/component/ComponentStage.hpp index b39cf08e..00678779 100644 --- a/src/lib-tempo/include/tempo/component/ComponentStage.hpp +++ b/src/lib-tempo/include/tempo/component/ComponentStage.hpp @@ -68,6 +68,8 @@ struct ComponentStage ComponentID getId(); }; +void loadButtons(anax::World &world, const char *tile_map); + } // namespace tempo #endif diff --git a/src/lib-tempo/src/component/ComponentStage.cpp b/src/lib-tempo/src/component/ComponentStage.cpp index 9df35047..57c182c1 100644 --- a/src/lib-tempo/src/component/ComponentStage.cpp +++ b/src/lib-tempo/src/component/ComponentStage.cpp @@ -1,17 +1,22 @@ #include +#include #include +#include + #define STB_IMAGE_IMPLEMENTATION #include #include #include #include +#include + +#include namespace tempo { - std::vector _global_stage; std::string _global_stage_loaded("None"); @@ -51,7 +56,7 @@ void ComponentStage::loadLevel(const char *stage_file) } } } - tiles = &_global_stage; + tiles = &_global_stage; _global_stage_loaded = std::string(stage_file); stbi_image_free(pixel_data); @@ -132,4 +137,72 @@ sf::Packet ComponentStage::dumpComponent() return p; } + +void fake_createButtonGroup(anax::World & world, + std::vector positions, + std::vector tiles) +{ + std::cout << "positions = {"; + for (int i = 0; i < positions.size() - 1; i++) { + std::cout << glm::to_string(positions[i]) << ","; + } + std::cout << glm::to_string(positions.back()) << "}" << std::endl; + + std::cout << "tiles = {"; + for (int i = 0; i < tiles.size() - 1; i++) { + std::cout << glm::to_string(tiles[i]) << ","; + } + std::cout << glm::to_string(tiles.back()) << "}" << std::endl; +} + +void loadButtons(anax::World &world, const char *tile_map) +{ + + int width, height, components; + + uint8_t *pixel_data = (uint8_t *) stbi_load(tile_map, &width, &height, &components, 4); + if (pixel_data == NULL || width < 0 || height < 0 || components < 0) { + printf("Failed to load level '%s', pixels: %p, width: %i, height: %i, components: %i\n", + tile_map, pixel_data, width, height, components); + return; + } + + std::vector> buttons(256); + std::vector> walls(256); + + // Load the new tiles + for (int y = 0; y < height; y++) { + int base = width * y * 4; + for (int x = 0; x < width; x++) { + uint8_t *pixel = &pixel_data[base + x * 4]; + + uint8_t r = pixel[0]; + uint8_t g = pixel[1]; + uint8_t b = pixel[2]; + + if (b == 0 && r != 0) { + // this is a button + // r = index + // g = level + buttons[r].push_back(glm::ivec2(y, x)); + } else if (r == 0 && g != 0) { + // this is a wall + // g = index + // b = height + walls[g].push_back(glm::ivec2(y, x)); + } + } + } + stbi_image_free(pixel_data); + + for (int i = 0; i < 256; i++) { + if (buttons[i].empty() || walls[i].empty()) { + continue; + } + + // fake_createButtonGroup(world, buttons[i], walls[i]); + createButtonGroup(world, buttons[i], walls[i]); + } +} + } // namespace tempo diff --git a/src/lib-tempo/src/entity/EntityCreationServer.cpp b/src/lib-tempo/src/entity/EntityCreationServer.cpp index 32dfae4c..168b50df 100644 --- a/src/lib-tempo/src/entity/EntityCreationServer.cpp +++ b/src/lib-tempo/src/entity/EntityCreationServer.cpp @@ -150,7 +150,7 @@ anax::Entity createButtonGroup(anax::World & world, std::vector positions, std::vector tiles) { - printf("Creating button\n"); + // printf("Creating button\n"); anax::Entity entity_button = world.createEntity(); entity_button.addComponent(positions, tiles); entity_button.addComponent("resources/levels/levelTest.bmp"); diff --git a/src/lib-tempo/src/song.cpp b/src/lib-tempo/src/song.cpp index a4027237..2a247f11 100644 --- a/src/lib-tempo/src/song.cpp +++ b/src/lib-tempo/src/song.cpp @@ -10,6 +10,7 @@ Song::Song(std::string path) void Song::start() { + //sound.setLoop(true); sound.play(); } diff --git a/src/server/main.cpp b/src/server/main.cpp index 3fac4d56..84b39d97 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -50,12 +50,12 @@ int main(int argc, const char **argv) anax::World world; // Create Systems - server::SystemAI system_ai; + server::SystemAI system_ai; server::SystemAttack system_attack(world); - server::SystemCombo system_combo; + server::SystemCombo system_combo; server::SystemMovement system_movement; - tempo::SystemHealth system_health; - tempo::SystemTrigger system_trigger(world); + tempo::SystemHealth system_health; + tempo::SystemTrigger system_trigger(world); world.addSystem(system_ai); world.addSystem(system_attack); @@ -66,44 +66,26 @@ int main(int argc, const char **argv) world.refresh(); // Create some Test Entities - + tempo::createMobStill(world, glm::ivec2(36, 42)); tempo::createMobStill(world, glm::ivec2(40, 42)); tempo::createMobStill(world, glm::ivec2(44, 42)); - + tempo::createMobCreeper(world, glm::ivec2(40, 64)); - std::deque path {glm::ivec2(64, 68), - glm::ivec2(64, 72), - glm::ivec2(68, 72), - glm::ivec2(68, 68)}; + std::deque path{glm::ivec2(64, 68), glm::ivec2(64, 72), glm::ivec2(68, 72), + glm::ivec2(68, 68)}; tempo::createMobPatroller(world, path[0], path); - std::deque path2 {glm::ivec2(11, 67), - glm::ivec2(11, 73), - glm::ivec2(15, 73), - glm::ivec2(15, 67)}; + std::deque path2{glm::ivec2(11, 67), glm::ivec2(11, 73), glm::ivec2(15, 73), + glm::ivec2(15, 67)}; tempo::createMobPatroller(world, path2[0], path2); - + // tempo::createMobCreeper(world, glm::ivec2(12, 12)); // tempo::createMobCreeper(world, glm::ivec2(14, 14)); // tempo::createMobAntiSnail(world, glm::ivec2(4, 4)); - std::vector wall = {{37,17},{38,17},{39,17},{40,17},{41,17},{42,17},{43,17},{44,17}, {45,17}}; - tempo::createButtonGroup(world, {{40, 12}}, wall); - - std::vector wall1 = {{37,48},{38,48},{39,48},{40,48},{41,48},{42,48},{43,48},{44,48},}; - tempo::createButtonGroup(world, {{40, 43},{44,43},{36,43}}, wall1); - - std::vector wall2 = {{36,62},{36,63},{36,64},{36,65},{36,66},{36,67},{36,68}, - {50,62},{50,63},{50,64},{50,65},{50,66},{50,67},{50,68}}; - tempo::createButtonGroup(world, {{40, 65}}, wall2); - - std::vector wall3 = {{37,69},{38,69},{39,69},{40,69},{41,69},{42,69},{43,69}}; - tempo::createButtonGroup(world, {{66,70},{13,69}}, wall3); - - std::vector wall4 = {{40,132},{41,132},{42,132}}; - tempo::createButtonGroup(world, {{41,110},{26,128},{57,128}}, wall4); + tempo::loadButtons(world, "resources/levels/levelTest_buttons.bmp"); world.refresh(); @@ -142,8 +124,7 @@ int main(int argc, const char **argv) system_health.broadcastHealth(); } - if (clock.passed_antibeat()) - { + if (clock.passed_antibeat()) { } ////////////////