diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build.yml similarity index 66% rename from .github/workflows/build_windows.yml rename to .github/workflows/build.yml index 6e6b3998..25ab6fac 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Windows Build +name: Build on: [push, pull_request] jobs: @@ -7,10 +7,11 @@ jobs: runs-on: ${{ matrix.os }} if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository strategy: + fail-fast: false matrix: include: - # - os: ubuntu-latest - # name: Linux + - os: ubuntu-latest + name: Linux # - os: macOS-latest # name: MacOS - os: windows-latest @@ -22,10 +23,16 @@ jobs: - name: Install Xorg lib if: matrix.name == 'Linux' run: | - sudo apt install -y libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev + sudo apt install -y libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev liblua5.3-dev - name: Update G++ if: matrix.name == 'Linux' run: sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100 + - name: Install Lua + if: matrix.name == 'Windows' + shell: bash + run: | + curl https://sourceforge.net/projects/luabinaries/files/5.4.2/Windows%20Libraries/Dynamic/lua-5.4.2_Win64_dll16_lib.zip/download -L > lua.zip + unzip lua - name: Build run: | mkdir build && cd build @@ -36,7 +43,14 @@ jobs: if: matrix.name == 'Linux' run: test -f build/bomberman - name: Archive production artifact for Windows binary + if: matrix.name == 'Windows' uses: actions/upload-artifact@v1 with: name: BombermanWindows.exe path: build/Debug/bomberman.exe + - name: Archive production artifact for Linux binary + if: matrix.name == 'Linux' + uses: actions/upload-artifact@v1 + with: + name: BombermanLinux + path: build/bomberman diff --git a/.github/workflows/build_linux.yml b/.github/workflows/build_linux.yml deleted file mode 100644 index 6c6d01e9..00000000 --- a/.github/workflows/build_linux.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Linux Build (Epitech Container) -on: [push, pull_request] - -jobs: - testbox: - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository - runs-on: ubuntu-latest - container: - image: epitechcontent/epitest-docker:latest - steps: - - uses: actions/checkout@v2 - with: - submodules: true - - name: Build - run: | - mkdir build && cd build - cmake .. - cmake --build . - - name: CheckBinaryName - shell: bash - run: test -f build/bomberman - - name: Archive production artifact for Linux binary - uses: actions/upload-artifact@v1 - with: - name: BombermanLinux - path: build/bomberman \ No newline at end of file diff --git a/.github/workflows/build_web.yml b/.github/workflows/build_web.yml index 2b9a2f3e..88d67e18 100644 --- a/.github/workflows/build_web.yml +++ b/.github/workflows/build_web.yml @@ -9,6 +9,8 @@ jobs: - uses: actions/checkout@v1 with: submodules: true + - name: Install lua + run: sudo apt install -y liblua5.3-dev - name: Exec shell: bash run: ./build_web.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e87b9b9d..ae5f9a29 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: submodules: true - name: Install Xorg lib run: | - sudo apt install -y libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev + sudo apt install -y libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev liblua5.3-dev - name: Update G++ run: sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100 - name: Build diff --git a/CMakeLists.txt b/CMakeLists.txt index 62587c04..c1a406d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,12 +3,14 @@ project(bomberman) set(CMAKE_CXX_STANDARD 20) -include_directories(bomberman lib/Ray/sources) -include_directories(bomberman lib/wal/sources) -include_directories(bomberman sources) +include_directories(lib/Ray/sources) +include_directories(lib/wal/sources) +include_directories(lib/LuaGate/sources) +include_directories(sources) add_subdirectory(${PROJECT_SOURCE_DIR}/lib/wal) add_subdirectory(${PROJECT_SOURCE_DIR}/lib/Ray) +add_subdirectory(${PROJECT_SOURCE_DIR}/lib/LuaGate) if (EMSCRIPTEN) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY") @@ -79,6 +81,12 @@ set(SOURCES sources/Component/Collision/CollisionComponent.hpp sources/System/Collision/CollisionSystem.hpp sources/System/Collision/CollisionSystem.cpp + sources/Component/IAControllable/IAControllableComponent.hpp + sources/Component/IAControllable/IAControllableComponent.cpp + sources/System/IAControllable/IAControllableSystem.hpp + sources/System/IAControllable/IAControllableSystem.cpp + sources/Map/MapInfo.hpp + sources/Map/MapInfo.cpp sources/Component/Button/ButtonComponent.hpp sources/System/MenuControllable/MenuControllableSystem.cpp sources/System/MenuControllable/MenuControllableSystem.hpp @@ -131,6 +139,8 @@ set(SOURCES sources/Component/IntroAnimation/IntroAnimationComponent.cpp sources/System/IntroAnimation/IntroAnimationSystem.hpp sources/System/IntroAnimation/IntroAnimationSystem.cpp + sources/System/Renderer/CameraSystem.cpp + sources/System/Renderer/CameraSystem.cpp sources/Runner/SplashScreenScene.cpp sources/Runner/TitleScreenScene.cpp sources/Runner/MainMenuScene.cpp @@ -177,23 +187,23 @@ add_executable(bomberman sources/main.cpp ${SOURCES} ) -target_include_directories(bomberman PUBLIC sources) -target_link_libraries(bomberman PUBLIC wal ray) +target_include_directories(bomberman PUBLIC sources LuaGate) +target_link_libraries(bomberman PUBLIC wal ray LuaGate) add_executable(unit_tests EXCLUDE_FROM_ALL - ${SOURCES} - tests/CacheTest.cpp - tests/EntityTests.cpp - tests/MainTest.cpp - tests/EngineTests.cpp - tests/CallbackTest.cpp - tests/MoveTests.cpp - tests/ViewTest.cpp - tests/CollisionTest.cpp - ) -target_include_directories(unit_tests PUBLIC sources) -target_link_libraries(unit_tests PUBLIC wal ray) + ${SOURCES} + tests/CacheTest.cpp + tests/EntityTests.cpp + tests/MainTest.cpp + tests/EngineTests.cpp + tests/CallbackTest.cpp + tests/MoveTests.cpp + tests/ViewTest.cpp + tests/CollisionTest.cpp + ) +target_include_directories(unit_tests PUBLIC sources LuaGate) +target_link_libraries(unit_tests PUBLIC wal ray LuaGate) find_package(Catch2 QUIET) if (NOT Catch2_FOUND) diff --git a/Doxyfile b/Doxyfile index 12d9ca89..a8900e66 100644 --- a/Doxyfile +++ b/Doxyfile @@ -889,7 +889,6 @@ FILE_PATTERNS = *.c \ *.dox \ *.doc \ *.txt \ - *.py \ *.pyw \ *.f90 \ *.f95 \ @@ -919,6 +918,8 @@ RECURSIVE = YES EXCLUDE = */tests/* \ cmake-build-debug/* + build*/* + emsdk/* # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded @@ -1027,7 +1028,7 @@ FILTER_SOURCE_PATTERNS = # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = +USE_MDFILE_AS_MAINPAGE = README.md #--------------------------------------------------------------------------- # Configuration options related to source browsing diff --git a/a b/a new file mode 100644 index 00000000..0e66280b --- /dev/null +++ b/a @@ -0,0 +1,266 @@ +WARNING: SHADER: [ID 5] Failed to find shader attribute: vertexTexCoord2 +WARNING: SHADER: [ID 5] Failed to find shader attribute: vertexNormal +WARNING: SHADER: [ID 5] Failed to find shader attribute: vertexTangent +WARNING: SHADER: [ID 5] Failed to find shader attribute: vertexColor +WARNING: SHADER: [ID 5] Failed to find shader uniform: view +WARNING: SHADER: [ID 5] Failed to find shader uniform: projection +WARNING: SHADER: [ID 5] Failed to find shader uniform: matNormal +WARNING: SHADER: [ID 5] Failed to find shader uniform: colDiffuse +WARNING: SHADER: [ID 5] Failed to find shader uniform: texture1 +WARNING: SHADER: [ID 5] Failed to find shader uniform: texture2 +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader attribute: vertexTexCoord2 +WARNING: SHADER: [ID 8] Failed to find shader attribute: vertexTangent +WARNING: SHADER: [ID 8] Failed to find shader attribute: vertexColor +WARNING: SHADER: [ID 8] Failed to find shader uniform: view +WARNING: SHADER: [ID 8] Failed to find shader uniform: projection +WARNING: SHADER: [ID 8] Failed to find shader uniform: matNormal +WARNING: SHADER: [ID 8] Failed to find shader uniform: colDiffuse +WARNING: SHADER: [ID 8] Failed to find shader uniform: texture1 +WARNING: SHADER: [ID 8] Failed to find shader uniform: texture2 +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 5] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask +WARNING: SHADER: [ID 8] Failed to find shader uniform: mask diff --git a/assets/ai_scripts/john.lua b/assets/ai_scripts/john.lua new file mode 100644 index 00000000..3363cb37 --- /dev/null +++ b/assets/ai_scripts/john.lua @@ -0,0 +1,330 @@ +------------ JOHN AI + +--[[ +Info available to the ai +mapinfo.player { x, y, z } +mapinfo.raw { {x, y, z, type }, ...} +mapinfo.dist { } +]] +------------ + +------ Debug variables +local debug = false + +if not debug then + log = function() end +else + log = function(a) + print(a) + end +end +----- Global variables +Dirs = {{x = 1, y = 0}, {x = -1, y = 0}, {x = 0, y = -1}, {x = 0, y = 1}} +MaxX = 0 +MaxY = 0 +Map = {} +Danger = {} +LastPos = nil + +----- Map functions +function PrintMap(map, MaxX, maxZ) + log("---------") + log("PRINT MAP") + log("---------") + for i=0,MaxX + 1 do + local s = "| " + for j=0,maxZ + 1 do + s = s .. tostring(map[i][j]) .. " | "; + end + log(s) + log(string.rep("-", (maxZ - 1) * 5 - 1)) + end +end + +function CreateMyMap(infos, MaxX, MaxY) + local map = {} + for i=0,MaxX + 1 do + map[i] = {} + for j=0,MaxY + 1 do + map[i][j] = 0 + end + end + for i, info in ipairs(infos) do + map[info.x][info.y] = info.type + end + --PrintMap(map, MaxX, MaxY) + return map +end + +function CreateDangerMap(dangers) + local danger = {} + for i=0,MaxX + 1 do + danger[i] = {} + for j=0,MaxY + 1 do + danger[i][j] = 0 + end + end + for i, zone in ipairs(dangers) do + if danger[math.floor(zone.x)] == nil then + danger[math.floor(zone.x)] = {} + end + danger[math.floor(zone.x)][math.floor(zone.y)] = math.floor(zone.level) + end + PrintMap(danger, MaxX, MaxY) + return danger +end + +function isInExplosionRange(x, y) + if Danger[x][y] > 0 then + return true + end + return false +end + +---- Pathfinding + +function setAdd(set, toAdd) + table.insert(set, toAdd) +end + +function setRemove(set, toRemove) + for i, node in ipairs(set) do + if node == toRemove then + set[i] = set[#set] + set[#set] = nil + break + end + end +end + +function not_in(set, node) + for _,value in pairs(set) do + if value.x == node.x and value.y == node.y then + return false + end + end + return true +end + + +function getNeighbors(node) + local neighbors = {} + for _, dir in ipairs(Dirs) do + local neighborX = node.x + dir.x + local neighborY = node.y + dir.y + if neighborY <= MaxY and neighborX <= MaxX then + if neighborY >= 0 and neighborX >= 0 then + if Map[neighborX][neighborY] == 0 and Danger[neighborX][neighborY] ~= 1 then + table.insert(neighbors, {x = neighborX, y = neighborY}) + end + end + end + end + if #neighbors == 0 and Danger[node.x][node.y] <= 1 then + for _, dir in ipairs(Dirs) do + local neighborX = node.x + dir.x + local neighborY = node.y + dir.y + if neighborY <= MaxY and neighborX <= MaxX then + if neighborY >= 0 and neighborX >= 0 then + if Map[neighborX][neighborY] == 0 then + table.insert(neighbors, {x = neighborX, y = neighborY}) + end + end + end + end + end + return neighbors +end + +function getLowestFromSet(set, f_score) + local lowest = 100000 + local best = nil + for _,node in ipairs(set) do + local score = f_score[node] + if score < lowest then + lowest = score + best = node + end + end + return best +end + +function fill_path(path, came_from, node) + if came_from[node] then + table.insert(path, 1, came_from[node]) + return fill_path(path, came_from, came_from[node]) + else + return path + end +end + +--A star search +function pathfind(root, target) + local closed = {} + local open = { root } + local came_from = {} + + local g_score = {} + local f_score = {} + + g_score[root] = 0 + f_score[root] = dist(root, target) + + while #open > 0 do + log("openset size") + log(#open) + local curr = getLowestFromSet(open, f_score) --get lowest node of openset + log("current node") + log(curr.x) + log(curr.y) + if curr.x == target.x and curr.y == target.y then + local path = fill_path({}, came_from, target) -- fill the path with came from + table.insert(path, target) + return path + end + setRemove(open, curr) -- remove curr from open + setAdd(closed, curr)-- add node to closed + log("closed set") + for i, c in ipairs(closed) do + log("member") + log(c.x) + log(c.y) + end + local neighbors = getNeighbors(curr) -- get neighbors of current + for _, neighbor in ipairs(neighbors) do + if not_in(closed, neighbor) then -- neighbor not in closed set + local try_g_score = g_score[curr] + 1 + if not_in(open, neighbor) or try_g_score < g_score[neighbor] then + came_from[neighbor] = curr + g_score[neighbor] = try_g_score + f_score[neighbor] = g_score[neighbor] + dist(neighbor, target) + if not_in(open, neighbor) then + setAdd(open, neighbor) + end + end + end + end + end + return {} +end + +function dist(nodeA, nodeB) + return math.sqrt(math.pow(nodeB.x - nodeA.x, 2) + math.pow(nodeB.y - nodeA.y, 2)) +end + +function getPathToSafeSpace(player) + local minXesc = (player.x - 3 < 0) and 0 or (player.x - 3); + local MaxXesc = (player.x + 3 > MaxX) and MaxX or (player.x + 3); + local minYesc = (player.y - 3 < 0) and 0 or (player.y - 3); + local MaxYesc = (player.y + 3 > MaxY) and MaxY or (player.y + 3); + + local minDist = 100000 + local res = {} + for i=minXesc,MaxXesc do + for j=minYesc, MaxYesc do + if Map[i][j] == 0 and Danger[i][j] == 0 then + local safe = {x = i, y = j} + local currDist = dist(player, safe) + if currDist < minDist then + minDist, res = currDist, safe + end + end + end + end + local path = pathfind(player, res) + return path +end + +function getNeighborAttack() +end + +function getPathToEnemy(player, enemies) + local minDist = 100000 + local res = {} + for _, enemy in ipairs(enemies) do + local currDist = dist(player, enemy) + if currDist < minDist then + minDist, res = currDist, enemy + end + end + local path = pathfind(player, res, getNeighborAttack) + return path +end + + +------ Update +function Update(mapinfo) + MaxX = 0 + MaxY = 0 + log("NEW FRAME") + for i, info in ipairs(mapinfo.raw) do + if info.x > MaxX then + MaxX = info.x + end + if info.y > MaxY then + MaxY = info.y + end + end + Map = CreateMyMap(mapinfo.raw, MaxX, MaxY) + Danger = CreateDangerMap(mapinfo.danger) + PrintMap(Danger, MaxX, MaxY) + log("Current player pos") + log(mapinfo.player.x) + log(mapinfo.player.y) + log("Rounded player pos") + local roundedPlayerPos = {x = math.floor(mapinfo.player.x+0.5), y = math.floor(mapinfo.player.y+0.5)} + log(roundedPlayerPos.x) + log(roundedPlayerPos.y) + log("Last target") + if LastTarget ~= nil then + log(LastTarget.x) + log(LastTarget.y) + if math.abs(LastTarget.x - mapinfo.player.x) <= 0.1 and math.abs(LastTarget.x - mapinfo.player.x) <= 0.1 then + LastTarget = nil + else + return (LastTarget.x - mapinfo.player.x), (LastTarget.y - mapinfo.player.y), false, false + end + else + log("No last target") + end + if (isInExplosionRange(roundedPlayerPos.x, roundedPlayerPos.y)) then + log("IN DANGER") + local pathToSafeSpace = getPathToSafeSpace(roundedPlayerPos) + log("PATH") + for i,p in ipairs(pathToSafeSpace) do + log(i) + log(p.x) + log(p.y) + end + if #pathToSafeSpace == 0 then + return 0, 0, false, false + end + local f = pathToSafeSpace[1] + log("first way of the path") + log(f.x) + log(f.y) + LastTarget = {x = f.x, y = f.y} + return f.x - roundedPlayerPos.x, f.y - roundedPlayerPos.y, false, false + else + local enemies = mapinfo.enemies + local pathToEnemy = getPathToEnemy(roundedPlayerPos, enemies) + if #pathToEnemy == 0 then + return 0, 0, false, false + end + local f = pathToEnemy[1] + log("first way of the path") + log(f.x) + log(f.y) + LastTarget = {x = f.x, y = f.y} + --pathfind to closest player + if LastPos == nil then + LastPos = {x = mapinfo.player.x, y = mapinfo.player.y} + else + if mapinfo.player.x == LastPos.x and mapinfo.player.y == LastPos.y then + return 0, 0, true, true + end + end + LastTarget = {x = f.x, y = f.y} + return f.x - roundedPlayerPos.x, f.y - roundedPlayerPos.y, false, false; + end +end \ No newline at end of file diff --git a/assets/ai_scripts/randboi.lua b/assets/ai_scripts/randboi.lua new file mode 100644 index 00000000..0979d7ae --- /dev/null +++ b/assets/ai_scripts/randboi.lua @@ -0,0 +1,14 @@ +math.randomseed(os.time()) + +function Update(mapinfo) + + local x = math.random() + local y = math.random() + if (math.random() < 0.5) then + x = x * -1 + end + if (math.random() < 0.5) then + y = y * -1 + end + return x, y, false, true; +end \ No newline at end of file diff --git a/assets/background.png b/assets/background.png new file mode 100644 index 00000000..dd3b18b4 Binary files /dev/null and b/assets/background.png differ diff --git a/assets/background_game.png b/assets/background_game.png deleted file mode 100644 index 22b4cd46..00000000 Binary files a/assets/background_game.png and /dev/null differ diff --git a/assets/map/floor.png b/assets/map/floor.png index 74624ea9..030ed46d 100644 Binary files a/assets/map/floor.png and b/assets/map/floor.png differ diff --git a/assets/map/hole.png b/assets/map/hole.png index 3a79a9e0..f8038fa3 100644 Binary files a/assets/map/hole.png and b/assets/map/hole.png differ diff --git a/lib/LuaGate/CMakeLists.txt b/lib/LuaGate/CMakeLists.txt new file mode 100644 index 00000000..eb227570 --- /dev/null +++ b/lib/LuaGate/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.11) +set(CMAKE_CXX_STANDARD 20) +project(LuaGate) + +include_directories(sources) + +if (CMAKE_COMPILER_IS_GNUCXX) + set(GCC_COVERAGE_COMPILE_FLAGS "-Wall -Wextra -Werror -Wshadow") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}") +endif () + +set(HEADERS + sources/LuaGate.hpp +) + +set(SRC + sources/LuaGate.cpp +) + +include(FindLua) +if (NOT LUA_FOUND) + if (EXISTS ${CMAKE_SOURCE_DIR}/include/lua.hpp) + message("Using local lua") + set(LUA_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include/) + set(LUA_LIBRARIES ${CMAKE_SOURCE_DIR}/lua54.lib) + else() + message(FATAL_ERROR "Lua could not be found.") + endif() +endif() + +add_library(LuaGate STATIC ${SRC} ${HEADERS}) +target_include_directories(LuaGate PUBLIC ${LUA_INCLUDE_DIR}) +target_link_libraries(LuaGate ${LUA_LIBRARIES}) diff --git a/lib/LuaGate/sources/LuaGate.cpp b/lib/LuaGate/sources/LuaGate.cpp new file mode 100644 index 00000000..bb381901 --- /dev/null +++ b/lib/LuaGate/sources/LuaGate.cpp @@ -0,0 +1,97 @@ +// +// Created by Louis Auzuret on 10/06/21 +// + +#include "LuaGate.hpp" + +namespace LuaG +{ + State::State() + : _state(luaL_newstate()) + { + luaL_openlibs(_state); + } + + State::~State() + { + lua_close(_state); + } + + lua_State *State::getState(void) + { + return _state; + } + + void State::getGlobal(std::string str) + { + lua_getglobal(_state, str.c_str()); + } + + void State::dofile(std::string filepath) + { + luaL_dofile(_state, filepath.c_str()); + } + + void State::dostring(std::string str) + { + luaL_dostring(_state, str.c_str()); + } + + float State::getReturnNumber(void) + { + float res = 0; + + if (lua_isnil(_state, -1)) + return res; + if (!lua_isnumber(_state, -1)) + return res; + res = lua_tonumber(_state, -1); + lua_pop(_state, 1); + + return res; + } + + bool State::getReturnBool(void) + { + bool res = false; + + if (lua_isnil(_state, -1)) + return res; + if (!lua_isboolean(_state, -1)) + return res; + res = lua_toboolean(_state, -1); + lua_pop(_state, 1); + return res; + } + + bool State::callFunction(int nbParams, int nbReturns) + { + lua_pcall(_state, nbParams, nbReturns, 0); + return true; + } + + void State::setTable(void) + { + lua_settable(_state, -3); + } + + void State::push(float val) + { + lua_pushnumber(_state, val); + } + + void State::push(std::string str) + { + lua_pushstring(_state, str.c_str()); + } + + void State::newTable(void) + { + lua_newtable(_state); + } + + void State::popLast(void) + { + lua_pop(_state, -1); + } +} diff --git a/lib/LuaGate/sources/LuaGate.hpp b/lib/LuaGate/sources/LuaGate.hpp new file mode 100644 index 00000000..cf59833a --- /dev/null +++ b/lib/LuaGate/sources/LuaGate.hpp @@ -0,0 +1,64 @@ +// +// Created by Louis Auzuret on 10/06/21 +// + +#include +#include + +namespace LuaG +{ + class State + { + private: + //! @brief Lua state + lua_State *_state; + public: + //! @brief ctor + State(); + + //! @brief dtor + ~State(); + + //! @brief No copy constrructor + State(const State &) = delete; + + //! @brief No assign operator + State &operator=(const State &) = delete; + + //! @brief Get Lua state + lua_State *getState(void); + + //! @brief Get global value on top of the stack + void getGlobal(std::string str); + + //! @brief Execute a file in this state + void dofile(std::string filepath); + + //! @brief Execute a string in this state + void dostring(std::string str); + + //! @brief Get return Number + float getReturnNumber(void); + + //! @brief Get return Number + bool getReturnBool(void); + + //! @brief call a lua function + bool callFunction(int nbParams, int nbReturns); + + //! @brief setTable + void setTable(void); + + //! @brief push a number onto the lua stack + void push(float val); + + //! @brief push a string onto the lua stack + void push(std::string str); + + //! @brief Creates a new table at the top of the stack + void newTable(void); + + //! @brief Pop last value on the stack + void popLast(void); + }; +} \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/Image.cpp b/lib/Ray/sources/Drawables/Image.cpp index a95246be..6b971898 100644 --- a/lib/Ray/sources/Drawables/Image.cpp +++ b/lib/Ray/sources/Drawables/Image.cpp @@ -11,7 +11,13 @@ #include "Exceptions/RayError.hpp" namespace RAY { - Cache<::Image> Image::_imagesCache(LoadImage, UnloadImage); + Cache<::Image> Image::_imagesCache([] (const char *str) { + ::Image image = LoadImage(str); + + if (image.data == nullptr) + throw Exception::ResourceNotFound(std::string(str)); + return image; + }, UnloadImage); Image::Image(const std::string &filename, bool lonely): Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE), diff --git a/lib/Ray/sources/Drawables/Texture.cpp b/lib/Ray/sources/Drawables/Texture.cpp index ee017382..8114f98d 100644 --- a/lib/Ray/sources/Drawables/Texture.cpp +++ b/lib/Ray/sources/Drawables/Texture.cpp @@ -11,10 +11,16 @@ namespace RAY { - Cache<::Texture> Texture::_texturesCache(LoadTexture, UnloadTexture); + Cache<::Texture> Texture::_texturesCache([] (const char *str) { + ::Texture texture = LoadTexture(str); + + if (texture.id <= 0) + throw Exception::ResourceNotFound(std::string(str)); + return texture; + }, UnloadTexture); Texture::Texture() - : Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE, 0, 0) + : Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE, 1, 0), _resourcePath("") {} Texture::Texture(const std::string &filename, bool lonely, float scale, float rotation): diff --git a/lib/Ray/sources/Exceptions/RayError.cpp b/lib/Ray/sources/Exceptions/RayError.cpp index a4de1200..ee0d4fa7 100644 --- a/lib/Ray/sources/Exceptions/RayError.cpp +++ b/lib/Ray/sources/Exceptions/RayError.cpp @@ -26,3 +26,8 @@ RAY::Exception::WrongInputError::WrongInputError(const std::string &what): RayError(what) { } + +RAY::Exception::ResourceNotFound::ResourceNotFound(const std::string &path): + RayError(path + " couldn't be loaded") +{ +} diff --git a/lib/Ray/sources/Exceptions/RayError.hpp b/lib/Ray/sources/Exceptions/RayError.hpp index 158640d6..43c5590f 100644 --- a/lib/Ray/sources/Exceptions/RayError.hpp +++ b/lib/Ray/sources/Exceptions/RayError.hpp @@ -76,6 +76,23 @@ namespace RAY::Exception { //! @brief A default assignment operator WrongInputError &operator=(const WrongInputError &) = default; }; + + //! @brief exception used when a resource is not found + class ResourceNotFound: public RayError { + public: + //! @brief Create a new exception instance + //! @param path path of the un-loadable path + explicit ResourceNotFound(const std::string &path); + + //! @brief A default destructor + ~ResourceNotFound() override = default; + + //! @brief An exception is copy constructable + ResourceNotFound(const ResourceNotFound &) = default; + + //! @brief A default assignment operator + ResourceNotFound &operator=(const ResourceNotFound &) = default; + }; } #endif /* !RAYERROR_HPP_ */ diff --git a/lib/Ray/sources/Font.cpp b/lib/Ray/sources/Font.cpp index 89bf9517..50bb26a8 100644 --- a/lib/Ray/sources/Font.cpp +++ b/lib/Ray/sources/Font.cpp @@ -7,7 +7,13 @@ #include "Font.hpp" -RAY::Cache<::Font> RAY::Font::_fontsCache(LoadFont, UnloadFont); +RAY::Cache<::Font> RAY::Font::_fontsCache([] (const char *str) { + ::Font font = LoadFont(str); + + if (font.texture.id <= 0) + throw Exception::ResourceNotFound(std::string(str)); + return font; + }, UnloadFont); RAY::Font::Font(const std::string &filename, bool lonely): _font(_fontsCache.fetch(filename, lonely)) diff --git a/lib/Ray/sources/Model/Model.cpp b/lib/Ray/sources/Model/Model.cpp index b694fb4d..7ad788ef 100644 --- a/lib/Ray/sources/Model/Model.cpp +++ b/lib/Ray/sources/Model/Model.cpp @@ -13,15 +13,21 @@ namespace RAY::Drawables::Drawables3D { - RAY::Cache<::Model> Model::_modelsCache(LoadModel, UnloadModel); + RAY::Cache<::Model> Model::_modelsCache([] (const char *str) { + ::Model model = LoadModel(str); + + if (model.meshCount == 0) + throw Exception::ResourceNotFound(std::string(str)); + return model; + }, UnloadModel); Model::Model(const std::string &filename, bool lonely, std::optional> texture, const RAY::Vector3 &scale, + float rotationAngle, const RAY::Vector3 &position, - const RAY::Vector3 &rotationAxis, - float rotationAngle) + const RAY::Vector3 &rotationAxis) : ADrawable3D(position, WHITE), _model(_modelsCache.fetch(filename, lonely)), _rotationAxis(rotationAxis), @@ -35,9 +41,9 @@ namespace RAY::Drawables::Drawables3D Model::Model(const Mesh::AMesh &mesh, std::optional> texture, const RAY::Vector3 &scale, + float rotationAngle, const RAY::Vector3 &position, - const RAY::Vector3 &rotationAxis, - float rotationAngle) + const RAY::Vector3 &rotationAxis) : ADrawable3D(position, WHITE), _model(std::make_shared<::Model>(LoadModelFromMesh(*mesh.getRaylibMesh()))), _rotationAxis(rotationAxis), diff --git a/lib/Ray/sources/Model/Model.hpp b/lib/Ray/sources/Model/Model.hpp index 1d44352e..877cb769 100644 --- a/lib/Ray/sources/Model/Model.hpp +++ b/lib/Ray/sources/Model/Model.hpp @@ -31,18 +31,18 @@ namespace RAY::Drawables::Drawables3D { Model(const std::string &filePath, bool lonely = false, std::optional> texture = std::nullopt, const RAY::Vector3 &scale = RAY::Vector3(1, 1, 1), + float rotationAngle = 0, const RAY::Vector3 &position = {0, 0, 0}, - const RAY::Vector3 &rotationAxis = RAY::Vector3(0, 1, 0), - float rotationAngle = 0); + const RAY::Vector3 &rotationAxis = RAY::Vector3(0, 1, 0)); //! @brief Create an model, loading a file //! @param mesh: mesh to load Model(const Mesh::AMesh &mesh, std::optional> texture = std::nullopt, const RAY::Vector3 &scale = RAY::Vector3(1, 1, 1), + float rotationAngle = 0, const RAY::Vector3 &position = {0, 0, 0}, - const RAY::Vector3 &rotationAxis = RAY::Vector3(0, 1, 0), - float rotationAngle = 0); + const RAY::Vector3 &rotationAxis = RAY::Vector3(0, 1, 0)); //! @brief A copy constructor Model(const Model &model) = default; diff --git a/lib/Ray/sources/Model/ModelAnimations.cpp b/lib/Ray/sources/Model/ModelAnimations.cpp index 6d41832d..b1eedebc 100644 --- a/lib/Ray/sources/Model/ModelAnimations.cpp +++ b/lib/Ray/sources/Model/ModelAnimations.cpp @@ -7,7 +7,13 @@ #include "Model/ModelAnimations.hpp" -RAY::Cache<::ModelAnimation> RAY::ModelAnimations::_animationsCache(LoadModelAnimations, UnloadModelAnimations); +RAY::Cache<::ModelAnimation> RAY::ModelAnimations::_animationsCache([] (const char *str, int *counter) { + ::ModelAnimation *modelanimations = LoadModelAnimations(str, counter); + + if (modelanimations == nullptr) + throw Exception::ResourceNotFound(std::string(str)); + return modelanimations; + }, UnloadModelAnimations); RAY::ModelAnimations::ModelAnimations(const std::string &filePath): _animationsPtr(_animationsCache.fetch(filePath, &this->_animationCount)), diff --git a/lib/Ray/sources/Window.cpp b/lib/Ray/sources/Window.cpp index 8a41d850..ec856fca 100644 --- a/lib/Ray/sources/Window.cpp +++ b/lib/Ray/sources/Window.cpp @@ -70,11 +70,21 @@ bool RAY::Window::isFocused(void) const return IsWindowFocused(); } -const RAY::Vector2 &RAY::Window::getDimensions(void) const +const RAY::Vector2 &RAY::Window::getDimensions(void) { + this->_dimensions.x = GetScreenWidth(); + this->_dimensions.y = GetScreenHeight(); return this->_dimensions; } +RAY::Window &RAY::Window::setDimensions(const Vector2 &dims) +{ + this->_dimensions = dims; + if (this->_isOpen) + SetWindowSize(dims.x, dims.y); + return *this; +} + void RAY::Window::setVisibleCursor(bool visible) { if (visible) @@ -184,4 +194,40 @@ bool RAY::Window::isReady() const void RAY::Window::setExitKey(RAY::Controller::Keyboard::Key key) { SetExitKey(key); +} + +unsigned RAY::Window::getConfigFlags(void) const +{ + return this->_flags; +} + +bool RAY::Window::isFullscreen(void) const +{ + return IsWindowFullscreen(); +} + +RAY::Window &RAY::Window::setConfigFlags(unsigned flags) +{ + if (this->_isOpen) + SetWindowState(flags); + this->_flags = flags; + return *this; +} + +RAY::Window &RAY::Window::toggleFullscreen() +{ + ToggleFullscreen(); + return *this; +} + +RAY::Window &RAY::Window::maximize() +{ + MaximizeWindow(); + return *this; +} + +RAY::Window &RAY::Window::restore() +{ + RestoreWindow(); + return *this; } \ No newline at end of file diff --git a/lib/Ray/sources/Window.hpp b/lib/Ray/sources/Window.hpp index 525f2992..b8370719 100644 --- a/lib/Ray/sources/Window.hpp +++ b/lib/Ray/sources/Window.hpp @@ -64,8 +64,11 @@ namespace RAY { //! @brief Check if window is currently focused bool isFocused(void) const; + //! @brief Get window dimensions + const RAY::Vector2 &getDimensions(void); + //! @brief Set window dimensions - const RAY::Vector2 &getDimensions(void) const; + RAY::Window &setDimensions(const Vector2 &dims); //! @brief Set the cursor visibility //! @param visible True if the cursor is visible @@ -136,6 +139,23 @@ namespace RAY { //! @info Calling this function override the previous closing key void setExitKey(Controller::Keyboard::Key key); + //! @return the configuration flgs for the window + unsigned getConfigFlags(void) const; + + //! @param flag the configuration flgs for the window + RAY::Window &setConfigFlags(unsigned flags); + + //! @brief set window to fullscreen + RAY::Window &toggleFullscreen(); + + //! @return true if the window is fullscreen + bool isFullscreen(void) const; + + //! @brief set window to max size + RAY::Window &maximize(); + + //! @brief reset window size + RAY::Window &restore(); private: //! @brief Creates window, and opens it if openNow is set to true diff --git a/lib/wal/sources/Entity/Entity.hpp b/lib/wal/sources/Entity/Entity.hpp index 2e8905ed..7f1a5b21 100644 --- a/lib/wal/sources/Entity/Entity.hpp +++ b/lib/wal/sources/Entity/Entity.hpp @@ -146,7 +146,7 @@ namespace WAL { const std::type_index &type = typeid(T); if (this->hasComponent(type)) - throw DuplicateError("A component of the type \"" + std::string(type.name()) + "\" already exists."); + throw DuplicateError("A component of the type \"" + std::string(type.name()) + "\" already exists on " + this->_name + "."); this->_components[type] = std::make_unique(*this, TypeHolder()..., std::forward(params)...); if (this->_notifyScene) this->_componentAdded(type); diff --git a/lib/wal/sources/System/System.hpp b/lib/wal/sources/System/System.hpp index 88a1c73b..2d7f544c 100644 --- a/lib/wal/sources/System/System.hpp +++ b/lib/wal/sources/System/System.hpp @@ -44,7 +44,8 @@ namespace WAL virtual void onFixedUpdate(ViewEntity &entity) {} //! @brief A method called after all entities that this system manage has been updated. - virtual void onSelfUpdate() {} + //! @param dtime The delta time. + virtual void onSelfUpdate(std::chrono::nanoseconds dtime) {} //! @brief Update the whole system (every entities that this system is responsible can be updated. @@ -53,7 +54,7 @@ namespace WAL { for (auto &entity : this->getView()) this->onUpdate(entity, dtime); - this->onSelfUpdate(); + this->onSelfUpdate(dtime); } //! @brief An alternative of update that is called every 8ms (120 times per seconds). If the system slow down, it will try to catch up. diff --git a/screenshot000.png b/screenshot000.png deleted file mode 100644 index e4060bf1..00000000 Binary files a/screenshot000.png and /dev/null differ diff --git a/sources/Component/Bomb/BasicBombComponent.cpp b/sources/Component/Bomb/BasicBombComponent.cpp index 97cbb70d..9de464d7 100644 --- a/sources/Component/Bomb/BasicBombComponent.cpp +++ b/sources/Component/Bomb/BasicBombComponent.cpp @@ -4,17 +4,19 @@ #include "BasicBombComponent.hpp" +#include + namespace BBM { - BasicBombComponent::BasicBombComponent(WAL::Entity &entity, int damage, int explosionRadius, unsigned ownerID) - : WAL::Component(entity), - damage(damage), - explosionRadius(explosionRadius), - ownerID(ownerID) + BasicBombComponent::BasicBombComponent(WAL::Entity &entity, int damage, int explosionRadius, std::vector ignored) + : WAL::Component(entity), + damage(damage), + explosionRadius(explosionRadius), + ignoredEntities(std::move(ignored)) {} WAL::Component *BasicBombComponent::clone(WAL::Entity &entity) const { - return new BasicBombComponent(entity, this->damage, this->explosionRadius, this->ownerID); + return new BasicBombComponent(entity, this->damage, this->explosionRadius, this->ignoredEntities); } } \ No newline at end of file diff --git a/sources/Component/Bomb/BasicBombComponent.hpp b/sources/Component/Bomb/BasicBombComponent.hpp index 1b9b46bf..5d3838c8 100644 --- a/sources/Component/Bomb/BasicBombComponent.hpp +++ b/sources/Component/Bomb/BasicBombComponent.hpp @@ -19,16 +19,14 @@ namespace BBM const int explosionRadius = 3; //! @brief The damage made by the explosion on an entity const int damage = 1; - //! @brief The ID of the owner. - unsigned ownerID; - //! @brief Should collisions with the owner be disabled.² - bool ignoreOwner = true; + //! @brief The list of IDs of ignored entities. + std::vector ignoredEntities; //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; //! @brief A component can't be instantiated, it should be derived. - explicit BasicBombComponent(WAL::Entity &entity, int damage, int explosionRadius, unsigned ownerID); + explicit BasicBombComponent(WAL::Entity &entity, int damage, int explosionRadius, std::vector ignored); //! @brief A component can't be instantiated, it should be derived. BasicBombComponent(const BasicBombComponent &) = default; diff --git a/sources/Component/Collision/CollisionComponent.cpp b/sources/Component/Collision/CollisionComponent.cpp index 652e6727..759e6d21 100644 --- a/sources/Component/Collision/CollisionComponent.cpp +++ b/sources/Component/Collision/CollisionComponent.cpp @@ -54,4 +54,20 @@ namespace BBM bound({boundSize, boundSize, boundSize}), positionOffset({positionOffset, positionOffset, positionOffset}) {} + + CollisionComponent::CollidedAxis operator|(CollisionComponent::CollidedAxis first, + CollisionComponent::CollidedAxis second) + { + return static_cast(static_cast(first) | static_cast(second)); + } + + CollisionComponent::CollidedAxis &operator|=(CollisionComponent::CollidedAxis &self, + CollisionComponent::CollidedAxis other) + { + int &selfI = reinterpret_cast(self); + int otherI = static_cast(other); + + selfI |= otherI; + return reinterpret_cast(selfI); + } } \ No newline at end of file diff --git a/sources/Component/Collision/CollisionComponent.hpp b/sources/Component/Collision/CollisionComponent.hpp index 0190a56a..e50b4ead 100644 --- a/sources/Component/Collision/CollisionComponent.hpp +++ b/sources/Component/Collision/CollisionComponent.hpp @@ -17,6 +17,7 @@ namespace BBM //! @brief Used to tell the collided axis //! @note Usage: (collidedAxis (int given by callback)) & CollidedAxis::X enum CollidedAxis { + NONE = 0, X = 1, Y = 2, Z = 4, @@ -73,4 +74,7 @@ namespace BBM //! @brief A component can't be assigned CollisionComponent &operator=(const CollisionComponent &) = delete; }; + + CollisionComponent::CollidedAxis operator|(CollisionComponent::CollidedAxis first, CollisionComponent::CollidedAxis second); + CollisionComponent::CollidedAxis &operator|=(CollisionComponent::CollidedAxis &self, CollisionComponent::CollidedAxis other); } \ No newline at end of file diff --git a/sources/Component/IAControllable/IAControllableComponent.cpp b/sources/Component/IAControllable/IAControllableComponent.cpp new file mode 100644 index 00000000..05f6eb9b --- /dev/null +++ b/sources/Component/IAControllable/IAControllableComponent.cpp @@ -0,0 +1,26 @@ +/* +** EPITECH PROJECT, 2021 +** Bomberman +** File description: +** IAControllableComponent +*/ + +#include +#include "Map/MapInfo.hpp" +#include "Component/IAControllable/IAControllableComponent.hpp" + +namespace BBM +{ + IAControllableComponent::IAControllableComponent(WAL::Entity &entity, std::string scriptPath) + : Component(entity), _scriptPath(scriptPath), _state() + { + if (std::filesystem::exists(scriptPath)) + _state.dofile(scriptPath); + } + + WAL::Component *IAControllableComponent::clone(WAL::Entity &entity) const + { + return new IAControllableComponent(entity, _scriptPath); + } + +} diff --git a/sources/Component/IAControllable/IAControllableComponent.hpp b/sources/Component/IAControllable/IAControllableComponent.hpp new file mode 100644 index 00000000..a1556662 --- /dev/null +++ b/sources/Component/IAControllable/IAControllableComponent.hpp @@ -0,0 +1,47 @@ +/* +** EPITECH PROJECT, 2021 +** Bomberman +** File description: +** IAComponent +*/ + +#ifndef IACOMPONENT_HPP_ +#define IACOMPONENT_HPP_ + +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" +#include "Models/Vector3.hpp" +#include "LuaGate.hpp" + +namespace BBM +{ + class IAControllableComponent : public WAL::Component + { + private: + //! @brief path to the lua script + const std::string _scriptPath; + public: + + //! @brief LuaGate state + LuaG::State _state; + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief Constructor + IAControllableComponent(WAL::Entity &entity, std::string scripPath); + + //! @brief A IA component can't be instantiated, it should be derived. + IAControllableComponent(const IAControllableComponent &) = default; + + //! @brief default destructor + ~IAControllableComponent() override = default; + + //! @brief A IA component can't be assigned + IAControllableComponent &operator=(const IAControllableComponent &) = delete; + protected: + }; +} + + +#endif /* !IACOMPONENT_HPP_ */ diff --git a/sources/Component/Tag/TagComponent.hpp b/sources/Component/Tag/TagComponent.hpp index c4b3b9c1..9775c06d 100644 --- a/sources/Component/Tag/TagComponent.hpp +++ b/sources/Component/Tag/TagComponent.hpp @@ -52,6 +52,12 @@ namespace BBM // interact with bombs & stop the explosion constexpr const char Blowable[] = "Blowable"; + // interact with visual features like camera + constexpr const char Player[] = "Player"; + constexpr const char Unbreakable[] = "Unbreakable"; + constexpr const char Breakable[] = "Breakable"; + constexpr const char Hole[] = "Hole"; + constexpr const char Bumper[] = "Bumper"; // interact with bombs (getting damage etc) but doesn't stop explosion constexpr const char BlowablePass[] = "BlowablePass"; } diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index 17266a5f..c7f9049c 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -2,6 +2,7 @@ // Created by HENRY Benjamin on 02/06/2021. // +#include #include #include #include @@ -20,6 +21,7 @@ namespace BBM { if (!bombHolder) return; bombHolder->maxBombCount++; + const_cast(bonus).scheduleDeletion(); } void Bonus::ExplosionRangeBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) @@ -31,6 +33,7 @@ namespace BBM { if (!bombHolder || !playerBonus) return; bombHolder->explosionRadius++; + const_cast(bonus).scheduleDeletion(); } void Bonus::SpeedUpBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) @@ -42,6 +45,7 @@ namespace BBM { if (!controllable || !playerBonus) return; controllable->speed += 0.025f; + const_cast(bonus).scheduleDeletion(); } void Bonus::NoClipBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) @@ -53,6 +57,7 @@ namespace BBM { return; playerBonus->nextNoClipRate = playerBonus->noClipBonusRate; playerBonus->isNoClipOn = true; + const_cast(bonus).scheduleDeletion(); } Bonus::BonusType Bonus::getRandomBonusType() diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index cf3fcf79..4ff7a9d7 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -143,6 +143,7 @@ namespace BBM scene->addEntity("Unbreakable Wall") .addComponent(i, 0, j) .addComponent>() + .addComponent>() .addComponent( WAL::Callback(), &MapGenerator::wallCollided, 0.25, .75) @@ -248,6 +249,7 @@ namespace BBM scene->addEntity("Breakable Block") .addComponent(coords) .addComponent>() + .addComponent>() .addComponent(1, &MapGenerator::wallDestroyed) .addComponent( WAL::Callback(), @@ -274,6 +276,7 @@ namespace BBM scene->addEntity("Unbreakable Block") .addComponent(coords) .addComponent>() + .addComponent>() .addComponent( WAL::Callback(), &MapGenerator::wallCollided, 0.25, .75) @@ -291,11 +294,12 @@ namespace BBM WAL::Entity &holeEntity = scene->addEntity("Hole Block"); holeEntity.addComponent(Vector3f(coords.x, coords.y - 1, coords.z)) + .addComponent>() .addComponent( WAL::Callback(), &MapGenerator::holeCollide, Vector3f(0.25, 0.25, 0.25),Vector3f(0.75, 1.75, 0.75)); if (coords.y == 0) - holeEntity.addComponent(holeObj, false, std::make_pair(MAP_DIFFUSE, holePng)); + holeEntity.addComponent(holeObj, false, std::make_pair(MAP_DIFFUSE, holePng), Vector3f(1,1,1), 180); else holeEntity.addComponent(secondFloorObj, false, std::make_pair(MAP_DIFFUSE, secondFloorPng)); @@ -309,7 +313,8 @@ namespace BBM scene->addEntity("Bumper Block") .addComponent(Vector3f(coords.x, coords.y, coords.z)) - .addComponent(bumperObj, false,std::make_pair(MAP_DIFFUSE, bumperPng)) + .addComponent>() + .addComponent(bumperObj, false, std::make_pair(MAP_DIFFUSE, bumperPng)) .addComponent( WAL::Callback(), &MapGenerator::bumperCollide, Vector3f(0.25, 0.25, 0.25),Vector3f(0.75, 0.75, 0.75)); diff --git a/sources/Map/MapInfo.cpp b/sources/Map/MapInfo.cpp new file mode 100644 index 00000000..f7c8f7c8 --- /dev/null +++ b/sources/Map/MapInfo.cpp @@ -0,0 +1,25 @@ +// +// Created by Louis Auzuret 09/06/21 +// + +#include "MapInfo.hpp" + +namespace BBM +{ + MapInfo::MapInfo(Vector3f pos, MapGenerator::BlockType type) + : x(pos.x), y(pos.y), z(pos.z), type(type) + { } + + MapInfo::MapInfo(const MapInfo &other) + : x(other.x), y(other.y), z(other.z), type(other.type) + { } + + MapInfo &MapInfo::operator=(MapInfo &other) + { + this->x = other.x; + this->y = other.y; + this->z = other.z; + this->type = other.type; + return *this; + } +} \ No newline at end of file diff --git a/sources/Map/MapInfo.hpp b/sources/Map/MapInfo.hpp new file mode 100644 index 00000000..78d10a83 --- /dev/null +++ b/sources/Map/MapInfo.hpp @@ -0,0 +1,37 @@ +// +// Created by Louis Auzuret on 09/06/21 +// + +#include "Map.hpp" + +namespace BBM +{ + class MapInfo + { + private: + public: + //! @brief Position on the x axis + float x; + + //! @brief Position on the y axis + float y; + + //! @brief Position on the z axis + float z; + + //! @brief Type of the block + int type; + + //! @brief Constructor + MapInfo(Vector3f pos, MapGenerator::BlockType type); + + //! @brief Default destructor + ~MapInfo() = default; + + //! @brief Default copy constructor + MapInfo(const MapInfo &); + + //! @brief Assignment operator + MapInfo &operator=(MapInfo &); + }; +} \ No newline at end of file diff --git a/sources/Models/Vector3.hpp b/sources/Models/Vector3.hpp index d1d1d919..3f6ef2cf 100644 --- a/sources/Models/Vector3.hpp +++ b/sources/Models/Vector3.hpp @@ -135,7 +135,7 @@ namespace BBM double magnitude() const { - return (std::sqrt(std::pow(this->x, 2) + std::pow(this->y, 2), std::pow(this->z, 2))); + return (std::sqrt(std::pow(this->x, 2) + std::pow(this->y, 2) + std::pow(this->z, 2))); } Vector3 normalize() @@ -168,6 +168,11 @@ namespace BBM return (point * this) / std::pow(this->magnitude(), 2) * this; } + Vector3 abs() const + { + return Vector3(std::abs(this->x), std::abs(this->y), std::abs(this->z)); + } + Vector3 trunc() const requires(std::is_floating_point_v) { return Vector3(std::trunc(this->x), std::trunc(this->y), std::trunc(this->z)); diff --git a/sources/Runner/CreditScene.cpp b/sources/Runner/CreditScene.cpp index fa77c9ff..a0dfb539 100644 --- a/sources/Runner/CreditScene.cpp +++ b/sources/Runner/CreditScene.cpp @@ -23,7 +23,7 @@ namespace BBM {SoundComponent::JUMP, "assets/sounds/click.ogg"} }; - addMenuControl(*scene); + addMenuControl(*scene, sounds); scene->addEntity("background") .addComponent() .addComponent("assets/plain_menu_background.png"); diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index 1a967149..daad8c57 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -22,8 +22,6 @@ #include "Component/Renderer/Drawable2DComponent.hpp" #include #include "Drawables/2D/Text.hpp" -#include "Component/Renderer/Drawable2DComponent.hpp" -#include "Component/Button/ButtonComponent.hpp" #include "Drawables/Texture.hpp" #include "Component/Gravity/GravityComponent.hpp" #include "Component/BumperTimer/BumperTimerComponent.hpp" @@ -31,7 +29,6 @@ #include "Model/Model.hpp" #include "Map/Map.hpp" #include "Component/Score/ScoreComponent.hpp" -#include "Drawables/2D/Text.hpp" namespace RAY3D = RAY::Drawables::Drawables3D; namespace RAY2D = RAY::Drawables::Drawables2D; @@ -42,7 +39,7 @@ namespace BBM { auto scene = std::make_shared(); scene->addEntity("camera") - .addComponent(8, 20, 7) + .addComponent(8, 0, -5) .addComponent(Vector3f(8, 0, 8)); scene->addEntity("Timer") .addComponent(std::chrono::minutes (3), [](WAL::Entity &, WAL::Wal &) { @@ -51,7 +48,7 @@ namespace BBM .addComponent(1920 / 2 - 2 * 30, 30, 0) .addComponent("", 60, RAY::Vector2(), ORANGE); scene->addEntity("background image") - .addComponent(true, "assets/background_game.png", false) + .addComponent(true, "assets/background.png", false) .addComponent(); return scene; } @@ -68,12 +65,12 @@ namespace BBM return scene.addEntity("Player") .addComponent() .addComponent("assets/player/player.iqm", true) - .addComponent() .addComponent() .addComponent() .addComponent() .addComponent() .addComponent>() + .addComponent>() .addComponent("assets/player/player.iqm", 3) .addComponent(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75}) .addComponent() @@ -83,7 +80,15 @@ namespace BBM .addComponent() .addComponent(1, [](WAL::Entity &entity, WAL::Wal &) { auto &animation = entity.getComponent(); + animation.setAnimIndex(5); + if (entity.hasComponent()) + entity.removeComponent(); + if (entity.hasComponent()) + return; + entity.addComponent(1s, [](WAL::Entity &entity, WAL::Wal &wal) { + entity.scheduleDeletion(); + }); }); } } \ No newline at end of file diff --git a/sources/Runner/HowToPlayScene.cpp b/sources/Runner/HowToPlayScene.cpp index cfb2cb7e..782a70c0 100644 --- a/sources/Runner/HowToPlayScene.cpp +++ b/sources/Runner/HowToPlayScene.cpp @@ -22,7 +22,7 @@ namespace BBM {SoundComponent::JUMP, "assets/sounds/click.ogg"} }; - addMenuControl(*scene); + addMenuControl(*scene, sounds); scene->addEntity("Control entity") .addComponent("assets/musics/music_player_select.ogg") .addComponent(sounds); diff --git a/sources/Runner/LobbyScene.cpp b/sources/Runner/LobbyScene.cpp index 7254006e..6c0f6f3a 100644 --- a/sources/Runner/LobbyScene.cpp +++ b/sources/Runner/LobbyScene.cpp @@ -33,7 +33,7 @@ namespace BBM }; auto scene = std::make_shared(); - addMenuControl(*scene); + addMenuControl(*scene, sounds); scene->addEntity("Control entity") .addComponent("assets/musics/music_player_select.ogg") .addComponent(sounds); @@ -196,11 +196,11 @@ namespace BBM auto &ready = scene->addEntity("ready") .addComponent(224 * (i + 1) + 200 * i, 1080 / 3, 0) // todo check why it does this | hacky way to fix ready texture - .addComponent(""); + .addComponent(); player.addComponent(i, ready, playerTile); } scene->addEntity("camera") - .addComponent(8, 20, 7) + .addComponent(-5, 0, -5) .addComponent(Vector3f(8, 0, 8)); play.getComponent().setButtonLinks(&lavaOption, &back, &back, &howToPlay); howToPlay.getComponent().setButtonLinks(&play, nullptr, &play); diff --git a/sources/Runner/MainMenuScene.cpp b/sources/Runner/MainMenuScene.cpp index 329e6129..ab678654 100644 --- a/sources/Runner/MainMenuScene.cpp +++ b/sources/Runner/MainMenuScene.cpp @@ -25,7 +25,7 @@ namespace BBM }; auto scene = std::make_shared(); - addMenuControl(*scene); + addMenuControl(*scene, sounds); scene->addEntity("Control entity") .addComponent("assets/musics/music_title.ogg") .addComponent(sounds); diff --git a/sources/Runner/PauseMenuScene.cpp b/sources/Runner/PauseMenuScene.cpp index 77b7dc21..d6886a87 100644 --- a/sources/Runner/PauseMenuScene.cpp +++ b/sources/Runner/PauseMenuScene.cpp @@ -25,7 +25,7 @@ namespace BBM }; auto scene = std::make_shared(); - addMenuControl(*scene); + addMenuControl(*scene, sounds); scene->addEntity("Control entity") .addComponent("assets/musics/music_player_select.ogg") .addComponent(sounds); diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 4ed81f40..cf45bce3 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -12,6 +12,14 @@ #include "System/Controllable/ControllableSystem.hpp" #include "System/Gamepad/GamepadSystem.hpp" #include +#include "Component/Button/ButtonComponent.hpp" +#include +#include +#include +#include +#include +#include "Component/Renderer/CameraComponent.hpp" +#include "Component/Renderer/Drawable3DComponent.hpp" #include "Component/Renderer/Drawable2DComponent.hpp" #include "Runner.hpp" #include "Models/GameState.hpp" @@ -30,6 +38,7 @@ #include "System/Shaders/ShaderModelSystem.hpp" #include "System/Animation/AnimationsSystem.hpp" #include "Map/Map.hpp" +#include "System/IAControllable/IAControllableSystem.hpp" #include "System/MenuControllable/MenuControllableSystem.hpp" #include #include @@ -38,6 +47,7 @@ #include "System/Gravity/GravitySystem.hpp" #include "System/BumperTimer/BumperTimerSystem.hpp" #include "System/Music/MusicSystem.hpp" +#include "System/Renderer/CameraSystem.hpp" #include "System/Lobby/LobbySystem.hpp" #include "System/Score/ScoreSystem.hpp" #include "System/EndCondition/EndConditionSystem.hpp" @@ -79,6 +89,7 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem() .addSystem() .addSystem() @@ -101,29 +112,33 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem(); } void Runner::enableRaylib(WAL::Wal &wal) { RAY::TraceLog::setLevel(LOG_WARNING); - RAY::Window &window = RAY::Window::getInstance(1920, 1080, "Bomberman"); + RAY::Window &window = RAY::Window::getInstance(1280, 720, "Bomberman", FLAG_WINDOW_RESIZABLE); wal.addSystem() .addSystem() .addSystem(window); } - void Runner::addMenuControl(WAL::Scene &scene) + void Runner::addMenuControl(WAL::Scene &scene, const std::map &sounds) { scene.addEntity("Keyboard default control") .addComponent() + .addComponent(sounds) .addComponent(); scene.addEntity("Keyboard second control") .addComponent() + .addComponent(sounds) .addComponent(ControllableComponent::Layout::KEYBOARD_1); for (int i = 0; i < 4; i++) { scene.addEntity("Gamepad controller") .addComponent() + .addComponent(sounds) .addComponent(i); } } @@ -149,13 +164,7 @@ namespace BBM Runner::enableRaylib(wal); Runner::loadScenes(); wal.changeScene(Runner::gameState._loadedScenes[GameState::SceneID::SplashScreen]); - - try { - wal.run(Runner::updateState, Runner::gameState); - return 0; - } catch (const std::exception &ex) { - std::cerr << ex.what() << std::endl; - return 1; - } + wal.run(Runner::updateState, Runner::gameState); + return 0; } } \ No newline at end of file diff --git a/sources/Runner/Runner.hpp b/sources/Runner/Runner.hpp index 77fb51db..da023c97 100644 --- a/sources/Runner/Runner.hpp +++ b/sources/Runner/Runner.hpp @@ -5,6 +5,8 @@ #pragma once #include "Models/GameState.hpp" #include "Wal.hpp" +#include +#include "Component/Sound/SoundComponent.hpp" namespace BBM { @@ -35,7 +37,7 @@ namespace BBM //! @brief init all raylib-related data & context static void enableRaylib(WAL::Wal &wal); - static void addMenuControl(WAL::Scene &scene); + static void addMenuControl(WAL::Scene &scene, const std::map &sounds = {}); //! @brief load all data related to title screen static std::shared_ptr loadTitleScreenScene(); diff --git a/sources/Runner/ScoreScene.cpp b/sources/Runner/ScoreScene.cpp index 76a3008f..4f80babb 100644 --- a/sources/Runner/ScoreScene.cpp +++ b/sources/Runner/ScoreScene.cpp @@ -45,7 +45,7 @@ namespace BBM playersIconPath.push_back(path.replace(path.find("textures"), std::string("textures").size(), "icons")); } - addMenuControl(*scene); + addMenuControl(*scene, sounds); scene->addEntity("Audio ressources") .addComponent("assets/musics/music_result.ogg") .addComponent(sounds); diff --git a/sources/Runner/SettingsMenuScene.cpp b/sources/Runner/SettingsMenuScene.cpp index 8883bbeb..1fd24c48 100644 --- a/sources/Runner/SettingsMenuScene.cpp +++ b/sources/Runner/SettingsMenuScene.cpp @@ -24,7 +24,7 @@ namespace BBM {SoundComponent::JUMP, "assets/sounds/click.ogg"} }; - addMenuControl(*scene); + addMenuControl(*scene, sounds); scene->addEntity("Control entity") .addComponent("assets/musics/music_title.ogg") .addComponent(sounds); @@ -35,7 +35,7 @@ namespace BBM .addComponent(1920 / 3, 180, 0) .addComponent("assets/logo_small.png"); auto &music = scene->addEntity("music text") - .addComponent(1920 / 2.5, 1080 - 540, 0) + .addComponent(1920 / 2.5, 1080 - 100 - 540, 0) .addComponent("Music Volume", 70, RAY::Vector2(), BLACK) .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) @@ -48,7 +48,7 @@ namespace BBM }); auto &musicUp = scene->addEntity("music up button") - .addComponent(1920 / 1.5, 1080 - 540, 0) + .addComponent(1920 / 1.5, 1080 - 100 - 540, 0) .addComponent("assets/buttons/button_plus.png") .addComponent("assets/musics/music_title.ogg") .addComponent([](WAL::Entity &entity, WAL::Wal &) @@ -71,7 +71,7 @@ namespace BBM }); auto &musicDown = scene->addEntity("music down button") - .addComponent(1920 / 3, 1080 - 540, 0) + .addComponent(1920 / 3, 1080 - 100 - 540, 0) .addComponent("assets/buttons/button_minus.png") .addComponent("assets/musics/music_title.ogg") .addComponent([](WAL::Entity &entity, WAL::Wal &) @@ -94,7 +94,7 @@ namespace BBM }); auto &sound = scene->addEntity("sound text") - .addComponent(1920 / 2.5, 1080 - 360, 0) + .addComponent(1920 / 2.5, 1080 - 100 - 360, 0) .addComponent("Sound Volume", 70, RAY::Vector2(), BLACK) .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) @@ -107,9 +107,10 @@ namespace BBM }); auto &soundUp = scene->addEntity("sound up button") - .addComponent(1920 / 1.5, 1080 - 360, 0) + .addComponent(1920 / 1.5, 1080 - 100 - 360, 0) .addComponent("assets/buttons/button_plus.png") .addComponent(sounds) + .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) { auto &component = entity.getComponent(); @@ -130,9 +131,10 @@ namespace BBM }); auto &soundDown = scene->addEntity("sound down button") - .addComponent(1920 / 3, 1080 - 360, 0) + .addComponent(1920 / 3, 1080 - 100 - 360, 0) .addComponent("assets/buttons/button_minus.png") .addComponent(sounds) + .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); @@ -153,7 +155,7 @@ namespace BBM }); auto &debug = scene->addEntity("debug text") - .addComponent(1920 / 2.5, 1080 - 180, 0) + .addComponent(1920 / 2.5, 1080 - 100 - 180, 0) .addComponent("Debug Mode: Off", 70, RAY::Vector2(), BLACK) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { @@ -175,6 +177,31 @@ namespace BBM { entity.getComponent().drawable->setColor(ORANGE); }); + auto &fullscreen = scene->addEntity("fullscreen text") + .addComponent(1920 / 2.5, 1080 - 100 - 50, 0) + .addComponent("Fullscreen: Off", 70, RAY::Vector2(), BLACK) + .addComponent([](WAL::Entity &entity, WAL::Wal &wal) + { + RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); + RAY::Window &window = RAY::Window::getInstance(); + + if (text->getString().find("Off") != std::string::npos) { + text->setText("Fullscreen: On"); + window.setDimensions(RAY::Vector2(1920, 1080)); + } else { + text->setText("Fullscreen: Off"); + window.setDimensions(RAY::Vector2(1280, 720)); + } + window.toggleFullscreen(); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + entity.getComponent().drawable->setColor(BLACK); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + entity.getComponent().drawable->setColor(ORANGE); + }); auto &back = scene->addEntity("back to menu") .addComponent(10, 1080 - 85, 0) .addComponent("assets/buttons/button_back.png") @@ -204,8 +231,9 @@ namespace BBM sound.getComponent().setButtonLinks(&music, &debug, &soundDown, &soundUp); soundDown.getComponent().setButtonLinks(&music, &debug, nullptr, &sound); soundUp.getComponent().setButtonLinks(&music, &debug, &sound); - debug.getComponent().setButtonLinks(&sound, &back, &back); - back.getComponent().setButtonLinks(&debug, nullptr, nullptr, &debug); + debug.getComponent().setButtonLinks(&sound, &fullscreen); + fullscreen.getComponent().setButtonLinks(&debug, &back, &back); + back.getComponent().setButtonLinks(&fullscreen, nullptr, nullptr, &fullscreen); return scene; } } \ No newline at end of file diff --git a/sources/Runner/TitleScreenScene.cpp b/sources/Runner/TitleScreenScene.cpp index 729434f3..defa265e 100644 --- a/sources/Runner/TitleScreenScene.cpp +++ b/sources/Runner/TitleScreenScene.cpp @@ -22,7 +22,7 @@ namespace BBM {SoundComponent::JUMP, "assets/sounds/click.ogg"} }; auto scene = std::make_shared(); - addMenuControl(*scene); + addMenuControl(*scene, sounds); scene->addEntity("control") .addComponent(sounds) .addComponent("assets/musics/music_title.ogg"); diff --git a/sources/System/Animator/AnimatorSystem.cpp b/sources/System/Animator/AnimatorSystem.cpp index f03aeb9b..23f312dc 100644 --- a/sources/System/Animator/AnimatorSystem.cpp +++ b/sources/System/Animator/AnimatorSystem.cpp @@ -10,6 +10,7 @@ #include #include "AnimatorSystem.hpp" #include "Component/Renderer/Drawable3DComponent.hpp" +#include "Component/Health/HealthComponent.hpp" using Keyboard = RAY::Controller::Keyboard; namespace RAY3D = RAY::Drawables::Drawables3D; @@ -27,6 +28,10 @@ namespace BBM auto drawable = entity.get().drawable.get(); auto &animation = entity.get(); auto anim = dynamic_cast(drawable); + auto health = entity->tryGetComponent(); + + if (health && health->getHealthPoint() <= 0 || entity->shouldDelete()) + return; if (anim && controllable.move != Vector2f(0, 0)) { anim->setRotationAngle(controllable.move.angle(Vector2f(-1, 0))); animation.setAnimIndex(0); diff --git a/sources/System/Bomb/BombSystem.cpp b/sources/System/Bomb/BombSystem.cpp index 60ff5a30..39b7698b 100644 --- a/sources/System/Bomb/BombSystem.cpp +++ b/sources/System/Bomb/BombSystem.cpp @@ -14,15 +14,16 @@ namespace BBM void BombSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) { auto &bomb = entity.get(); - if (!bomb.ignoreOwner) + + if (bomb.ignoredEntities.empty()) return; + auto &pos = entity.get(); for (auto &[owner, ownerPos, _] : this->_wal.getScene()->view()) { - if (owner.getUid() != bomb.ownerID) - continue; if (pos.position.distance(ownerPos.position) >= 1.1) { - bomb.ignoreOwner = false; - return; + bomb.ignoredEntities.erase( + std::remove(bomb.ignoredEntities.begin(), bomb.ignoredEntities.end(), owner.getUid()), + bomb.ignoredEntities.end()); } } } diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index 0a69c435..02ed40aa 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -2,7 +2,6 @@ // Created by Zoe Roux on 5/31/21. // -#include #include #include "Component/Timer/TimerComponent.hpp" #include "System/Event/EventSystem.hpp" @@ -31,7 +30,8 @@ namespace BBM CollisionComponent::CollidedAxis collidedAxis) { auto &bombInfo = bomb.getComponent(); - if (bombInfo.ignoreOwner && bombInfo.ownerID == entity.getUid()) + auto found = std::find(bombInfo.ignoredEntities.begin(), bombInfo.ignoredEntities.end(), entity.getUid()); + if (found != bombInfo.ignoredEntities.end()) return; return MapGenerator::wallCollided(entity, bomb, collidedAxis); } @@ -115,10 +115,17 @@ namespace BBM _dispatchExplosion(position, wal, explosionRadius); } - void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id) + void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder) { + std::vector overlapping; + + for (auto &[entity, pos, _] : this->_wal.getScene()->view()) { + if (position.distance(pos.position) <= 1.1) + overlapping.emplace_back(entity.getUid()); + } + this->_wal.getScene()->scheduleNewEntity("Bomb") - .addComponent(position.round()) + .addComponent(position) .addComponent(1, [](WAL::Entity &entity, WAL::Wal &wal) { // the bomb explode when hit entity.scheduleDeletion(); @@ -154,7 +161,7 @@ namespace BBM }) .addComponent() .addComponent>() - .addComponent(holder.damage, holder.explosionRadius, id) + .addComponent(holder.damage, holder.explosionRadius, overlapping) .addComponent(BombHolderSystem::explosionTimer, &BombHolderSystem::_bombExplosion) .addComponent( WAL::Callback(), @@ -166,18 +173,13 @@ namespace BBM )); } - void - BombHolderSystem::onUpdate(WAL::ViewEntity &entity, - std::chrono::nanoseconds dtime) + void BombHolderSystem::onUpdate(WAL::ViewEntity &entity, + std::chrono::nanoseconds dtime) { auto &holder = entity.get(); auto &position = entity.get(); auto &controllable = entity.get(); - if (controllable.bomb && holder.bombCount > 0) { - holder.bombCount--; - this->_spawnBomb(position.position, holder, entity->getUid()); - } if (holder.bombCount < holder.maxBombCount) { holder.nextBombRefill -= dtime; if (holder.nextBombRefill <= 0ns) { @@ -185,5 +187,14 @@ namespace BBM holder.bombCount++; } } + if (controllable.bomb && holder.bombCount > 0) { + auto spawnPos = position.position.round(); + for (auto &[entity, pos, _] : this->_wal.getScene()->view()) { + if (pos.position == spawnPos) + return; + } + holder.bombCount--; + this->_spawnBomb(spawnPos, holder); + } } } \ No newline at end of file diff --git a/sources/System/BombHolder/BombHolderSystem.hpp b/sources/System/BombHolder/BombHolderSystem.hpp index c5631190..9ba67f2b 100644 --- a/sources/System/BombHolder/BombHolderSystem.hpp +++ b/sources/System/BombHolder/BombHolderSystem.hpp @@ -35,7 +35,7 @@ namespace BBM { private: //! @brief Spawn a bomb at the specified position. - void _spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id); + void _spawnBomb(Vector3f position, BombHolderComponent &holder); //! @brief Spawn a bomb at the specified position. static void _dispatchExplosion(const Vector3f &position, diff --git a/sources/System/Collision/CollisionSystem.cpp b/sources/System/Collision/CollisionSystem.cpp index f2604254..85e0e009 100644 --- a/sources/System/Collision/CollisionSystem.cpp +++ b/sources/System/Collision/CollisionSystem.cpp @@ -7,7 +7,6 @@ #include "Component/Collision/CollisionComponent.hpp" #include "System/Collision/CollisionSystem.hpp" #include "Scene/Scene.hpp" - namespace BBM { CollisionSystem::CollisionSystem(WAL::Wal &wal) @@ -64,25 +63,25 @@ namespace BBM continue; auto pointB = posB.position + colB.positionOffset; - int collidedAxis = 0; + CollisionComponent::CollidedAxis collidedAxis = CollisionComponent::NONE; // TODO if B is also a movable we don't check with it's changing position Vector3f minB = Vector3f::min(pointB, pointB + colB.bound); Vector3f maxB = Vector3f::max(pointB, pointB + colB.bound); if (boxesCollide(minAx, maxAx, minB, maxB)) { - collidedAxis += vel.isNull() ? 7 : CollisionComponent::CollidedAxis::X; + collidedAxis |= vel.isNull() ? CollisionComponent::ALL : CollisionComponent::X; } if (!vel.isNull()) { if (boxesCollide(minAy, maxAy, minB, maxB)) { - collidedAxis += CollisionComponent::CollidedAxis::Y; + collidedAxis |= CollisionComponent::Y; } if (boxesCollide(minAz, maxAz, minB, maxB)) { - collidedAxis += CollisionComponent::CollidedAxis::Z; + collidedAxis |= CollisionComponent::Z; } } if (collidedAxis) { - colA.onCollide(entity, other, static_cast(collidedAxis)); - colB.onCollided(entity, other, static_cast(collidedAxis)); + colA.onCollide(entity, other, collidedAxis); + colB.onCollided(entity, other, collidedAxis); } } } diff --git a/sources/System/Controllable/ControllableSystem.cpp b/sources/System/Controllable/ControllableSystem.cpp index 6916de9f..36e9815a 100644 --- a/sources/System/Controllable/ControllableSystem.cpp +++ b/sources/System/Controllable/ControllableSystem.cpp @@ -6,6 +6,7 @@ #include "ControllableSystem.hpp" #include "Component/Movable/MovableComponent.hpp" #include "Component/Controllable/ControllableComponent.hpp" +#include "Component/Health/HealthComponent.hpp" #include "Entity/Entity.hpp" namespace BBM @@ -18,8 +19,11 @@ namespace BBM { auto &controllable = entity.get(); auto &movable = entity.get(); + auto health = entity->tryGetComponent(); Vector2f move = controllable.move.normalized() * controllable.speed; + if (health && health->getHealthPoint() <= 0) + return; movable.addForce(Vector3f(move.x, 0, move.y)); } } \ No newline at end of file diff --git a/sources/System/EndCondition/EndConditionSystem.cpp b/sources/System/EndCondition/EndConditionSystem.cpp index fdabe35a..93ea2003 100644 --- a/sources/System/EndCondition/EndConditionSystem.cpp +++ b/sources/System/EndCondition/EndConditionSystem.cpp @@ -11,7 +11,7 @@ namespace BBM : System(wal) {} - void EndConditionSystem::onSelfUpdate() + void EndConditionSystem::onSelfUpdate(std::chrono::nanoseconds dtime) { unsigned int alivePlayersCount = 0; auto &view = this->_wal.getScene()->view(); @@ -20,7 +20,12 @@ namespace BBM return; for (auto &[_, scoreComponent, healthComponent]: view) alivePlayersCount += (healthComponent.getHealthPoint() != 0); - if (alivePlayersCount <= 1) - Runner::gameState.nextScene = Runner::gameState.ScoreScene; + if (alivePlayersCount <= 1) { + endConditionRate -= dtime; + if (endConditionRate <= 0ns) { + Runner::gameState.nextScene = Runner::gameState.ScoreScene; + endConditionRate = 500ms; + } + } } } \ No newline at end of file diff --git a/sources/System/EndCondition/EndConditionSystem.hpp b/sources/System/EndCondition/EndConditionSystem.hpp index edd3a9d7..38d1dc5a 100644 --- a/sources/System/EndCondition/EndConditionSystem.hpp +++ b/sources/System/EndCondition/EndConditionSystem.hpp @@ -5,14 +5,19 @@ #include "Component/Score/ScoreComponent.hpp" #include "Component/Health/HealthComponent.hpp" #include "Wal.hpp" +#include + +using namespace std::chrono_literals; namespace BBM { class EndConditionSystem : public WAL::System { public: + std::chrono::nanoseconds endConditionRate = 500ms; + //! @inherit - void onSelfUpdate() override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @brief ctor EndConditionSystem(WAL::Wal &wal); diff --git a/sources/System/Event/EventSystem.cpp b/sources/System/Event/EventSystem.cpp index da683dec..71f7d204 100644 --- a/sources/System/Event/EventSystem.cpp +++ b/sources/System/Event/EventSystem.cpp @@ -26,7 +26,7 @@ namespace BBM event(entity); } - void EventSystem::onSelfUpdate() + void EventSystem::onSelfUpdate(std::chrono::nanoseconds dtime) { for (auto &event : this->_globalEvents) event(this->_wal); diff --git a/sources/System/Event/EventSystem.hpp b/sources/System/Event/EventSystem.hpp index bcdb14c0..9d4cdfdb 100644 --- a/sources/System/Event/EventSystem.hpp +++ b/sources/System/Event/EventSystem.hpp @@ -27,7 +27,7 @@ namespace BBM //! @inherit void onUpdate(WAL::ViewEntity<> &entity, std::chrono::nanoseconds dtime) override; //! @inherit - void onSelfUpdate() override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @brief A default constructor explicit EventSystem(WAL::Wal &wal); diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp new file mode 100644 index 00000000..cec372fc --- /dev/null +++ b/sources/System/IAControllable/IAControllableSystem.cpp @@ -0,0 +1,181 @@ +// +// Created by Louis Auzuret on 06/07/21 +// + +#include "Component/Bomb/BasicBombComponent.hpp" +#include "Component/Tag/TagComponent.hpp" +#include "Component/Timer/TimerComponent.hpp" +#include "Component/Controllable/ControllableComponent.hpp" +#include "Component/IAControllable/IAControllableComponent.hpp" +#include "System/IAControllable/IAControllableSystem.hpp" +#include + +namespace BBM +{ + IAControllableSystem::IAControllableSystem(WAL::Wal &wal) + : System(wal), _wal(wal), _cached(false) + { } + + void IAControllableSystem::UpdateMapInfos(WAL::ViewEntity &entity) + { + _players.clear(); + for (auto &[other, pos, _] : _wal.getScene()->view>()) { + if (static_cast(entity).getUid() == other.getUid()) + continue; + _players.push_back(MapInfo(pos.position, MapGenerator::NOTHING)); + } + if (_cached) + return; + if (!_wal.getScene()) + return; + for (auto &[other, pos, _] : _wal.getScene()->view>()) + _map.push_back(MapInfo(pos.position, MapGenerator::BREAKABLE)); + for (auto &[other, pos, _] : _wal.getScene()->view>()) + _map.push_back(MapInfo(pos.position, MapGenerator::UNBREAKABLE)); + for (auto &[other, pos, _] : _wal.getScene()->view>()) + _map.push_back(MapInfo(pos.position, MapGenerator::BUMPER)); + for (auto &[other, pos, _] : _wal.getScene()->view>()) + _map.push_back(MapInfo(pos.position, MapGenerator::HOLE)); + for (auto &[other, pos, bomb, timer] : _wal.getScene()->view()) + _bombs.push_back(std::make_tuple(pos.position, bomb.explosionRadius, timer.ringIn)); + _cached = true; + + } + + void IAControllableSystem::pushInfoPlayer(LuaG::State &state, MapInfo &player, BombHolderComponent &bombHolder) + { + state.push("player"); + state.newTable(); + state.push("x"); + state.push(player.x); + state.setTable(); + state.push("y"); + state.push(player.z); + state.setTable(); + state.push("bombCount"); + state.push(bombHolder.bombCount); + state.setTable(); + state.push("radius"); + state.push(bombHolder.explosionRadius); + state.setTable(); + state.setTable(); + } + + void IAControllableSystem::pushInfoRaw(LuaG::State &state) + { + int index = 0; + state.push("raw"); + state.newTable(); + for (auto &info : _map) { + state.push(index++); + state.newTable(); + state.push("x"); + state.push(info.x); + state.setTable(); + state.push("y"); + state.push(info.z); + state.setTable(); + state.push("type"); + state.push(info.type); + state.setTable(); + state.setTable(); + } + for (auto &bomb : _bombs) { + Vector3f bombPos = std::get<0>(bomb); + state.push(index++); + state.newTable(); + state.push("x"); + state.push(bombPos.x); + state.setTable(); + state.push("y"); + state.push(bombPos.z); + state.setTable(); + state.push("type"); + state.push(10); + state.setTable(); + state.setTable(); + } + state.setTable(); + } + + void IAControllableSystem::pushInfoDangerPos(LuaG::State &state, int &index, float xpos, float ypos, int dangerLevel) + { + state.push(index++); + state.newTable(); + state.push("x"); + state.push(xpos); + state.setTable(); + state.push("y"); + state.push(ypos); + state.setTable(); + state.push("level"); + state.push(dangerLevel); + state.setTable(); + state.setTable(); + } + + void IAControllableSystem::pushInfoDanger(LuaG::State &state) + { + int index = 0; + state.push("danger"); + state.newTable(); + for (auto &bomb : _bombs) { + Vector3f bombPos = std::get<0>(bomb); + int bombRadius = std::get<1>(bomb); + std::chrono::nanoseconds timeleft = std::get<2>(bomb); + int dangerLevel = std::chrono::duration_cast(timeleft).count(); + if (dangerLevel == 0) + dangerLevel = 1; + pushInfoDangerPos(state, index, bombPos.x, bombPos.z, dangerLevel); + pushInfoDangerPos(state, index, bombPos.x, bombPos.z, dangerLevel); + for (int i = 1; i < bombRadius; i++) { + Vector3f pos = bombPos - Vector3f(i, 0, 0); + pushInfoDangerPos(state, index, pos.x, pos.z, dangerLevel); + pos = bombPos - Vector3f(-i, 0, 0); + pushInfoDangerPos(state, index, pos.x, pos.z, dangerLevel); + pos = bombPos - Vector3f(0, 0, i); + pushInfoDangerPos(state, index, pos.x, pos.z, dangerLevel); + pos = bombPos - Vector3f(0, 0, -i); + pushInfoDangerPos(state, index, pos.x, pos.z, dangerLevel); + } + } + state.setTable(); + } + + void IAControllableSystem::pushInfo(LuaG::State &state, MapInfo &player, BombHolderComponent &bombHolder) + { + state.newTable(); + pushInfoPlayer(state, player, bombHolder); + pushInfoRaw(state); + pushInfoDanger(state); + } + + void IAControllableSystem::onFixedUpdate(WAL::ViewEntity &entity) + { + auto &ia = entity.get(); + auto &controllable = entity.get(); + auto &pos = entity.get(); + auto &bombHolder = entity.get(); + MapInfo player(pos.position, MapGenerator::NOTHING); + + UpdateMapInfos(entity); + + ia._state.getGlobal("Update"); + if (!lua_isfunction(ia._state.getState(), -1)) + return; + pushInfo(ia._state, player, bombHolder); + ia._state.callFunction(1, 4); + controllable.bomb = ia._state.getReturnBool(); + controllable.select = ia._state.getReturnBool(); + controllable.move.y = ia._state.getReturnNumber(); + controllable.move.x = ia._state.getReturnNumber(); + ia._state.popLast(); + } + + void IAControllableSystem::onSelfUpdate(std::chrono::nanoseconds dtime) + { + _cached = false; + _map.clear(); + _bombs.clear(); + } +} \ No newline at end of file diff --git a/sources/System/IAControllable/IAControllableSystem.hpp b/sources/System/IAControllable/IAControllableSystem.hpp new file mode 100644 index 00000000..36ce9cfe --- /dev/null +++ b/sources/System/IAControllable/IAControllableSystem.hpp @@ -0,0 +1,67 @@ +// +// Created by Louis Auzuret on 06/07/21 +// + +#pragma once + +#include +#include "Component/BombHolder/BombHolderComponent.hpp" +#include "Map/MapInfo.hpp" +#include "System/System.hpp" + +namespace BBM +{ + //! @brief A system to handle keyboard entities. + class IAControllableSystem : public WAL::System + { + private: + //! @brief Reference to wal to get Views + WAL::Wal &_wal; + + //! @brief Are the infos cached for current update + bool _cached; + + //! @brief All blocks in the map + std::vector _map; + + //! @brief All players in the map + std::vector _players; + + //! @brief All bombs on the map + std::vector> _bombs; + + //! @brief update the raw info of the map + void UpdateMapInfos(WAL::ViewEntity &entity); + + //! @brief push danger info position + void pushInfoDangerPos(LuaG::State &state, int &index, float xpos, float ypos, int dangerLevel); + + //! @brief push player info + void pushInfoPlayer(LuaG::State &state, MapInfo &player, BombHolderComponent &bombHolder); + + //! @brief push raw map info + void pushInfoRaw(LuaG::State &state); + + //! @brief push danger map info + void pushInfoDanger(LuaG::State &state); + + //! @brief push all the infos to the lua stack + void pushInfo(LuaG::State &state, MapInfo &player, BombHolderComponent &bombHolder); + public: + + //! @inherit + void onFixedUpdate(WAL::ViewEntity &entity) override; + + //! @inherit + void onSelfUpdate(std::chrono::nanoseconds dtime) override; + + //! @brief A default constructor + IAControllableSystem(WAL::Wal &wal); + //! @brief A keyboard system is copy constructable + IAControllableSystem(const IAControllableSystem &) = default; + //! @brief A default destructor + ~IAControllableSystem() override = default; + //! @brief A keyboard system is assignable. + IAControllableSystem &operator=(const IAControllableSystem &) = default; + }; +} diff --git a/sources/System/IntroAnimation/IntroAnimationSystem.cpp b/sources/System/IntroAnimation/IntroAnimationSystem.cpp index 887a11d8..9e14eb1b 100644 --- a/sources/System/IntroAnimation/IntroAnimationSystem.cpp +++ b/sources/System/IntroAnimation/IntroAnimationSystem.cpp @@ -97,7 +97,7 @@ namespace BBM component.frameCounter++; } - void IntroAnimationSystem::onSelfUpdate(void) + void IntroAnimationSystem::onSelfUpdate(std::chrono::nanoseconds) { } } \ No newline at end of file diff --git a/sources/System/IntroAnimation/IntroAnimationSystem.hpp b/sources/System/IntroAnimation/IntroAnimationSystem.hpp index 1a266443..a48c2af4 100644 --- a/sources/System/IntroAnimation/IntroAnimationSystem.hpp +++ b/sources/System/IntroAnimation/IntroAnimationSystem.hpp @@ -14,7 +14,7 @@ namespace BBM public: //! @inherit - void onSelfUpdate(void) override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @inherit void onFixedUpdate(WAL::ViewEntity &entities) override; diff --git a/sources/System/Lobby/LobbySystem.cpp b/sources/System/Lobby/LobbySystem.cpp index b55ea90a..a502732b 100644 --- a/sources/System/Lobby/LobbySystem.cpp +++ b/sources/System/Lobby/LobbySystem.cpp @@ -12,6 +12,7 @@ #include #include #include +#include "Component/IAControllable/IAControllableComponent.hpp" #include #include #include @@ -150,7 +151,7 @@ namespace BBM texture->unload(); } - void LobbySystem::onSelfUpdate() + void LobbySystem::onSelfUpdate(std::chrono::nanoseconds dtime) { auto &view = this->_wal.getScene()->view, Drawable2DComponent>(); if (view.size() == 0) @@ -193,7 +194,7 @@ namespace BBM player.addComponent(3); break; case ControllableComponent::AI: -// throw std::runtime_error("Not implemented error"); + player.addComponent("./assets/ai_scripts/john.lua"); break; default: throw std::runtime_error("Invalid controller for a player."); @@ -206,22 +207,20 @@ namespace BBM int mapWidth = 16; int mapHeight = 16; int playerCount = 0; - int playerID = 0; for (auto &[_, lobby] : wal.getScene()->view()) { - playerID++; if (lobby.layout == ControllableComponent::NONE) continue; auto &player = Runner::createPlayer(*scene); addController(player, lobby.layout); player.getComponent().position = Vector3f(mapWidth * (playerCount % 2), - 0, + (Runner::hasHeights ? 1.01 : 0), mapHeight * (!(playerCount % 3))); auto *model = dynamic_cast(player.getComponent().drawable.get()); model->setTextureToMaterial(MAP_DIFFUSE, "assets/player/textures/" + _colors[lobby.color] + ".png"); std::string texturePath = "assets/player/ui/" + _colors[lobby.color] + ".png"; - int x = (playerID % 2 == 0) ? 1920 - 10 - 320 : 10; - int y = playerID > 2 ? 1080 - 10 - 248 : 10; + int x = (playerCount % 2 == 0) ? 1920 - 10 - 320 : 10; + int y = (playerCount % 3 != 0) ? 1080 - 10 - 248 : 10; scene->addEntity("player color tile") .addComponent(x, y - 2, 0) .addComponent(x, y, 320, 248, _rayColors[lobby.color]); @@ -239,7 +238,7 @@ namespace BBM RAY2D::Text *text = dynamic_cast(drawble.drawable.get()); if (!text) return; - text->setText(std::to_string(bonus->explosionRadius)); + text->setText(std::to_string(static_cast(bonus->explosionRadius))); }); scene->addEntity("player hide bombup") .addComponent(x + 220, y + 77, 0) diff --git a/sources/System/Lobby/LobbySystem.hpp b/sources/System/Lobby/LobbySystem.hpp index 8ca92a72..5a07701d 100644 --- a/sources/System/Lobby/LobbySystem.hpp +++ b/sources/System/Lobby/LobbySystem.hpp @@ -36,7 +36,7 @@ namespace BBM void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override; //! @inherit - void onSelfUpdate() override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @brief Check if every player is ready. //! @param scene The lobby scene containing lobby players. diff --git a/sources/System/MenuControllable/MenuControllableSystem.cpp b/sources/System/MenuControllable/MenuControllableSystem.cpp index d3158774..f0115900 100644 --- a/sources/System/MenuControllable/MenuControllableSystem.cpp +++ b/sources/System/MenuControllable/MenuControllableSystem.cpp @@ -18,8 +18,9 @@ namespace BBM { MenuControllableSystem::MenuControllableSystem(WAL::Wal &wal) : System(wal), - _currentButton() - {} + _currentButton(), _oldMousePosition(-1, -1) + { + } void MenuControllableSystem::_updateCurrentButton(bool selected, Vector2f move) { @@ -51,37 +52,37 @@ namespace BBM this->_currentButton->getComponent().onEvent(*this->_currentButton, this->_wal); } - bool MenuControllableSystem::_mouseOnButton(WAL::ViewEntity &entity) const + bool MenuControllableSystem::_mouseOnButton(const Vector2f &mousePos, WAL::ViewEntity &entity) const { auto &positionComponent = entity.get(); - RAY::Vector2 rayMousePos = RAYControl::Mouse::getCursorPosition(); RAY::Texture *texture = dynamic_cast(entity.get().drawable.get()); RAY2D::Text *text = dynamic_cast(entity.get().drawable.get()); Vector2f buttonPos(positionComponent.getX(), positionComponent.getY()); - Vector2f mousePos(rayMousePos.x, rayMousePos.y); Vector2f dimensions; - WAL::Entity *newButton = nullptr; - if (texture) { dimensions.x = texture->getDimensions().x; dimensions.y = texture->getDimensions().y; } else if (text) { dimensions.y = text->getFontSize(); - dimensions.x = text->getString().size() * (text->getLetterSpacing() + text->getFontSize()); + dimensions.x = text->getString().size() * (text->getFontSize()); } else return false; return ((buttonPos.x <= mousePos.x && mousePos.x <= buttonPos.x + dimensions.x) && (buttonPos.y <= mousePos.y && mousePos.y <= buttonPos.y + dimensions.y)); } - void MenuControllableSystem::onSelfUpdate() + void MenuControllableSystem::onSelfUpdate(std::chrono::nanoseconds dtime) { - + RAY::Vector2 rayMousePos = RAYControl::Mouse::getCursorPosition(); + RAY::Vector2 winSize = RAY::Window::getInstance().getDimensions(); + Vector2f relativeMousePos(rayMousePos.x * 1920 / winSize.x, rayMousePos.y * 1080 / winSize.y); auto &controllableView = this->_wal.getScene()->view(); auto &buttons = _wal.getScene()->view(); + if (this->_oldMousePosition == Vector2f(-1, -1)) + this->_oldMousePosition = relativeMousePos; if (this->_currentButton && this->_currentButton->_scene.getID() != this->_wal.getScene()->getID()) { this->_currentButton->getComponent().onEvent(*this->_currentButton, this->_wal); this->_currentButton = nullptr; @@ -98,8 +99,11 @@ namespace BBM this->_updateCurrentButton(controllable.select, controllable.move); return; } + if (relativeMousePos == this->_oldMousePosition && !RAYControl::Mouse::isPressed(RAYControl::Mouse::Button::MOUSE_BUTTON_LEFT)) + return; + this->_oldMousePosition = relativeMousePos; for (auto &entity: buttons) { - if (_mouseOnButton(entity)) { + if (_mouseOnButton(relativeMousePos, entity)) { if (this->_currentButton) this->_currentButton->getComponent().onEvent(*this->_currentButton, this->_wal); this->_currentButton = &(*entity); diff --git a/sources/System/MenuControllable/MenuControllableSystem.hpp b/sources/System/MenuControllable/MenuControllableSystem.hpp index 67254369..28fe0a60 100644 --- a/sources/System/MenuControllable/MenuControllableSystem.hpp +++ b/sources/System/MenuControllable/MenuControllableSystem.hpp @@ -20,17 +20,20 @@ namespace BBM //! @brief index of the current button selected WAL::Entity *_currentButton; + //! @brief position of the mouse at the precedent scene (to know which controller event to watch) + Vector2f _oldMousePosition; + //! @brief update current button reference //! @param selected lets know if te new selected button is 'pressed' void _updateCurrentButton(bool selected, Vector2f move); //! @return true if mouse on entity - bool _mouseOnButton(WAL::ViewEntity &entity) const; + bool _mouseOnButton(const Vector2f &mousePos, WAL::ViewEntity &entity) const; public: //! @brief time (in millisecond) since last check std::chrono::time_point now; //! @inherit - void onSelfUpdate() override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @brief A default constructor explicit MenuControllableSystem(WAL::Wal &wal); diff --git a/sources/System/Renderer/CameraSystem.cpp b/sources/System/Renderer/CameraSystem.cpp new file mode 100644 index 00000000..3c4e538c --- /dev/null +++ b/sources/System/Renderer/CameraSystem.cpp @@ -0,0 +1,79 @@ +// +// Created by Tom Augier on 05/06/2021 +// + +#include "CameraSystem.hpp" +#include "Entity/Entity.hpp" +#include "Component/Tag/TagComponent.hpp" + +namespace BBM +{ + CameraSystem::CameraSystem(WAL::Wal &wal) + : System(wal) + {} + + bool CameraSystem::introAnimation(WAL::ViewEntity &entity, bool restart) + { + auto &pos = entity.get(); + static Vector3f posTarget(8, 25, 7); + static bool hasEnded = false; + + if (restart) { + hasEnded = false; + return (false); + } + if (pos.position.distance(posTarget) < 4 || hasEnded) { + hasEnded = true; + return (true); + } + + auto &cam = entity.get(); + + pos.position += (posTarget - pos.position) / 100; + return (false); + } + + void CameraSystem::onUpdate(WAL::ViewEntity &entity, + std::chrono::nanoseconds dtime) + { + if (!introAnimation(entity)) + return; + auto &pos = entity.get(); + auto &cam = entity.get(); + Vector3f newCameraPos = Vector3f(-1, -1, -1); + std::vector playerPos; + float maxDist = 0; + float lowerXDist = 0; + float lowerZDist = 0; + + for (auto &[entity, pos, _] : this->_wal.getScene()->view>()) { + if (!entity.hasComponent()) + entity.addComponent(); + playerPos.emplace_back(pos.position); + } + if (playerPos.size() == 0) + introAnimation(entity, true); + if (playerPos.size() == 1) + newCameraPos = playerPos[0]; + for (int i = 0; i < playerPos.size(); i++) + for (int j = 0; j < playerPos.size(); j++) { + if (maxDist < playerPos[i].distance(playerPos[j])) { + maxDist = playerPos[i].distance(playerPos[j]); + newCameraPos = (playerPos[i] + playerPos[j]) / 2; + } + if (lowerXDist < std::abs((playerPos[i].x - playerPos[j].x))) + lowerXDist = std::abs((playerPos[i].x - playerPos[j].x)); + if (lowerZDist < std::abs((playerPos[i].z - playerPos[j].z))) + lowerZDist = std::abs((playerPos[i].z - playerPos[j].z)); + } + maxDist += (lowerXDist + lowerZDist) / 2; + if (maxDist < 14) + maxDist = 14; + if (maxDist > 25) + maxDist = 25; + cam.target += (newCameraPos.abs() - pos.position.abs()) / 10; + newCameraPos.y = maxDist; + newCameraPos.z -= 1; + pos.position += (newCameraPos.abs() - pos.position.abs()) / 10; + } +} \ No newline at end of file diff --git a/sources/System/Renderer/CameraSystem.hpp b/sources/System/Renderer/CameraSystem.hpp new file mode 100644 index 00000000..ce3a804f --- /dev/null +++ b/sources/System/Renderer/CameraSystem.hpp @@ -0,0 +1,36 @@ +// +// Created by Tom Augier on 05/06/2021 +// + +#pragma once + +#include "System/System.hpp" +#include "Window.hpp" +#include "Component/Renderer/CameraComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#include +#include "Wal.hpp" + +namespace BBM +{ + class CameraSystem : public WAL::System + { + public: + //! @inherit + void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds) override; + + //! @brief introduciton animation when entering gameScene + bool introAnimation(WAL::ViewEntity &entity, bool restart = false); + + //! @brief ctor + CameraSystem(WAL::Wal &wal); + //! @brief Default copy ctor + CameraSystem(const CameraSystem &) = default; + //! @brief Default dtor + ~CameraSystem() override = default; + //! @brief A CameraManager screen system can't be assigned. + CameraSystem &operator=(const CameraSystem &) = delete; + }; +} + + \ No newline at end of file diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index 161bd2d8..6fb43b5f 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -10,10 +10,16 @@ #include "Component/Renderer/Drawable2DComponent.hpp" #include #include "Drawables/ADrawable3D.hpp" +#include "Drawables/ADrawable2D.hpp" #include "Component/Shaders/ShaderComponent.hpp" +#include "Component/Tag/TagComponent.hpp" #include #include "Models/Vector3.hpp" #include "Component/Collision/CollisionComponent.hpp" +#include +#include + +namespace RAY2D = RAY::Drawables::Drawables2D; namespace BBM { @@ -23,7 +29,7 @@ namespace BBM _camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE), _debugMode(debugMode) { - this->_window.setFPS(this->FPS); + this->_window.setFPS(BBM::RenderSystem::FPS); } void RenderSystem::drawBoundingBox(const WAL::Entity &entity, const PositionComponent &posComponent, const Drawable3DComponent &drawable) const @@ -40,11 +46,71 @@ namespace BBM drawable.drawable->drawWiresOn(this->_window); } - void RenderSystem::onSelfUpdate() + Vector2f RenderSystem::getRescaledPosition(Vector3f &position, const Vector2f &newWinDims) + { + Vector2f newPosition; + newPosition.x = (position.x * newWinDims.x) / 1920; + newPosition.y = (position.y * newWinDims.y) / 1080; + return newPosition; + } + + void RenderSystem::drawRescaledDrawable(RAY::Drawables::ADrawable2D &drawable, const Vector2f &newDims) + { + RAY2D::Text *text = dynamic_cast(&drawable); + + if (text) { + float oldHeightSize = text->getFontSize(); + float oldWidthSize = text->getFontSize() + text->getLetterSpacing(); + float newHeightSize = oldHeightSize * newDims.y / 1080; + float newWidthSize = oldWidthSize * newDims.x / 1920; + text->setFontSize((newWidthSize + newHeightSize) / 2); + drawable.drawOn(this->_window); + text->setFontSize(oldHeightSize); + return; + } + RAY::Texture *texture = dynamic_cast(&drawable); + + if (texture) { + float oldScale = texture->getScale(); + float newScale = (texture->getWidth() * newDims.x / 1920) / texture->getWidth(); + texture->setScale(newScale); + drawable.drawOn(this->_window); + texture->setScale(oldScale); + return; + } + RAY2D::Rectangle *rect = dynamic_cast(&drawable); + + if (rect) { + float oldHeightSize = rect->getHeight(); + float oldWidthSize = rect->getWidth(); + rect->setHeight(oldHeightSize * newDims.y / 1080); + rect->setWidth(oldWidthSize * newDims.x / 1920); + drawable.drawOn(this->_window); + rect->setWidth(oldWidthSize); + rect->setHeight(oldHeightSize); + return; + } + } + + void RenderSystem::resizeWindow(Vector2f &newDims) + { + newDims.y = (newDims.x * 720) / 1280; + if ((newDims.y < 720 || newDims.x < 1280)) { + newDims.y = 720; + newDims.x = 1280; + } + this->_window.setDimensions(newDims); + } + + void RenderSystem::onSelfUpdate(std::chrono::nanoseconds dtime) { this->_camera.update(); this->_window.beginDrawing(); this->_window.clear(); + RAY::Vector2 rayWinDims = this->_window.getDimensions(); + Vector2f windowDimensions(rayWinDims.x, rayWinDims.y); + + this->resizeWindow(windowDimensions); for (auto &[entity, pos, drawable] : this->_wal.getScene()->view()) { if (!drawable.drawBefore3D) @@ -85,8 +151,8 @@ namespace BBM if (shader) { RAY::Shader::BeginUsingCustomShader(shader->getShader()); } - drawable.drawable->setPosition(Vector2f(pos.position.x, pos.position.y)); - drawable.drawable->drawOn(this->_window); + drawable.drawable->setPosition(this->getRescaledPosition(pos.position, windowDimensions)); + this->drawRescaledDrawable(*drawable.drawable, windowDimensions); if (shader) { RAY::Shader::EndUsingCustomShader(); } @@ -99,10 +165,11 @@ namespace BBM void RenderSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) { - const auto &pos = entity.get(); - const auto &cam = entity.get(); - _camera.setPosition(pos.position); + auto &pos = entity.get(); + auto &cam = entity.get(); + _camera.setTarget(cam.target); + _camera.setPosition(pos.position); } void RenderSystem::setDebug(bool debug) diff --git a/sources/System/Renderer/RenderSystem.hpp b/sources/System/Renderer/RenderSystem.hpp index bff17267..e5679be5 100644 --- a/sources/System/Renderer/RenderSystem.hpp +++ b/sources/System/Renderer/RenderSystem.hpp @@ -6,11 +6,13 @@ #include "Component/Renderer/CameraComponent.hpp" #include "Component/Position/PositionComponent.hpp" +#include "Component/Movable/MovableComponent.hpp" #include "Component/Renderer/Drawable3DComponent.hpp" #include "System/System.hpp" #include "Camera/Camera2D.hpp" #include "Window.hpp" #include "Wal.hpp" +#include "Models/Vector2.hpp" namespace BBM { @@ -29,10 +31,22 @@ namespace BBM //! @brief Window framerate limit static constexpr short FPS = 60; + //! @brief rescale the drawables dimensions according to new window dimensions + //! @param drawable the drawable to rescale + //! @param newDims the new window's dimensions + void drawRescaledDrawable(RAY::Drawables::ADrawable2D &drawable, const Vector2f &newDims); + + //! @brief rescale the drawables position according to new window dimensions + //! @param position a reference to position + //! @param newDims the new window's dimensions + Vector2f getRescaledPosition(Vector3f &position, const Vector2f &newWinDims); + + void resizeWindow(Vector2f &newDims); + public: //! @brief A method called after all entities that this system manage has been updated. //! @note render on screen here - void onSelfUpdate() override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @inherit void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override; diff --git a/sources/main.cpp b/sources/main.cpp index c4e69c4a..9cf4bf85 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -23,5 +23,10 @@ int main(int argc, char **argv) usage(argv[0]); return 1; } - return BBM::Runner::run(); + try { + return BBM::Runner::run(); + } catch (const std::exception &ex) { + std::cerr << ex.what() << std::endl; + return 84; + } }