diff --git a/CMakeLists.txt b/CMakeLists.txt index bc1ae91..6992278 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,10 +38,12 @@ find_package(box2d CONFIG REQUIRED) find_package(nlohmann_json CONFIG REQUIRED) -find_package(TGUI CONFIG REQUIRED) find_package(OpenSSL REQUIRED) +find_package(TGUI CONFIG REQUIRED) + + #Настройка конфигурации if (CMAKE_BUILD_TYPE STREQUAL "Debug") set(TMXLITE_LIB ${TMXLITE_LIB} "libtmxlite-s-d") @@ -58,10 +60,12 @@ file(GLOB_RECURSE SOURCES "src/*.cpp" "include/*.h") # Добавьте источник в исполняемый файл этого проекта. add_executable (Roberto ${SOURCES}) add_executable (tester "tester/main.cpp" "include/SFMLOrthogonalLayer.hpp") +add_executable (ShaderTester "ShaderTest/main.cpp") add_executable (sfmlTest "sfmlTest/main.cpp") add_executable (rostikTest "rostikTest/main.cpp") target_link_libraries(tester PRIVATE sfml-system sfml-network sfml-graphics sfml-window box2d::box2d nlohmann_json::nlohmann_json tgui ${OPENSSL_LIBRARIES} thor ${TMXLITE_LIB}) +target_link_libraries(ShaderTester PRIVATE sfml-system sfml-network sfml-graphics sfml-window) target_link_libraries(sfmlTest PRIVATE sfml-system sfml-network sfml-graphics sfml-window box2d::box2d nlohmann_json::nlohmann_json tgui ${OPENSSL_LIBRARIES}) target_link_libraries(Roberto PRIVATE sfml-system sfml-network sfml-graphics sfml-window box2d::box2d nlohmann_json::nlohmann_json tgui ${OPENSSL_LIBRARIES} thor ${TMXLITE_LIB}) target_link_libraries(rostikTest PRIVATE sfml-system sfml-network sfml-graphics sfml-window box2d::box2d nlohmann_json::nlohmann_json tgui ${OPENSSL_LIBRARIES} thor ${TMXLITE_LIB}) diff --git a/Resources/maps/testMap.tmx b/Resources/maps/testMap.tmx index acbdef9..33103cd 100644 --- a/Resources/maps/testMap.tmx +++ b/Resources/maps/testMap.tmx @@ -46,22 +46,22 @@ 91,92,93,94,5,103,97,105,9,101,108,3,4,105,83,7,8,86,1,88,89,90,91,92,93,94,95,96,97,98,99,91,92,93,94,95,96,97,100,101,102,103,104,105,106,107,108,443,444,445,446,447,454,455,456,454,458,456,473,439,449,455,456,467,458,439,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 100,101,102,103,14,15,16,17,108,10,11,12,13,114,115,93,17,18,10,97,138,15,100,101,102,103,104,105,106,107,108,100,101,102,103,104,105,106,109,110,111,112,113,114,115,116,117,452,453,454,455,462,457,445,446,436,428,455,456,462,449,448,445,458,0,0,449,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 19,20,111,22,120,24,115,123,27,19,20,21,22,123,124,102,26,27,105,22,147,24,109,110,111,112,113,114,115,82,83,84,85,86,87,88,89,90,118,119,120,121,122,123,124,125,126,461,462,463,464,465,466,454,455,436,454,428,439,449,458,439,454,455,456,0,458,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -28,29,30,31,32,130,124,35,133,28,129,30,31,32,33,34,112,36,30,31,32,31,118,119,120,121,122,123,124,91,92,93,94,95,96,97,98,99,127,128,129,130,131,132,133,134,135,470,471,472,473,474,462,476,464,445,436,456,445,449,473,462,449,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -37,38,39,40,41,42,43,44,45,37,38,39,40,41,42,43,121,45,37,40,41,126,127,128,129,130,131,132,133,100,101,102,103,104,105,106,107,108,88,89,90,139,140,141,142,143,144,298,470,471,472,473,474,475,462,454,455,456,454,458,449,475,458,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -46,47,48,49,50,51,52,53,54,46,47,48,49,50,51,52,130,54,132,47,134,49,136,137,138,139,140,141,142,109,110,111,112,113,114,115,116,117,97,98,99,148,149,150,151,152,153,307,476,518,519,520,535,536,462,538,454,455,456,530,458,458,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -55,56,57,58,59,60,61,62,63,55,56,57,58,59,60,61,62,63,55,56,57,58,145,146,147,148,149,150,151,118,119,120,121,122,123,124,125,126,106,107,108,157,158,159,160,161,162,316,524,527,528,529,544,545,546,462,462,537,464,539,540,541,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -64,65,66,67,68,69,70,71,72,64,65,66,67,68,69,70,71,72,64,65,66,67,154,155,156,157,158,159,160,127,128,129,130,131,132,133,134,135,115,116,117,265,266,267,508,265,510,511,508,536,510,538,553,513,555,556,557,546,473,548,549,550,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -73,74,75,76,77,78,79,80,81,73,74,75,76,77,78,79,80,81,73,74,75,76,77,78,79,80,81,73,74,136,137,138,139,140,141,142,143,144,124,125,126,274,265,266,267,274,519,520,521,522,519,520,562,563,564,565,566,555,556,557,558,559,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,145,146,147,148,149,150,151,152,153,133,134,135,283,274,525,526,527,284,525,430,430,431,0,530,531,424,0,510,0,0,513,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -10,11,12,13,14,15,16,17,18,10,11,12,13,14,15,16,17,18,10,11,12,13,14,15,16,17,18,10,11,154,155,156,157,158,159,160,161,162,142,143,144,292,283,284,285,436,436,538,427,540,541,0,0,432,0,0,519,520,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -19,20,21,22,23,24,25,26,27,19,20,21,22,23,24,25,26,27,19,20,21,22,23,24,25,26,27,19,20,21,22,23,145,146,147,148,149,150,151,152,153,100,292,293,294,104,546,547,448,448,450,450,431,525,0,527,0,0,530,531,532,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -28,29,30,31,32,33,34,35,36,28,29,30,31,32,33,34,35,36,28,29,30,31,32,33,34,35,36,28,29,30,31,32,154,155,156,157,158,159,160,161,162,109,551,425,112,427,455,455,436,0,432,0,449,450,0,0,537,0,0,540,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -37,38,39,40,41,42,43,44,45,37,38,39,40,41,42,43,44,45,37,38,39,40,41,42,43,44,45,37,38,39,40,41,42,43,44,45,118,119,21,121,122,118,119,120,462,462,437,0,466,466,456,448,0,450,0,0,0,547,548,549,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -46,47,48,49,50,51,52,53,54,46,47,48,49,50,51,52,53,54,46,47,48,49,50,51,52,53,54,46,47,48,49,50,51,52,53,54,127,128,129,30,131,32,128,129,130,131,0,0,0,455,450,0,467,468,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -55,56,57,58,59,60,61,62,63,55,56,57,58,59,60,61,62,63,55,56,57,58,59,60,61,62,63,16,56,57,58,59,16,61,62,63,136,5,138,139,140,136,137,138,139,454,0,462,0,473,0,466,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +28,29,30,31,32,130,124,35,133,28,129,30,31,32,33,34,112,36,30,31,32,31,118,119,120,121,122,123,124,91,92,93,94,95,96,97,98,99,127,128,129,130,131,132,133,134,135,470,471,472,82,474,15,476,464,445,436,89,445,449,473,462,449,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +37,38,39,40,41,42,43,44,45,37,38,39,40,41,42,43,121,45,37,40,41,126,127,128,129,130,131,132,133,100,101,102,103,104,105,106,107,108,88,89,90,139,140,141,142,143,144,298,470,21,91,473,474,94,407,454,455,456,454,458,449,475,458,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +46,47,48,49,50,51,52,53,54,46,47,48,49,50,51,52,130,54,132,47,134,49,136,137,138,139,140,141,142,109,110,111,112,113,114,115,116,117,97,98,99,148,149,418,419,152,153,255,260,418,258,259,33,261,462,84,454,102,420,421,422,458,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +55,56,57,58,59,60,61,62,63,55,56,57,58,59,60,61,62,63,55,56,57,58,145,146,147,148,149,150,151,118,119,120,121,122,123,124,125,126,106,107,108,157,426,264,160,266,162,268,346,433,40,349,269,112,113,114,462,418,429,430,431,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +64,65,66,67,68,69,70,71,72,64,65,66,67,68,69,70,71,72,64,65,66,67,154,155,156,157,158,159,160,127,128,129,130,131,132,133,134,135,115,116,117,265,435,267,274,275,276,22,274,421,418,119,278,121,122,435,409,120,438,439,440,414,415,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +73,74,75,76,77,78,79,80,81,73,74,75,76,77,78,79,80,81,73,74,75,76,77,78,79,80,81,73,74,136,137,138,139,140,141,142,143,144,124,125,126,274,444,266,283,284,285,428,283,430,431,128,129,130,131,132,128,134,420,448,449,423,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,145,146,147,148,149,150,151,152,153,133,134,135,417,339,419,418,293,294,437,430,293,294,0,418,378,424,0,419,0,0,422,431,432,433,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,11,12,13,14,15,16,17,18,10,11,12,13,14,15,16,17,18,10,11,12,13,14,15,16,17,18,10,11,154,155,156,157,158,159,160,161,162,142,143,346,292,283,349,429,436,445,432,382,51,384,385,147,432,0,0,436,464,0,0,440,441,442,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +19,20,21,22,23,24,25,26,27,19,20,21,22,23,24,25,26,27,19,20,21,22,23,24,25,26,27,19,20,21,22,23,145,146,147,148,149,150,151,152,153,100,292,293,438,104,440,441,448,457,450,450,431,157,435,84,445,446,439,419,476,0,451,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +28,29,30,31,32,33,34,35,36,28,29,30,31,32,33,34,35,36,28,29,30,31,32,33,34,35,36,28,29,30,31,32,154,155,156,157,158,159,160,161,364,109,366,425,112,427,455,455,436,0,432,0,449,450,0,0,446,447,268,269,0,430,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +37,38,39,40,41,42,43,44,45,37,38,39,40,41,42,43,44,45,37,38,39,40,41,42,43,44,45,37,38,39,40,41,42,43,44,45,118,119,21,121,122,118,119,120,462,378,437,0,466,466,456,448,0,450,461,274,463,276,421,278,467,468,469,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +46,47,48,49,50,51,52,53,54,46,47,48,49,50,51,52,53,54,46,47,48,49,50,51,52,53,54,46,47,48,49,50,51,52,53,54,127,128,129,30,382,32,384,385,130,131,0,0,0,455,450,0,467,468,0,0,0,0,0,287,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +55,56,57,58,59,60,61,62,63,55,56,57,58,59,60,61,62,63,55,56,57,58,59,60,61,62,63,16,56,57,58,59,16,61,62,63,136,5,138,139,140,136,137,138,139,454,0,462,0,473,0,466,0,0,0,436,481,482,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 64,65,66,67,68,69,70,71,72,64,65,5,67,68,69,70,71,12,13,65,66,67,2,18,22,23,24,64,65,22,23,24,69,70,71,72,13,146,15,148,49,425,146,427,148,149,464,0,432,467,468,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -73,12,75,76,15,78,79,18,81,73,74,75,76,16,78,79,80,21,22,74,24,76,29,30,31,32,33,29,30,31,32,33,34,79,80,81,21,155,24,157,58,154,155,156,437,158,473,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,22,0,24,25,26,19,0,0,0,0,0,25,0,0,0,30,31,32,0,0,38,39,40,0,24,25,39,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,449,450,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +73,12,75,76,15,78,79,18,81,73,74,75,76,16,78,79,80,21,22,74,24,76,29,30,31,32,33,29,30,31,32,33,34,79,80,81,21,155,24,157,58,154,155,156,437,158,473,0,0,0,0,0,0,0,0,0,0,312,457,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,22,0,24,25,26,19,0,0,0,0,0,25,0,0,0,30,31,32,0,0,38,39,40,0,24,25,39,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,449,450,0,0,0,0,0,0,0,0,321,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,30,31,32,0,0,0,0,0,0,31,0,0,0,35,36,0,39,40,41,42,0,29,0,49,50,0,34,35,49,50,0,0,0,0,0,40,41,0,0,0,0,0,454,0,456,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,40,41,0,43,44,0,0,0,0,0,0,0,44,45,0,48,49,0,51,0,0,0,58,41,0,43,44,58,59,0,0,62,47,48,0,0,0,0,53,0,0,0,464,0,0,467,468,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 47,0,0,50,0,0,53,0,0,0,0,50,51,0,53,54,0,0,0,0,0,46,0,0,0,50,0,52,53,0,0,0,70,16,56,57,0,0,0,61,0,0,0,0,473,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -215,7 +215,7 @@ 290,291,292,293,294,295,296,297,298,290,291,292,293,294,12,0,0,0,49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,534,535,157,0,538,539,0,479,480,481,482,483,484,485,486,487 - + @@ -259,12 +259,12 @@ - + - + diff --git a/Resources/shaders/ExplosionSharer.frag b/Resources/shaders/ExplosionSharer.frag new file mode 100644 index 0000000..cbdf0d3 --- /dev/null +++ b/Resources/shaders/ExplosionSharer.frag @@ -0,0 +1,281 @@ +// "Volumetric explosion" by Duke +// https://www.shadertoy.com/view/lsySzd +//------------------------------------------------------------------------------------- +// Based on "Supernova remnant" (https://www.shadertoy.com/view/MdKXzc) +// and other previous shaders +// otaviogood's "Alien Beacon" (https://www.shadertoy.com/view/ld2SzK) +// and Shane's "Cheap Cloud Flythrough" (https://www.shadertoy.com/view/Xsc3R4) shaders +// Some ideas came from other shaders from this wonderful site +// Press 1-2-3 to zoom in and zoom out. +// License: Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License +//------------------------------------------------------------------------------------- + +// comment this string to see each part in full screen +#define BOTH +// uncomment this string to see left part +//#define LEFT + +//#define LOW_QUALITY + +#define DITHERING + +//#define TONEMAPPING + +//------------------- +#define pi 3.14159265 +#define R(p, a) p=cos(a)*p+sin(a)*vec2(p.y, -p.x) + +// iq's noise +float noise( in vec3 x ) +{ + vec3 p = floor(x); + vec3 f = fract(x); + f = f*f*(3.0-2.0*f); + vec2 uv = (p.xy+vec2(37.0,17.0)*p.z) + f.xy; + vec2 rg = textureLod( iChannel0, (uv+ 0.5)/256.0, 0.0 ).yx; + return 1. - 0.82*mix( rg.x, rg.y, f.z ); +} + +float fbm( vec3 p ) +{ + return noise(p*.06125)*.5 + noise(p*.125)*.25 + noise(p*.25)*.125 + noise(p*.4)*.2; +} + +float Sphere( vec3 p, float r ) +{ + return length(p)-r; +} + +//============================================================== +// otaviogood's noise from https://www.shadertoy.com/view/ld2SzK +//-------------------------------------------------------------- +// This spiral noise works by successively adding and rotating sin waves while increasing frequency. +// It should work the same on all computers since it's not based on a hash function like some other noises. +// It can be much faster than other noise functions if you're ok with some repetition. +const float nudge = 4.; // size of perpendicular vector +float normalizer = 1.0 / sqrt(1.0 + nudge*nudge); // pythagorean theorem on that perpendicular to maintain scale +float SpiralNoiseC(vec3 p) +{ + float n = -mod(iTime * 0.2,-2.); // noise amount + float iter = 2.0; + for (int i = 0; i < 8; i++) + { + // add sin and cos scaled inverse with the frequency + n += -abs(sin(p.y*iter) + cos(p.x*iter)) / iter; // abs for a ridged look + // rotate by adding perpendicular and scaling down + p.xy += vec2(p.y, -p.x) * nudge; + p.xy *= normalizer; + // rotate on other axis + p.xz += vec2(p.z, -p.x) * nudge; + p.xz *= normalizer; + // increase the frequency + iter *= 1.733733; + } + return n; +} + +float VolumetricExplosion(vec3 p) +{ + float final = Sphere(p,4.); + #ifdef LOW_QUALITY + final += noise(p*12.5)*.2; + #else + final += fbm(p*50.); + #endif + final += SpiralNoiseC(p.zxy*0.4132+333.)*3.0; //1.25; + + return final; +} + +float map(vec3 p) +{ + R(p.xz, iMouse.x*0.008*pi+iTime*0.1); + + float VolExplosion = VolumetricExplosion(p/0.5)*0.5; // scale + + return VolExplosion; +} +//-------------------------------------------------------------- + +// assign color to the media +vec3 computeColor( float density, float radius ) +{ + // color based on density alone, gives impression of occlusion within + // the media + vec3 result = mix( vec3(1.0,0.9,0.8), vec3(0.4,0.15,0.1), density ); + + // color added to the media + vec3 colCenter = 7.*vec3(0.8,1.0,1.0); + vec3 colEdge = 1.5*vec3(0.48,0.53,0.5); + result *= mix( colCenter, colEdge, min( (radius+.05)/.9, 1.15 ) ); + + return result; +} + +bool RaySphereIntersect(vec3 org, vec3 dir, out float near, out float far) +{ + float b = dot(dir, org); + float c = dot(org, org) - 8.; + float delta = b*b - c; + if( delta < 0.0) + return false; + float deltasqrt = sqrt(delta); + near = -b - deltasqrt; + far = -b + deltasqrt; + return far > 0.0; +} + +// Applies the filmic curve from John Hable's presentation +// More details at : http://filmicgames.com/archives/75 +vec3 ToneMapFilmicALU(vec3 _color) +{ + _color = max(vec3(0), _color - vec3(0.004)); + _color = (_color * (6.2*_color + vec3(0.5))) / (_color * (6.2 * _color + vec3(1.7)) + vec3(0.06)); + return _color; +} + +void mainImage( out vec4 fragColor, in vec2 fragCoord ) +{ + const float KEY_1 = 49.5/256.0; + const float KEY_2 = 50.5/256.0; + const float KEY_3 = 51.5/256.0; + float key = 0.0; + key += 0.7*texture(iChannel1, vec2(KEY_1,0.25)).x; + key += 0.7*texture(iChannel1, vec2(KEY_2,0.25)).x; + key += 0.7*texture(iChannel1, vec2(KEY_3,0.25)).x; + + vec2 uv = fragCoord/iResolution.xy; + + // ro: ray origin + // rd: direction of the ray + vec3 rd = normalize(vec3((fragCoord.xy-0.5*iResolution.xy)/iResolution.y, 1.)); + vec3 ro = vec3(0., 0., -6.+key*1.6); + + // ld, td: local, total density + // w: weighting factor + float ld=0., td=0., w=0.; + + // t: length of the ray + // d: distance function + float d=1., t=0.; + + const float h = 0.1; + + vec4 sum = vec4(0.0); + + float min_dist=0.0, max_dist=0.0; + + if(RaySphereIntersect(ro, rd, min_dist, max_dist)) + { + + t = min_dist*step(t,min_dist); + + // raymarch loop + #ifdef LOW_QUALITY + for (int i=0; i<56; i++) + #else + for (int i=0; i<86; i++) + #endif + { + + vec3 pos = ro + t*rd; + + // Loop break conditions. + if(td>0.9 || d<0.12*t || t>10. || sum.a > 0.99 || t>max_dist) break; + + // evaluate distance function + float d = map(pos); + + #ifdef BOTH + /* + if (uv.x<0.5) + { + d = abs(d)+0.07; + } + */ + //split screen variant + //d = uv.x < 0.5 ? abs(d)+0.07 : d; + + d = cos(iTime)*uv.x < 0.1 ? abs(d)+0.07 : d; + #else + #ifdef LEFT + d = abs(d)+0.07; + #endif + #endif + + // change this string to control density + d = max(d,0.03); + + // point light calculations + vec3 ldst = vec3(0.0)-pos; + float lDist = max(length(ldst), 0.001); + + // the color of light + vec3 lightColor=vec3(1.0,0.5,0.25); + + sum.rgb+=(lightColor/exp(lDist*lDist*lDist*.08)/30.); // bloom + + if (d + +int main() +{ + sf::RenderWindow window(sf::VideoMode(1280, 728), "Shader"); + window.setFramerateLimit(60); + sf::Vector2f size(1280, 728); + sf::Texture whiteTexture; + whiteTexture.create(size.x, size.y); + + // + sf::Image image; + image.create(size.x, size.y, sf::Color::White); + whiteTexture.update(image); + + sf::Sprite sprite; + sprite.setTexture(whiteTexture); + + sf::Shader shader; + if (!shader.loadFromFile("Resources/shaders/text.frag", sf::Shader::Fragment)) { + return 1; + } + //shader.setUniform("resolution", sf::Vector2f(window.getSize())); + + shader.setUniform("resolution", sf::Vector2f(1280, 728)); + + //shader.setUniform("surfacePosition", sf::Vector2f(640, 480)); + sf::Vector2f worldPosition; + float animationTime = 0.0f; + sf::Clock clock; + + while (window.isOpen()) { + sf::Event event; + while (window.pollEvent(event)) { + + if (event.type == sf::Event::Closed) { + window.close(); + } + sf::Vector2i mousePosition = sf::Mouse::getPosition(window); + // view + worldPosition = window.mapPixelToCoords(mousePosition); + } + //window.clear(sf::Color::White); + // + animationTime += clock.restart().asSeconds(); + if (animationTime > 9999.0f) { + animationTime = 0.0f; // + } + //shader.setUniform("resolution", worldPosition); + shader.setUniform("time", animationTime); // + + window.draw(sprite, &shader); + // + window.display(); + } + + return 0; +} diff --git a/include/Ammo.h b/include/Ammo.h index 1834179..bc9cc7b 100644 --- a/include/Ammo.h +++ b/include/Ammo.h @@ -68,6 +68,8 @@ class Ammo const Ammo& operator+(const long& other); const Ammo& operator-(const long& other); + + void operator+=(Ammo& other); diff --git a/include/Ammo/AmmoGrenadeLauncher.h b/include/Ammo/AmmoGrenadeLauncher.h index 02f4138..59206ac 100644 --- a/include/Ammo/AmmoGrenadeLauncher.h +++ b/include/Ammo/AmmoGrenadeLauncher.h @@ -1,12 +1,13 @@ + #pragma once -//#include "Entity.h" #include "Ammo.h" +#include "DynamicProjectile.h" -class AmmoGrenadeLauncher:public Ammo +class GrenadeLauncherProjectaile:public DynamicProjectile { public: - AmmoGrenadeLauncher(); - ~AmmoGrenadeLauncher(); + GrenadeLauncherProjectaile(); + ~GrenadeLauncherProjectaile(); private: diff --git a/include/Camera.h b/include/Camera.h index faae0c1..7d1b12d 100644 --- a/include/Camera.h +++ b/include/Camera.h @@ -2,40 +2,18 @@ #include #include #include "GameObject.h" -// HUD -class HeadsUpDisplay -{ - -public: - sf::Font font; - sf::Text fpsText; - HeadsUpDisplay() - { - if (!font.loadFromFile("Resources/fonts/impact.ttf")) - { - std::cout << "Error load font!" << std::endl; - } - fpsText.setFont(font); - fpsText.setString(L" --------------------------------------------------------------------------------------------"); - fpsText.setCharacterSize(24); - fpsText.setFillColor(sf::Color::Green); - fpsText.setPosition(1000, 1000); - - } - void draw(sf::RenderWindow& window) - { - - window.draw(fpsText); - } -}; + class Camera : public sf::View { float moveSpeed; float zoomSpeed; float targetZoom; GameObject* trackingObject; - HeadsUpDisplay headsUpDisplay; sf::RectangleShape blind; + + + void updateHUD(const float& dts, sf::RenderWindow& window); + public: Camera(); @@ -43,6 +21,8 @@ class Camera : public sf::View void update(const sf::Time& deltaTime, sf::RenderWindow& window); + void draw(sf::RenderWindow& window); + void setMoveSpeed(const float& speed); const float& getMoveSpeed(); diff --git a/include/DynamicProjectile.h b/include/DynamicProjectile.h index 7b9637e..99e7f04 100644 --- a/include/DynamicProjectile.h +++ b/include/DynamicProjectile.h @@ -1 +1,92 @@ -#pragma once \ No newline at end of file +#pragma once +#include "Ammo.h" +#include "GameObject.h" +#include "GlobalConsts.h" +#include +class MyQueryCallback : public b2QueryCallback { +public: + bool ReportFixture(b2Fixture* fixture) override { + // , , + bodiesInRange.push_back(fixture->GetBody()); + return true; // true, + } + + std::vector bodiesInRange; // +}; +class DynamicProjectile : public Ammo, public GameObject +{ +public: + DynamicProjectile(); + DynamicProjectile(const AmmoType& ammoType); + GameObjectData gameObjectData; + #pragma region Body + b2BodyDef bodyDef; + b2Body* body; + b2Fixture* fixture; + b2PolygonShape bodyShape; + + void initBody(b2World* world, const sf::Vector2f& pos, const float& angle = 0.f, const b2BodyType& bodyType = b2_dynamicBody); + + void setBodyOvalShape(const float& radius_x, const float& radius_y, const int num_segments = 8, const float& density = 1.f); + + void setBodyBoxShape(const sf::Vector2f& size, const float& density = 1.f); + + void setBodyPolygonShape(const b2Vec2* vertices, const int num_segments = 4); + + void update(const sf::Time& deltaTime, std::vector& gameObjects, TextureManager& textureManager, b2World& world); + + void applyResistance(); + + void draw(sf::RenderWindow& window); + + void setBodyPosition(const sf::Vector2f& vec); + + void setBodyPosition(const b2Vec2& vec); + #pragma endregion + + void setExplodes(const bool& explodes); + const bool& isExplodes(); + + void setExplosionRadius(const float& explosionRadius); + const float& getExplosionRadius(); + + void setExplosionPulse(const float& explosionPulse); + const float& getExplosionPulse(); + + void destroy(b2World& world, std::vector& gameObjects); +private: + /// + /// hitBox + /// + sf::Shape* hitBox; + + /// + /// ( ) + /// + sf::Vector2f targetCoordinates; + + /// + /// , + /// + GameObject* whoShot; + + /// + /// ? + /// + bool explodes; + + /// + /// + /// + float explosionRadius; + + /// + /// + /// + float explosionPulse; + + /// + /// = + /// + float resistanceCoefficient; +}; \ No newline at end of file diff --git a/include/Entity.h b/include/Entity.h index 33c2f6c..8e2a0bf 100644 --- a/include/Entity.h +++ b/include/Entity.h @@ -1,7 +1,7 @@ #pragma once //Entity.h #include -#include + #include "GlobalConsts.h" #include "GameObject.h" #include "GameObjectData.h" @@ -31,10 +31,6 @@ class Entity : public GameObject /// /// int selectedAmmoIndex; - - - - GameObjectData gameObjectData; Entity(); @@ -52,22 +48,26 @@ class Entity : public GameObject void setTargetCoordinates(const sf::Vector2f& targetCoordinates); - virtual void update(const sf::Time& deltaTime, std::vector& gameObjects, TextureManager& textureManager); + virtual void update(const sf::Time& deltaTime, std::vector& gameObjects, TextureManager& textureManager, b2World& world); void draw(sf::RenderWindow& window) override; void setPhysicalProperties(const float& density, const float& friction, const float& restitution); - void applyResistance(const float& deltaTime); - void setResistanceCoefficient(const float& resistanceCoefficient); + void setHealthPoints(const float& healthPoints); + void setMaxHealthPoints(const float& maxHealthPoints); + + void setMaxVelocity(const float& maxVelocity); + void setHittedFlag(const bool& hitted); const float& getResistanceCoefficient(); const float& getHealthPoints(); const float& getMaxHealthPoints(); + const float& getMaxVelocity(); const sf::Vector2f& getTargetCoordinates(); const bool& isHitted(); @@ -86,6 +86,12 @@ class Entity : public GameObject bool hitted; + + /// + /// + /// + float maxVelocity; + /// /// hitBox /// diff --git a/include/Game.h b/include/Game.h index fafd9f8..c1c881d 100644 --- a/include/Game.h +++ b/include/Game.h @@ -8,6 +8,8 @@ #include "Level.h" #include "TextureManager.h" #include "GlobalConsts.h" +#include +#include /// /// @@ -16,7 +18,7 @@ class CollisionHandler { public: // void handleCollision(GameObject* gameObject, std::set& contactedBodies, b2World& world, std::vector& gameObjects, TextureManager& textureManager); - void processContactEdge(Entity* entityA, b2ContactEdge* contactEdge, std::set& contactedBodies, std::set& objectsToRemove, b2World& world, TextureManager& textureManager); + void processContactEdge(GameObject* objectA, b2ContactEdge* contactEdge, std::set& contactedBodies, std::set& objectsToRemove, b2World& world, TextureManager& textureManager); void removeObjects(std::vector& gameObjects, std::set& objectsToRemove, b2World& world); }; diff --git a/include/GameObject.h b/include/GameObject.h index d2c6f88..bb2a97c 100644 --- a/include/GameObject.h +++ b/include/GameObject.h @@ -2,7 +2,9 @@ #include #include #include "TextureManager.h" - +#include "GameObjectData.h" +#include "HeadUpDisplay.h" +#include /// /// /// @@ -12,13 +14,14 @@ class GameObject : public sf::Sprite GameObject(); - virtual void update(const sf::Time& deltaTime, std::vector& gameObjects, TextureManager& textureManager) = 0; + virtual void update(const sf::Time& deltaTime, std::vector& gameObjects, TextureManager& textureManager, b2World& world) = 0; virtual void draw(sf::RenderWindow& window) = 0; void setPhysicalObjectFlag(const bool& physicalObjectFlag); void setHitboxFlag(const bool& hitboxFlag); const bool& getHitboxFlag(); const bool& getPhysicalObjectFlag(); - + GameObjectData gameObjectData; + HUD::HeadUpDisplay headUpDisplay; private: /// diff --git a/include/GameObjectData.h b/include/GameObjectData.h index ab2ed94..f2eb3fa 100644 --- a/include/GameObjectData.h +++ b/include/GameObjectData.h @@ -10,6 +10,7 @@ enum ObjectType { PepsiType, ObjectWeaponType, ObjectAmmoType, + DynamicProjectileType }; enum AmmoType { @@ -36,6 +37,8 @@ class GameObjectData /// ObjectType objectType; public: + GameObjectData(); + GameObjectData(const ObjectType& objectType); void setGameObjectType(const ObjectType& objectType); const ObjectType& getGameObjectType(); }; \ No newline at end of file diff --git a/include/GlobalConsts.h b/include/GlobalConsts.h index b6683d9..59afe46 100644 --- a/include/GlobalConsts.h +++ b/include/GlobalConsts.h @@ -1,4 +1,5 @@ #pragma once +#include "SFML/Graphics.hpp" // ANSI #define ANSI_COLOR_RED "\x1b[31m" #define ANSI_COLOR_GREEN "\x1b[32m" @@ -12,4 +13,5 @@ class GlobalConsts public: static const float SCALE; static bool hitBoxOn; + static sf::Font font; }; diff --git a/include/Gui.h b/include/Gui.h index d2948e8..eb32b06 100644 --- a/include/Gui.h +++ b/include/Gui.h @@ -34,10 +34,10 @@ class GUI void GameMenu(const bool& flag); void MainMenu(const bool& flag); void TestsMenu(int& test); - void GameMenuInit(tgui::Gui& gui); - void MainMenuInit(tgui::Gui& gui); - void SettingsMenuInit(tgui::Gui& gui); - void TestMenuInit(tgui::Gui& gui); + void GameMenuInit(auto& gui); + void MainMenuInit(auto& gui); + void SettingsMenuInit(auto& gui); + void TestMenuInit(auto& gui); Flags flags; tgui::Group::Ptr mainMenuWindow; tgui::Group::Ptr gameMenuWindow; diff --git a/include/HeadUpDisplay.h b/include/HeadUpDisplay.h new file mode 100644 index 0000000..2cc71c5 --- /dev/null +++ b/include/HeadUpDisplay.h @@ -0,0 +1,41 @@ +//HeadUpDisplay.h +#pragma once + +#include +#include +#include +namespace HUD +{ + enum HUDType + { + FpsType, + HealthPointType, + AmmoType, + }; + struct Label + { + HUDType type; + sf::Text text; + /// + /// 0 2 + /// + sf::Vector2f positionCoefficient; + }; + class HeadUpDisplay + { + + public: + std::vector Ammo ammoMagazine; + /// + /// + /// + float angle; /// /// ( ammoPulse) @@ -59,6 +66,11 @@ class Weapon : public sf::Sprite /// bool reloading; + /// + /// + /// + bool cooldowning; + public: Weapon(); @@ -76,9 +88,9 @@ class Weapon : public sf::Sprite ); - virtual void shot(std::vector& gameObjects, TextureManager& textureManager); + virtual const bool& shot(std::vector& gameObjects, TextureManager& textureManager, GameObject* whoShot, b2World& world); - void update(const float& angle); + void update(const float& dts,const float& angle, Ammo& ammo); const WeaponType& getWeaponType(); void setWeaponType(const WeaponType& weaponType); @@ -101,12 +113,18 @@ class Weapon : public sf::Sprite const float& getAccuracy(); void setAccuracy(const float& accuracy); + const float& getAngle(); + void setAngle(const float& angle); + const bool& isAvable(); void setAvable(const bool& avable); const bool& isReloading(); void setReload(const bool& reloading); + const bool& isCooldowning(); + void setCooldowning(const bool& cooldowning); + GameObject* getTrakingObject(); void setTrakingObject(GameObject* trakingObject); diff --git a/include/Weapons/GrenadeLauncher.h b/include/Weapons/GrenadeLauncher.h index e6f974c..4606757 100644 --- a/include/Weapons/GrenadeLauncher.h +++ b/include/Weapons/GrenadeLauncher.h @@ -8,7 +8,7 @@ class GrenadeLauncher: public Weapon { public: GrenadeLauncher(); - void shot(std::vector& gameObjects, TextureManager& textureManager) override; + const bool& shot(std::vector& gameObjects, TextureManager& textureManager, GameObject* whoShot, b2World& world) override; private: }; \ No newline at end of file diff --git a/include/Window.h b/include/Window.h index 85d4ad9..8f025be 100644 --- a/include/Window.h +++ b/include/Window.h @@ -1,5 +1,5 @@ #pragma once -#define buildVersion "Alpha V(0.0.4)" +#define buildVersion "Alpha V(0.0.5)" #include @@ -12,12 +12,12 @@ #include "Settings.h" #include "GUI.h" #include "Game.h" - +#include class MainWindow { private: sf::RenderWindow window; - tgui::GuiSFML gui; + tgui:: gui; GUI guiManager; FeatureTester test; Game game; diff --git a/modules/tmxlite/lib/libtmxlite-s-d.lib b/modules/tmxlite/lib/libtmxlite-s-d.lib index 4da7681..206f2be 100644 Binary files a/modules/tmxlite/lib/libtmxlite-s-d.lib and b/modules/tmxlite/lib/libtmxlite-s-d.lib differ diff --git a/modules/tmxlite/lib/libtmxlite-s.lib b/modules/tmxlite/lib/libtmxlite-s.lib index e5face8..9f09c85 100644 Binary files a/modules/tmxlite/lib/libtmxlite-s.lib and b/modules/tmxlite/lib/libtmxlite-s.lib differ diff --git a/oldout.zip b/oldout.zip new file mode 100644 index 0000000..cb098e1 Binary files /dev/null and b/oldout.zip differ diff --git a/src/Ammo.cpp b/src/Ammo.cpp index 8d72f45..a294ade 100644 --- a/src/Ammo.cpp +++ b/src/Ammo.cpp @@ -36,7 +36,7 @@ Ammo::Ammo(const AmmoType& ammoType, const bool& isEntyty) { case AmmoType::AGrenadeLauncherType: - *this = Ammo(ammoType,0,isEntyty?9:1, 65.f, 5.f, 20); + *this = Ammo(ammoType,0,isEntyty?30:4, 65.f, 2.5f, 20); break; case AmmoType::AVoidType: *this = Ammo(ammoType, 0, 0, 0, 0, 0); @@ -174,6 +174,7 @@ const Ammo& Ammo::operator-(const long& other) newOther = 0 - result; result += newOther; } + this->amountOfAmmo = result; return Ammo(this->ammoType, result, maximumAmmo, this->damage, this->lifeTime, this->ammoPulse); } diff --git a/src/Ammo/AmmoGrenadeLauncher.cpp b/src/Ammo/AmmoGrenadeLauncher.cpp index 86de08a..c9841ff 100644 --- a/src/Ammo/AmmoGrenadeLauncher.cpp +++ b/src/Ammo/AmmoGrenadeLauncher.cpp @@ -1,11 +1,11 @@ #include "Ammo/AmmoGrenadeLauncher.h" -AmmoGrenadeLauncher::AmmoGrenadeLauncher() - :Ammo(AmmoType::AGrenadeLauncherType) +GrenadeLauncherProjectaile::GrenadeLauncherProjectaile() + :DynamicProjectile(AmmoType::AGrenadeLauncherType) { } -AmmoGrenadeLauncher::~AmmoGrenadeLauncher() +GrenadeLauncherProjectaile::~GrenadeLauncherProjectaile() { } \ No newline at end of file diff --git a/src/Camera.cpp b/src/Camera.cpp index 56e92f8..5bf5365 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -1,12 +1,23 @@ #include "Camera.h" -Camera::Camera(): +void Camera::updateHUD(const float& dts, sf::RenderWindow& window) +{ + if (trackingObject != nullptr) + { + std::vector& labels = trackingObject->headUpDisplay.labels; + for (auto& label : labels) + { + label.text.setPosition(getCenter().x + window.getSize().x / label.positionCoefficient.x, getCenter().y - window.getSize().y / label.positionCoefficient.y); + } + } +} + +Camera::Camera(): View(), trackingObject(nullptr), moveSpeed(2.f), zoomSpeed(2.5f), - targetZoom(1.4f), - headsUpDisplay() + targetZoom(1.4f) { } @@ -19,7 +30,6 @@ void Camera::setTracking(GameObject* trackingObject) void Camera::update(const sf::Time& deltaTime, sf::RenderWindow& window) { float dts = deltaTime.asSeconds(); - headsUpDisplay.fpsText.setString("FPS: " + std::to_string(static_cast(1.f/dts))); #pragma region ZOOM float currentZoom = getSize().x / window.getSize().x; @@ -45,12 +55,17 @@ void Camera::update(const sf::Time& deltaTime, sf::RenderWindow& window) setCenter(newPosition); } #pragma endregion - headsUpDisplay.fpsText.setPosition(this->getCenter().x + 400, this->getCenter().y - 350); - headsUpDisplay.draw(window); + + updateHUD(dts, window); window.setView(*this); } +void Camera::draw(sf::RenderWindow& window) +{ + trackingObject->headUpDisplay.draw(window); +} + void Camera::setMoveSpeed(const float& speed) { this->moveSpeed = speed; diff --git a/src/DynamicProjectile.cpp b/src/DynamicProjectile.cpp index 776b104..0a1c41d 100644 --- a/src/DynamicProjectile.cpp +++ b/src/DynamicProjectile.cpp @@ -1 +1,264 @@ -#include "DynamicProjectile.h" \ No newline at end of file +#include "DynamicProjectile.h" +#include "Entity.h" + +DynamicProjectile::DynamicProjectile(): + Ammo(AmmoType::AVoidType), + body(nullptr), + fixture(nullptr), + hitBox(nullptr), + resistanceCoefficient(0.015f), + explosionRadius(5.f), + explosionPulse(0.5f), + gameObjectData(ObjectType::DynamicProjectileType) +{ + +} +DynamicProjectile::DynamicProjectile(const AmmoType& ammoType): + Ammo(ammoType, false), + body(nullptr), + fixture(nullptr), + hitBox(nullptr), + explosionRadius(5.f), + explosionPulse(0.5f), + resistanceCoefficient(0.015f), + gameObjectData(ObjectType::DynamicProjectileType) +{ + +} +void DynamicProjectile::initBody(b2World* world, const sf::Vector2f& pos, const float& angle, const b2BodyType& bodyType) +{ + bodyDef.type = bodyType; + bodyDef.position.Set(pos.x / GlobalConsts::SCALE, pos.y / GlobalConsts::SCALE); + bodyDef.angle = angle / 180.f * b2_pi; + body = world->CreateBody(&bodyDef); + body->SetBullet(true); + body->SetLinearDamping(resistanceCoefficient); + +} + +void DynamicProjectile::setBodyOvalShape(const float& radius_x, const float& radius_y, const int num_segments, const float& density) +{ + float fnum_segments = static_cast(num_segments); + b2Vec2* vertices = new b2Vec2[num_segments]; + sf::ConvexShape* hitbox; + hitbox = new sf::ConvexShape; + hitbox->setPointCount(num_segments); + + for (int i = 0; i < num_segments; ++i) { + float angle = 2.0f * b2_pi * static_cast(i) / fnum_segments; + vertices[i].Set(radius_x * getScale().x / GlobalConsts::SCALE * cos(angle), radius_y * getScale().y / GlobalConsts::SCALE * sin(angle)); + hitbox->setPoint(i, sf::Vector2f(vertices[i].x * GlobalConsts::SCALE, vertices[i].y * GlobalConsts::SCALE)); + } + + bodyShape.Set(vertices, num_segments); + fixture = body->CreateFixture(&bodyShape, density); + + b2Vec2 entityPosition = body->GetPosition(); + body->SetBullet(true); + hitbox->setPosition(entityPosition.x, entityPosition.y); + hitbox->setFillColor(sf::Color(0, 255, 0, 50)); + hitbox->setOutlineColor(sf::Color::Green); + hitbox->setOutlineThickness(2.0f); + hitBox = hitbox; +} + +void DynamicProjectile::setBodyBoxShape(const sf::Vector2f& size, const float& density) +{ + + b2Vec2 boxSize(size.x * getScale().x / 2.f / GlobalConsts::SCALE, size.y * getScale().y / 2.f / GlobalConsts::SCALE); + bodyShape.SetAsBox(boxSize.x, boxSize.y); + fixture = body->CreateFixture(&bodyShape, density); + body->SetBullet(true); + b2Vec2 entityPosition = body->GetPosition(); + sf::RectangleShape* hitbox; + hitbox = new sf::RectangleShape(sf::Vector2f(boxSize.x * GlobalConsts::SCALE * 2, boxSize.y * GlobalConsts::SCALE * 2)); + hitbox->setPosition(entityPosition.x, entityPosition.y); + hitbox->setOrigin(hitbox->getSize() / 2.f); + hitbox->setFillColor(sf::Color(0, 255, 0, 50)); + hitbox->setOutlineColor(sf::Color::Green); + hitbox->setOutlineThickness(2.0f); + hitBox = hitbox; +} + + +void DynamicProjectile::setBodyPolygonShape(const b2Vec2* vertices, const int num_segments) +{ + // + bodyShape.Set(vertices, num_segments); + + sf::ConvexShape* hitbox; + hitbox = new sf::ConvexShape; + hitbox->setPointCount(num_segments); + + for (int i = 0; i < num_segments; ++i) + { + hitbox->setPoint(i, sf::Vector2f(vertices[i].x * GlobalConsts::SCALE, vertices[i].y * GlobalConsts::SCALE)); + } + + b2Vec2 entityPosition = body->GetPosition(); + hitbox->setPosition(entityPosition.x, entityPosition.y); + hitbox->setFillColor(sf::Color(0, 255, 0, 50)); + hitbox->setOutlineColor(sf::Color::Green); + hitbox->setOutlineThickness(2.0f); + hitBox = hitbox; + // +} + +void DynamicProjectile::update(const sf::Time& deltaTime, std::vector& gameObjects, TextureManager& textureManager, b2World& world) +{ + if (body == nullptr) + { + return; + } + //applyResistance(); + b2Vec2 pos = body->GetPosition(); + setPosition(pos.x * GlobalConsts::SCALE, pos.y * GlobalConsts::SCALE); + setRotation(body->GetAngle() * 180.f / 3.14); + + if (hitBox != nullptr) + { + hitBox->setPosition(pos.x * GlobalConsts::SCALE, pos.y * GlobalConsts::SCALE); + hitBox->setRotation(body->GetAngle() * 180.f / 3.14); + } + if (getLifeTime() > 0) + { + + setLifeTime(getLifeTime() - deltaTime.asSeconds()); + } + else + { + destroy(world, gameObjects); + world.DestroyBody(body); + gameObjects.erase(std::remove_if(gameObjects.begin(), gameObjects.end(), + [this](GameObject* obj) { return obj == this; }), + gameObjects.end()); + + } + + +} + +void DynamicProjectile::applyResistance() +{ + const b2Vec2& velocity = body->GetLinearVelocity(); + + b2Vec2 resistance_force = resistanceCoefficient * velocity ; + + body->ApplyLinearImpulseToCenter(resistance_force, true); +} + +void DynamicProjectile::draw(sf::RenderWindow& window) +{ + if (GlobalConsts::hitBoxOn && hitBox != nullptr) + { + window.draw(*hitBox); + } + +} + +void DynamicProjectile::setBodyPosition(const sf::Vector2f& vec) +{ + setPosition(vec); + body->SetTransform(b2Vec2(vec.x / GlobalConsts::SCALE, vec.y / GlobalConsts::SCALE), body->GetAngle()); +} + +void DynamicProjectile::setBodyPosition(const b2Vec2& vec) +{ + body->SetTransform(vec, body->GetAngle()); +} + +void DynamicProjectile::setExplodes(const bool& explodes) +{ + this->explodes = explodes; +} + +const bool& DynamicProjectile::isExplodes() +{ + return explodes; +} + +void DynamicProjectile::setExplosionRadius(const float& explosionRadius) +{ + this->explosionRadius; +} + +const float& DynamicProjectile::getExplosionRadius() +{ + return explosionRadius; +} + +void DynamicProjectile::setExplosionPulse(const float& explosionPulse) +{ + this->explosionPulse = explosionPulse; +} + +const float& DynamicProjectile::getExplosionPulse() +{ + return explosionPulse; +} + +void DynamicProjectile::destroy(b2World& world, std::vector& gameObjects) +{ + b2AABB aabb; + aabb.lowerBound = body->GetPosition() - b2Vec2(explosionRadius, explosionRadius); + aabb.upperBound = body->GetPosition() + b2Vec2(explosionRadius, explosionRadius); + std::vector bodies; + for (auto gameOgject: gameObjects) + { + + if (gameOgject->getPhysicalObjectFlag()) + { + if (gameOgject->gameObjectData.getGameObjectType() == ObjectType::DynamicProjectileType) + { + + if (reinterpret_cast(gameOgject)->body != nullptr) + { + /* for (int32 childIndex = 0; childIndex < reinterpret_cast(gameOgject)->fixture->GetShape()->GetChildCount(); ++childIndex) { + b2AABB fixtureAABB; + reinterpret_cast(gameOgject)->fixture->GetShape()->ComputeAABB(&fixtureAABB, b2Transform(), childIndex); + if (b2TestOverlap(aabb, fixtureAABB)) + { + + } + }*/ + bodies.push_back(reinterpret_cast(gameOgject)->body); + } + + + + } + else if(gameOgject->gameObjectData.getGameObjectType() != ObjectType::UndefinedType) + { + if (reinterpret_cast(gameOgject)->body != nullptr) + { + /* for (int32 childIndex = 0; childIndex < reinterpret_cast(gameOgject)->fixture->GetShape()->GetChildCount(); ++childIndex) { + b2AABB fixtureAABB; + reinterpret_cast(gameOgject)->fixture->GetShape()->ComputeAABB(&fixtureAABB, b2Transform(), childIndex); + if (b2TestOverlap(aabb, fixtureAABB)) + { + + } + + }*/ + bodies.push_back(reinterpret_cast(gameOgject)->body); + } + + } + } + + } + for (b2Body* b : bodies) { + b2Vec2 bodyPos = b->GetPosition(); + b2Vec2 explosionDir = bodyPos - body->GetPosition(); + float distance = explosionDir.Length(); + + if (distance < explosionRadius) { + float strength = 1.0f - distance / explosionRadius; + b2Vec2 impulse = explosionDir; + impulse.Normalize(); + impulse *= strength * (explosionPulse); + + b->ApplyLinearImpulseToCenter(impulse, true); + } + } +} diff --git a/src/Entity.cpp b/src/Entity.cpp index c5b6cd1..a356351 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -7,11 +7,27 @@ Entity::Entity() : fixture(nullptr), hitBox(nullptr), hitted(false), - resistanceCoefficient(0.1f), + resistanceCoefficient(0.03f), selectedAmmoIndex(-1), selectedWeaponIndex(-1), - gameObjectData() + maxVelocity(0.1f) { + HUD::Label label; + label.type = HUD::FpsType; + label.text.setFont(GlobalConsts::font); + label.text.setCharacterSize(30); + label.text.setFillColor(sf::Color::Green); + label.positionCoefficient = sf::Vector2f(1.7f, 1.7f); + headUpDisplay.labels.push_back(label); + + label.type = HUD::AmmoType; + label.text.setCharacterSize(50); + label.positionCoefficient = sf::Vector2f(1.8f, -1.7f); + headUpDisplay.labels.push_back(label); + + label.type = HUD::HealthPointType; + label.positionCoefficient = sf::Vector2f(-1.5f, -1.7f); + headUpDisplay.labels.push_back(label); } void Entity::initBody(b2World* world, const sf::Vector2f &pos, const float& angle, const b2BodyType& bodyType) @@ -20,6 +36,8 @@ void Entity::initBody(b2World* world, const sf::Vector2f &pos, const float& angl bodyDef.position.Set(pos.x / GlobalConsts::SCALE, pos.y / GlobalConsts::SCALE); bodyDef.angle =angle/180.f * b2_pi; body = world->CreateBody(&bodyDef); + body->SetLinearDamping(resistanceCoefficient); + body->SetAngularDamping(resistanceCoefficient); } void Entity::setBodyOvalShape(const float &radius_x, const float &radius_y, const int num_segments, const float& density) @@ -69,6 +87,7 @@ void Entity::setBodyBoxShape(const sf::Vector2f& size, const float& density) void Entity::setBodyPolygonShape(const b2Vec2* vertices, const int num_segments) { + // bodyShape.Set(vertices, num_segments); sf::ConvexShape* hitbox; @@ -86,6 +105,7 @@ void Entity::setBodyPolygonShape(const b2Vec2* vertices, const int num_segments) hitbox->setOutlineColor(sf::Color::Green); hitbox->setOutlineThickness(2.0f); hitBox = hitbox; + // } void Entity::setBodyPosition(const sf::Vector2f& vec) @@ -104,13 +124,13 @@ void Entity::setTargetCoordinates(const sf::Vector2f& targetCoordinates) this->targetCoordinates = targetCoordinates; } -void Entity::update(const sf::Time& deltaTime, std::vector& gameObjects, TextureManager& textureManager) +void Entity::update(const sf::Time& deltaTime, std::vector& gameObjects, TextureManager& textureManager, b2World& world) { + float dts = deltaTime.asSeconds(); if (body == nullptr) { return; } - applyResistance(deltaTime.asSeconds()); b2Vec2 pos = body->GetPosition(); setPosition(pos.x * GlobalConsts::SCALE, pos.y * GlobalConsts::SCALE); setRotation(body->GetAngle() * 180.f / 3.14); @@ -122,9 +142,62 @@ void Entity::update(const sf::Time& deltaTime, std::vector& gameObj } if (!weapons.empty() && selectedWeaponIndex != -1) { Weapon* w = weapons[selectedWeaponIndex]; - w->update(angleTwoPoints(getPosition(), targetCoordinates)); + if (!ammo.empty()) + { + if (selectedAmmoIndex != -1) + { + if (ammo[selectedAmmoIndex].getAmmoType() != w->getAmmoMagazine().getAmmoType()) + { + for (size_t i = 0; i < ammo.size(); i++) + { + selectedAmmoIndex = i; + if (ammo[i].getAmmoType() == w->getAmmoMagazine().getAmmoType()) + { + break; + } + } + } + + } + else + { + for (size_t i = 0; i < ammo.size(); i++) + { + selectedAmmoIndex = i; + if (ammo[i].getAmmoType() == w->getAmmoMagazine().getAmmoType()) + { + break; + } + } + } + + for (auto& label : headUpDisplay.labels) + { + if (label.type == HUD::AmmoType) + label.text.setString("Ammo: " + std::to_string(static_cast(w->getAmmoMagazine().getAmountOfAmmo())) + "/" + std::to_string(static_cast(ammo[selectedAmmoIndex].getAmountOfAmmo()))); + } + + w->update(dts,angleTwoPoints(getPosition(), targetCoordinates), ammo[selectedAmmoIndex]); + } + else + { + Ammo voidAmmo(AmmoType::AVoidType); + w->update(dts,angleTwoPoints(getPosition(), targetCoordinates), voidAmmo); + } + } + + for (auto& label : headUpDisplay.labels) + { + switch (label.type) + { + case HUD::FpsType: + label.text.setString("FPS: " + std::to_string(static_cast(1.f / deltaTime.asSeconds()))); + break; + case HUD::HealthPointType: + label.text.setString("HP: " + std::to_string(static_cast(healthPoints))); + break; + } } - } void Entity::draw(sf::RenderWindow& window) @@ -148,21 +221,15 @@ void Entity::setPhysicalProperties(const float& density, const float& friction, fixture->SetRestitution(restitution); } -void Entity::applyResistance(const float& deltaTime) -{ - b2Vec2 velocity = body->GetLinearVelocity(); - - b2Vec2 resistance_force = -resistanceCoefficient * velocity ; - - body->ApplyForceToCenter(resistance_force, true); - - -} void Entity::setResistanceCoefficient(const float& resistanceCoefficient) { this->resistanceCoefficient = resistanceCoefficient; + if (body != nullptr) + { + body->SetLinearDamping(resistanceCoefficient); + } } void Entity::setHealthPoints(const float& healthPoints) @@ -175,6 +242,11 @@ void Entity::setMaxHealthPoints(const float& maxHealthPoints) this->maxHealthPoints = maxHealthPoints; } +void Entity::setMaxVelocity(const float& maxVelocity) +{ + this->maxVelocity = maxVelocity; +} + void Entity::setHittedFlag(const bool& hitted) { this->hitted = hitted; @@ -195,6 +267,11 @@ const float& Entity::getMaxHealthPoints() return maxHealthPoints; } +const float& Entity::getMaxVelocity() +{ + return maxVelocity; +} + const sf::Vector2f& Entity::getTargetCoordinates() { return targetCoordinates; diff --git a/src/Game.cpp b/src/Game.cpp index 27bdc2c..65b4b52 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -1,5 +1,5 @@ #include "Game.h" -#include + @@ -12,6 +12,8 @@ Game::Game(): void Game::init(const std::string& mapPath) { + GlobalConsts::font.loadFromFile("Resources/fonts/impact.ttf"); + const int texturesCount = 6; // Path \ Name std::pair textures[texturesCount] = @@ -43,6 +45,7 @@ void Game::init(const std::string& mapPath) b2BodyUserData& b2UserData = player.body->GetUserData(); b2UserData.pointer = reinterpret_cast(&player); camera.setTracking(&player); + gameObjects.push_back(&player); //Temp } @@ -89,7 +92,8 @@ void Game::handleEvent(sf::Event& event, sf::RenderWindow& window) if (event.key.code == sf::Keyboard::D) player.controlFlags.rightPressed = false; } - sf::Vector2i mousePosition = sf::Mouse::getPosition(window); + + sf::Vector2i mousePosition = sf::Mouse::getPosition(window);; // view sf::Vector2f worldPosition = window.mapPixelToCoords(mousePosition); player.setTargetCoordinates(sf::Vector2f(worldPosition)); @@ -100,24 +104,23 @@ void Game::update(const sf::Time& deltaTime, sf::RenderWindow& window) { CollisionHandler ollisionHandler; world.Step(60.f*deltaTime.asSeconds(), 8, 3); - player.update(deltaTime, gameObjects, textureManager); + //player.update(deltaTime, gameObjects, textureManager, world); level.update(deltaTime); camera.update(deltaTime, window); // std::set contactedBodies; - collisionHandler.handleCollision(&player, contactedBodies, world, gameObjects, textureManager); + //collisionHandler.handleCollision(&player, contactedBodies, world, gameObjects, textureManager); for (auto& gameObject : gameObjects) { collisionHandler.handleCollision(gameObject, contactedBodies, world, gameObjects, textureManager ); - gameObject->update(deltaTime, gameObjects, textureManager); + gameObject->update(deltaTime, gameObjects, textureManager, world); } for (size_t i = 0; i < player.ammo.size(); i++) { - //std::cout << "AmountOfAmmo = " << player.ammo[i].getAmountOfAmmo() <<" Ammo type: " << ammoTypeToString(player.ammo[i].getAmmoType())<<"\nIndex: " << i<< std::endl; - //std::cout << "MaximumAmmo = " << player.ammo[i].getMaximumAmmo() << std::endl; + } - //std::cout << "dts = " << deltaTime.asSeconds()<getHitboxFlag() if (gameObject->getPhysicalObjectFlag()) { - Entity* entity = reinterpret_cast(gameObject); - entity->draw(window); + gameObject->draw(window); } } - window.draw(player); - //if(player.getHitboxFlag()&& GlobalConsts::hitBoxOn) - player.draw(window); + //window.draw(player); + //player.draw(window); + camera.draw(window); } void CollisionHandler::handleCollision(GameObject* gameObject, std::set &contactedBodies, b2World& world, std::vector& gameObjects, TextureManager& textureManager) @@ -145,43 +146,42 @@ void CollisionHandler::handleCollision(GameObject* gameObject, std::set std::set objectsToRemove; if (!gameObject->getPhysicalObjectFlag()) return; + //std::cout << objectTypeToString(gameObject->gameObjectData.getGameObjectType()) << std::endl; // Entity - Entity* entityA = reinterpret_cast(gameObject); + if (gameObject->gameObjectData.getGameObjectType() == ObjectType::DynamicProjectileType) + { + DynamicProjectile* dynamicProjectileA = reinterpret_cast(gameObject); + if (dynamicProjectileA->body == nullptr) + return; - if (entityA->body == nullptr) - return; - entityA->body->GetFixtureList(); - contactedBodies.insert(entityA->body); - b2Fixture* fixture = entityA->body->GetFixtureList(); - if (fixture->GetShape()->GetType() == b2Shape::e_polygon) { - - //while (fixture) { - // b2ContactEdge* contactEdge = fixture->GetContactList(); // + dynamicProjectileA->body->GetFixtureList(); - // while (contactEdge) { - // // - // // ... + contactedBodies.insert(dynamicProjectileA->body); - // contactEdge = contactEdge->next; // - // } + b2Fixture* fixture = dynamicProjectileA->body->GetFixtureList(); - // fixture = fixture->GetNext(); // - //} - b2ContactEdge* contactEdge = entityA->body->GetContactList(); - processContactEdge(entityA, contactEdge, contactedBodies, objectsToRemove, world, textureManager); + b2ContactEdge* contactEdge = dynamicProjectileA->body->GetContactList(); + processContactEdge(dynamicProjectileA, contactEdge, contactedBodies, objectsToRemove, world, textureManager); } - else + else if(gameObject->gameObjectData.getGameObjectType() != ObjectType::UndefinedType) { - /*b2ContactEdge* contactEdge = entityA->body->GetContactList(); - processContactEdge(entityA,contactEdge, contactedBodies, objectsToRemove, world);*/ - + Entity* entityA = reinterpret_cast(gameObject); + if (entityA->body == nullptr) + return; + + entityA->body->GetFixtureList(); + + contactedBodies.insert(entityA->body); + + b2Fixture* fixture = entityA->body->GetFixtureList(); + + b2ContactEdge* contactEdge = entityA->body->GetContactList(); + processContactEdge(entityA, contactEdge, contactedBodies, objectsToRemove, world, textureManager); } - removeObjects(gameObjects, objectsToRemove, world); } -void CollisionHandler::processContactEdge(Entity* entityA, b2ContactEdge* contactEdge, std::set& contactedBodies, std::set& objectsToRemove, b2World& world, TextureManager& textureManager) +void CollisionHandler::processContactEdge(GameObject* objectA, b2ContactEdge* contactEdge, std::set& contactedBodies, std::set& objectsToRemove, b2World& world, TextureManager& textureManager) { - //std::cout << contactEdge << std::endl; while (contactEdge) { if (contactEdge->contact->IsTouching()) { // @@ -192,21 +192,27 @@ void CollisionHandler::processContactEdge(Entity* entityA, b2ContactEdge* contac continue; } // Entity + //, + GameObject* objectB = reinterpret_cast(contactEdge->other->GetUserData().pointer); - Entity* entityB = reinterpret_cast(contactEdge->other->GetUserData().pointer); + if (objectB != nullptr) { + ObjectType objA = objectA->gameObjectData.getGameObjectType(); + ObjectType objB = objectB->gameObjectData.getGameObjectType(); + + if (objA == ObjectType::ObjectWeaponType || objA == ObjectType::ObjectAmmoType) + { + std::swap(objectA, objectB); + std::swap(objA, objB); - if (entityA != nullptr && entityB != nullptr) { - const ObjectType& objA = entityA->gameObjectData.getGameObjectType(); - const ObjectType& objB = entityB->gameObjectData.getGameObjectType(); + } if (objA == ObjectType::PlayerType ) { - /*std::cout << ANSI_COLOR_CYAN; - std::cout << objectTypeToString(objA) << " collided with " << objectTypeToString(objB) << std::endl; - std::cout << ANSI_COLOR_RESET;*/ + Entity* entityA = reinterpret_cast(objectA); if (objB == ObjectType::ObjectWeaponType) { + Entity* entityB = reinterpret_cast(objectB); bool weapoFlaf = false; for (auto weaponB : entityB->weapons) { @@ -272,6 +278,7 @@ void CollisionHandler::processContactEdge(Entity* entityA, b2ContactEdge* contac } else if(objB == ObjectType::ObjectAmmoType) { + Entity* entityB = reinterpret_cast(objectB); bool ammoFlaf = false; for (auto& ammoB : entityB->ammo) { @@ -301,18 +308,9 @@ void CollisionHandler::processContactEdge(Entity* entityA, b2ContactEdge* contac } } - else + else if(objA == ObjectType::DynamicProjectileType) { - //objectsToRemove.insert(entityB); - - //std::cout << ANSI_COLOR_BLUE; - //std::cout << objectTypeToString(objA) << " collided with " << objectTypeToString(objB) << std::endl; - //std::cout << ANSI_COLOR_RESET; - } - if (true) - { - } } diff --git a/src/GameObjectData.cpp b/src/GameObjectData.cpp index de3acfa..afc4831 100644 --- a/src/GameObjectData.cpp +++ b/src/GameObjectData.cpp @@ -1,5 +1,14 @@ #include "GameObjectData.h" +GameObjectData::GameObjectData():objectType(ObjectType::UndefinedType) +{ +} + +GameObjectData::GameObjectData(const ObjectType& objectType) :objectType(objectType) +{ + +} + void GameObjectData::setGameObjectType(const ObjectType& objectType) { this->objectType = objectType; @@ -26,6 +35,8 @@ std::string objectTypeToString(const ObjectType& objectType) return "WeaponType"; case ObjectAmmoType: return "AmmoType"; + case DynamicProjectileType: + return "DynamicProjectileType"; default: return "UndefinedType"; } diff --git a/src/GlobalConsts.cpp b/src/GlobalConsts.cpp index 0aa3cab..666384b 100644 --- a/src/GlobalConsts.cpp +++ b/src/GlobalConsts.cpp @@ -2,4 +2,6 @@ const float GlobalConsts::SCALE = 100.f; -bool GlobalConsts::hitBoxOn = false; \ No newline at end of file +bool GlobalConsts::hitBoxOn = false; + +sf::Font GlobalConsts::font = sf::Font(); \ No newline at end of file diff --git a/src/Gui.cpp b/src/Gui.cpp index 6386e36..86b7ae2 100644 --- a/src/Gui.cpp +++ b/src/Gui.cpp @@ -1,6 +1,6 @@ #include "Gui.h" -void GUI::MainMenuInit(tgui::Gui& gui) +void GUI::MainMenuInit(auto& gui) { mainMenuWindow = tgui::Group::create(); mainMenuWindow->setSize("100%", "100%"); @@ -62,7 +62,7 @@ GUI::GUI(): } -void GUI::GameMenuInit(tgui::Gui& gui) +void GUI::GameMenuInit(auto& gui) { gameMenuWindow = tgui::Group::create(); gameMenuWindow->setSize("100%", "100%"); @@ -100,7 +100,7 @@ void GUI::GameMenuInit(tgui::Gui& gui) gui.add(gameMenuWindow); } -void GUI::SettingsMenuInit(tgui::Gui& gui) +void GUI::SettingsMenuInit(auto& gui) { settingsMenuWindow = tgui::Group::create(); settingsMenuWindow->setSize("100%", "100%"); @@ -175,7 +175,7 @@ void GUI::SettingsMenu(const bool& flag) flags.onSettingsMenu = flag; } -void GUI::TestMenuInit(tgui::Gui& gui) +void GUI::TestMenuInit(auto& gui) { } diff --git a/src/HeadUpDisplay.cpp b/src/HeadUpDisplay.cpp new file mode 100644 index 0000000..aa9ebee --- /dev/null +++ b/src/HeadUpDisplay.cpp @@ -0,0 +1 @@ +#include "HeadUpDisplay.h" diff --git a/src/Level.cpp b/src/Level.cpp index 60c28c8..13d9df2 100644 --- a/src/Level.cpp +++ b/src/Level.cpp @@ -160,6 +160,7 @@ void Level::parse(std::vector& gameObjects, TextureManager* texture entity->setOrigin(sf::Vector2f(entity->getLocalBounds().width / 2.f, entity->getLocalBounds().height / 2.f)); entity->initBody(&world, sf::Vector2f(object.getPosition().x + entity->getLocalBounds().width* scale.x / 2.f, object.getPosition().y - entity->getLocalBounds().height * scale.y / 2.f), object.getRotation()); entity->setBodyBoxShape(sf::Vector2f(entity->getLocalBounds().width, entity->getLocalBounds().height), density<0.f?1.f:density );//if(density < 0) density = 1.f; else density = customDensity + entity->setPhysicalObjectFlag(true); if (density >= 0.f && friction >= 0.f && restitution >= 0) { entity->setPhysicalProperties(density, friction, restitution); diff --git a/src/Player.cpp b/src/Player.cpp index 03b8539..08c96e9 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -1,19 +1,20 @@ #include "Player.h" Player::Player() : - healthPoints(100.f), - maxHealthPoints(100.f), - speed(0.8f), - hitted(false), + speed(0.09f), debugMode(false), live(true), Entity() { + setMaxHealthPoints(100.f); + setHealthPoints(100.f); + setResistanceCoefficient(0.1f); + bodyDef.fixedRotation = true; } -void Player::update(const sf::Time& deltaTime, std::vector& gameObjects, TextureManager& textureManager) +void Player::update(const sf::Time& deltaTime, std::vector& gameObjects, TextureManager& textureManager, b2World& world) { float dts = deltaTime.asSeconds(); if (controlFlags.upPressed) @@ -24,24 +25,16 @@ void Player::update(const sf::Time& deltaTime, std::vector& gameObj body->ApplyLinearImpulseToCenter(b2Vec2 ( - 1.f * dts * speed, 0), true); if (controlFlags.rightPressed) body->ApplyLinearImpulseToCenter(b2Vec2(1.f * dts * speed, 0), true); - if (controlFlags.downPressed) + if (controlFlags.attackPressed) { + if (!weapons.empty() && selectedWeaponIndex != -1) { + Weapon* w = weapons[selectedWeaponIndex]; - w->shot(gameObjects, textureManager); + w->shot(gameObjects, textureManager,this, world); } } - Entity::update(deltaTime, gameObjects, textureManager); -} - -void Player::setHealthPoints(const float& healthPoints) -{ - this->healthPoints = healthPoints; -} - -void Player::setMaxHealthPoints(const float& maxHealthPoints) -{ - this->maxHealthPoints = maxHealthPoints; + Entity::update(deltaTime, gameObjects, textureManager, world); } void Player::setSpeed(const float& speed) @@ -49,36 +42,17 @@ void Player::setSpeed(const float& speed) this->speed = speed; } -void Player::setHittedFlag(const bool& hitted) -{ - this->hitted = hitted; -} void Player::setDebugMode(const bool& mode) { this->debugMode = mode; } -const float& Player::getHealthPoints() -{ - return healthPoints; -} - -const float& Player::getMaxHealthPoints() -{ - return maxHealthPoints; -} - const float& Player::getSpeed() { return speed; } -const bool& Player::isHitted() -{ - return hitted; -} - const bool& Player::getDebugMode() { return debugMode; diff --git a/src/Weapon.cpp b/src/Weapon.cpp index 8f377d8..722d853 100644 --- a/src/Weapon.cpp +++ b/src/Weapon.cpp @@ -11,6 +11,7 @@ Weapon::Weapon() : dCooldown(0.f), avable(false), reloading(false), + cooldowning(false), trackingObject(nullptr) { } @@ -36,18 +37,43 @@ Weapon::Weapon dCooldown(0.f), avable(avable), reloading(false), + cooldowning(false), trackingObject(trackingObject) { } -void Weapon::shot(std::vector& gameObjects, TextureManager& textureManager) +const bool& Weapon::shot(std::vector& gameObjects, TextureManager& textureManager, GameObject* whoShot, b2World& world) { - + + if (reloading||cooldowning) + { + return false; + } + + if (ammoMagazine.getAmountOfAmmo() == 0) + { + reloading = true; + std::cout << "Reload..." << std::endl; + return false; + } + else + { + ammoMagazine - 1; + if (ammoMagazine.getAmountOfAmmo() != 0) + { + cooldowning = true; + std::cout << "Cooldown..." << std::endl; + } + return true; + + } + return false; } -void Weapon::update(const float& angle) +void Weapon::update(const float& dts, const float& angle, Ammo& ammo) { + // if (trackingObject != nullptr) { setPosition(trackingObject->getPosition()); @@ -61,6 +87,43 @@ void Weapon::update(const float& angle) } setRotation(angle); } + // + if (reloading) + { + if (ammo.getAmountOfAmmo() > 0) { + dReloadTime += dts; + if (dReloadTime >= reloadTime) + { + dReloadTime = 0.f; + reloading = false; + ammoMagazine += ammo; + } + } + else + { + dReloadTime = 0; + reloading = false; + } + } + + // + if (cooldowning) + { + if (ammoMagazine.getAmountOfAmmo() > 0) { + dCooldown += dts; + if (dCooldown >= cooldown) + { + dCooldown = 0.f; + cooldowning = false; + + } + } + else + { + dCooldown = 0; + cooldowning = false; + } + } } @@ -154,6 +217,16 @@ void Weapon::setReload(const bool& reloading) this->reloading = reloading; } +const bool& Weapon::isCooldowning() +{ + return cooldowning; +} + +void Weapon::setCooldowning(const bool& cooldowning) +{ + this->cooldowning = cooldowning; +} + GameObject* Weapon::getTrakingObject() { return trackingObject; diff --git a/src/Weapons/GrenadeLauncher.cpp b/src/Weapons/GrenadeLauncher.cpp index b2bc6fe..32c6d2c 100644 --- a/src/Weapons/GrenadeLauncher.cpp +++ b/src/Weapons/GrenadeLauncher.cpp @@ -2,7 +2,7 @@ GrenadeLauncher::GrenadeLauncher():Weapon( WeaponType::WGrenadeLauncherType, - Ammo(AmmoType::AGrenadeLauncherType), + Ammo(AmmoType::AGrenadeLauncherType, false), 20.f, 1.f, 1.f, @@ -13,19 +13,36 @@ GrenadeLauncher::GrenadeLauncher():Weapon( } -void GrenadeLauncher::shot(std::vector& gameObjects, TextureManager& textureManager) +const bool& GrenadeLauncher::shot(std::vector& gameObjects, TextureManager& textureManager, GameObject* whoShot, b2World& world) { - if (isReloading()) - { - return; - } - Ammo magazine = getAmmoMagazine(); - if (magazine.getAmountOfAmmo() == 0) - { - setReload(true); - } - else + bool Shoting = Weapon::shot(gameObjects, textureManager, whoShot, world); + if (Shoting) { + GrenadeLauncherProjectaile* projectile = new GrenadeLauncherProjectaile(); + projectile->setTexture(*textureManager.textures["grenade_launcher_ammo"]); + projectile->setOrigin(projectile->getLocalBounds().width / 2.f, projectile->getLocalBounds().height / 2.f); + projectile->gameObjectData.setGameObjectType(ObjectType::DynamicProjectileType); + + // + sf::Vector2f offsetToRightCenter(getTextureRect().width, getTextureRect().height / 2.f); + + // + float radians = getRotation() * (3.14159f / 180.f); // + float sinRadians = std::sin(radians); + float cosRadiand = std::cos(radians); + float rotatedX = offsetToRightCenter.x * cosRadiand - offsetToRightCenter.y * sinRadians; + float rotatedY = offsetToRightCenter.x * sinRadians + offsetToRightCenter.y * cosRadiand; + + // + sf::Vector2f rightCenter(getPosition().x + rotatedX, getPosition().y + rotatedY); + sf::Vector2f pos = sf::Vector2f(rightCenter.x + projectile->getLocalBounds().width * getScale().x / 2.f, rightCenter.y - projectile->getLocalBounds().height * getScale().y / 2.f); + projectile->initBody(&world, pos, getRotation(), b2_dynamicBody); + projectile->setBodyBoxShape(sf::Vector2f(projectile->getLocalBounds().width, projectile->getLocalBounds().height),1.f); + b2BodyUserData& b2UserData = projectile->body->GetUserData(); + b2UserData.pointer = reinterpret_cast(projectile); + projectile->body->ApplyLinearImpulseToCenter(b2Vec2(0.005f * cosRadiand,0.005f * sinRadians), true); + gameObjects.push_back(projectile); } + return false; } diff --git a/src/Window.cpp b/src/Window.cpp index 1646cdc..ac1ba17 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -9,6 +9,7 @@ MainWindow::MainWindow() : MainWindow::MainWindow(const Settings& settings) : window(settings.videoSettings.videoMode, "Roberto", (settings.videoSettings.fullscreen ? sf::Style::Fullscreen : sf::Style::Default), settings.videoSettings.ontext) { + window.setFramerateLimit(0); gui.setTarget(window); } diff --git a/tester/main.cpp b/tester/main.cpp index a6a880f..ffcb6e2 100644 --- a/tester/main.cpp +++ b/tester/main.cpp @@ -3,6 +3,7 @@ #include "../include/SFMLOrthogonalLayer.hpp" #include #include +#include struct WASD {