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 cf696742..d7e36036 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 @@ -167,8 +175,8 @@ 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 @@ -182,8 +190,8 @@ add_executable(unit_tests EXCLUDE_FROM_ALL tests/ViewTest.cpp tests/CollisionTest.cpp ) -target_include_directories(unit_tests PUBLIC sources) -target_link_libraries(unit_tests PUBLIC wal ray) +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/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/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..59a508c6 100644 --- a/lib/Ray/sources/Model/Model.cpp +++ b/lib/Ray/sources/Model/Model.cpp @@ -13,7 +13,13 @@ 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, 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..151cd615 100644 --- a/lib/Ray/sources/Window.cpp +++ b/lib/Ray/sources/Window.cpp @@ -70,11 +70,20 @@ 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; + SetWindowSize(dims.x, dims.y); + return *this; +} + void RAY::Window::setVisibleCursor(bool visible) { if (visible) @@ -184,4 +193,23 @@ 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; +} + +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; } \ No newline at end of file diff --git a/lib/Ray/sources/Window.hpp b/lib/Ray/sources/Window.hpp index 525f2992..81d4b1e4 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,14 @@ 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(); private: //! @brief Creates window, and opens it if openNow is set to true 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/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..74bf6253 100644 --- a/sources/Component/Tag/TagComponent.hpp +++ b/sources/Component/Tag/TagComponent.hpp @@ -52,6 +52,11 @@ namespace BBM // interact with bombs & stop the explosion constexpr const char Blowable[] = "Blowable"; + constexpr const char Unbreakable[] = "Unbreakable"; + constexpr const char Breakable[] = "Breakable"; + constexpr const char Hole[] = "Hole"; + constexpr const char Bumper[] = "Bumper"; + constexpr const char Player[] = "Player"; // interact with bombs (getting damage etc) but doesn't stop explosion constexpr const char BlowablePass[] = "BlowablePass"; } diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 02579a06..8506a8f4 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -132,6 +132,7 @@ namespace BBM scene->addEntity("Unbreakable Wall") .addComponent(i, 0, j) .addComponent>() + .addComponent>() .addComponent( WAL::Callback(), &MapGenerator::wallCollided, 0.25, .75) @@ -239,10 +240,11 @@ namespace BBM scene->addEntity("Breakable Block") .addComponent(coords) .addComponent>() + .addComponent>() .addComponent(1, &MapGenerator::wallDestroyed) - .addComponent( - WAL::Callback(), - &MapGenerator::wallCollided, 0.25, .75) + //.addComponent( + // WAL::Callback(), + // &MapGenerator::wallCollided, 0.25, .75) .addComponent(breakableObj, false, std::make_pair(MAP_DIFFUSE, breakablePng)); } @@ -276,6 +278,7 @@ namespace BBM scene->addEntity("Unbreakable Block") .addComponent(coords) .addComponent>() + .addComponent>() .addComponent( WAL::Callback(), &MapGenerator::wallCollided, 0.25, .75) @@ -293,6 +296,7 @@ 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)); @@ -311,7 +315,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/Map.hpp b/sources/Map/Map.hpp index e04a00fc..ff7b712e 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -30,8 +30,7 @@ namespace BBM class MapGenerator { - private: - + public: //! @brief Enum of the block available. enum BlockType { @@ -45,6 +44,7 @@ namespace BBM UNBREAKABLE }; + private: using MapElem = std::function scene)>; using MapBlock = std::map, BlockType>; 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/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 b2e6f279..4dbc2c55 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -62,7 +62,7 @@ namespace BBM {SoundComponent::BOMB, "assets/sounds/bomb_drop.ogg"}, //{SoundComponent::DEATH, "assets/sounds/death.ogg"} }; - + return scene.addEntity("player") .addComponent() .addComponent("assets/player/player.iqm", true) 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..c1596c17 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,7 +196,7 @@ 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") diff --git a/sources/Runner/MainMenuScene.cpp b/sources/Runner/MainMenuScene.cpp index 42067222..33377954 100644 --- a/sources/Runner/MainMenuScene.cpp +++ b/sources/Runner/MainMenuScene.cpp @@ -23,7 +23,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 cf7d66c6..3154e360 100644 --- a/sources/Runner/PauseMenuScene.cpp +++ b/sources/Runner/PauseMenuScene.cpp @@ -23,7 +23,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 2bcc5fc4..c9031468 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 "System/Sound/PlayerSoundManagerSystem.hpp" @@ -76,6 +85,7 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem() .addSystem() .addSystem() @@ -104,23 +114,26 @@ namespace BBM 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(1920, 1080, "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); } } @@ -145,13 +158,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 4fa9f6a1..3c1d9d04 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 { @@ -30,7 +32,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..88241d36 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,34 @@ 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(); + unsigned oldFlags = window.getConfigFlags(); + + if (oldFlags == FLAG_WINDOW_RESIZABLE) + window.toggleFullscreen(); + else + window.setConfigFlags(FLAG_WINDOW_RESIZABLE); + + if (text->getString().find("Off") != std::string::npos) { + text->setText("Fullscreen: On"); + } else { + text->setText("Fullscreen: Off"); + } + }) + .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 +234,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/Collision/CollisionSystem.cpp b/sources/System/Collision/CollisionSystem.cpp index abdfdf6d..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) diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp new file mode 100644 index 00000000..26432c1f --- /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() + { + _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..6c895a25 --- /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() 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/Lobby/LobbySystem.cpp b/sources/System/Lobby/LobbySystem.cpp index 4d2fd563..f3149162 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 @@ -192,7 +193,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."); @@ -214,7 +215,7 @@ namespace BBM 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"); diff --git a/sources/System/MenuControllable/MenuControllableSystem.cpp b/sources/System/MenuControllable/MenuControllableSystem.cpp index d3158774..24787a3d 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,14 +52,12 @@ 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; @@ -68,7 +67,7 @@ namespace BBM 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) @@ -77,11 +76,15 @@ namespace BBM void MenuControllableSystem::onSelfUpdate() { - + 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 +101,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..7462a358 100644 --- a/sources/System/MenuControllable/MenuControllableSystem.hpp +++ b/sources/System/MenuControllable/MenuControllableSystem.hpp @@ -20,12 +20,15 @@ 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; diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index 161bd2d8..4d6a3043 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -10,10 +10,15 @@ #include "Component/Renderer/Drawable2DComponent.hpp" #include #include "Drawables/ADrawable3D.hpp" +#include "Drawables/ADrawable2D.hpp" #include "Component/Shaders/ShaderComponent.hpp" #include #include "Models/Vector3.hpp" #include "Component/Collision/CollisionComponent.hpp" +#include +#include + +namespace RAY2D = RAY::Drawables::Drawables2D; namespace BBM { @@ -40,11 +45,71 @@ namespace BBM drawable.drawable->drawWiresOn(this->_window); } + 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() { 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 +150,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(); } diff --git a/sources/System/Renderer/RenderSystem.hpp b/sources/System/Renderer/RenderSystem.hpp index bff17267..0e229f2a 100644 --- a/sources/System/Renderer/RenderSystem.hpp +++ b/sources/System/Renderer/RenderSystem.hpp @@ -11,6 +11,7 @@ #include "Camera/Camera2D.hpp" #include "Window.hpp" #include "Wal.hpp" +#include "Models/Vector2.hpp" namespace BBM { @@ -29,6 +30,18 @@ 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 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; + } }