diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7143ed9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,8 @@ +# CMakeLists.txt +# Cubos Demo project root build configuration + +cmake_minimum_required(VERSION 3.20.0) +project(cubos-demo VERSION 0.1.0) + +add_subdirectory(lib/cubos) +add_subdirectory(platformer) diff --git a/flake.lock b/flake.lock index 6569ee2..dc1d79d 100644 --- a/flake.lock +++ b/flake.lock @@ -1,15 +1,12 @@ { "nodes": { "flake-utils": { - "inputs": { - "systems": "systems" - }, "locked": { - "lastModified": 1685518550, - "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "lastModified": 1648297722, + "narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", "type": "github" }, "original": { @@ -20,16 +17,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1687019075, - "narHash": "sha256-YjB+tp0DPfzct8XmXNW1UAfQp0irIVM7nGcJPiqT61c=", + "lastModified": 1695825837, + "narHash": "sha256-4Ne11kNRnQsmSJCRSSNkFRSnHC4Y5gPDBIQGjjPfJiU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "50d2e0780758fcb41cf5e494a51624cbf6c40b20", + "rev": "5cfafa12d57374f48bcc36fda3274ada276cf69e", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-22.11", + "ref": "nixos-23.05", "repo": "nixpkgs", "type": "github" } @@ -39,21 +36,6 @@ "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index d4b4610..398862b 100644 --- a/flake.nix +++ b/flake.nix @@ -1,30 +1,48 @@ # Flake used for development with nix { inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { nixpkgs, flake-utils, ... }: - flake-utils.lib.eachDefaultSystem (system: + outputs = inputs: + inputs.flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { inherit system; }; + pkgs = import inputs.nixpkgs { inherit system; }; in { devShell = pkgs.mkShell { - buildInputs = with pkgs; [ - pkg-config + packages = with pkgs; [ + # = build tools = cmake - gcc - glfw - glm - spdlog + ccache + pkg-config + + # = formatting = clang-tools + + # = docs = doxygen - graphviz - clang_14 + (python3.withPackages (ps: [ + ps.jinja2 + ps.pygments + ])) + + # = libs = + glfw + glm + # spdlog + # fmt doctest - lcov + + # = system libs = + libGL + xorg.libX11 + xorg.libXrandr + xorg.libXinerama + xorg.libXcursor + xorg.libXi + xorg.libXdmcp ]; }; }); diff --git a/lib/cubos b/lib/cubos index 2f2075f..4311a9a 160000 --- a/lib/cubos +++ b/lib/cubos @@ -1 +1 @@ -Subproject commit 2f2075fd797be781b14bd65466f4040ff53497ae +Subproject commit 4311a9ae72feaf53c575a26a121511bb0f048a9e diff --git a/platformer/CMakeLists.txt b/platformer/CMakeLists.txt index e4308ee..e8c4caf 100644 --- a/platformer/CMakeLists.txt +++ b/platformer/CMakeLists.txt @@ -1,30 +1,33 @@ # CMakeLists.txt -# Cubos Demo project root build configuration - -cmake_minimum_required(VERSION 3.20.0) -project(cubos-platformer-demo VERSION 0.1.0) - -# Include CubinhosGenerate -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../lib/cubos/cmake") -include(CubinhosGenerate) - -# Build demo executabe -set(PROJECT_SOURCE "main.cpp") -add_executable(platformer_demo ${PROJECT_SOURCE}) - -# Dependencies -add_subdirectory(../lib/cubos lib/cubos) -target_link_libraries(platformer_demo cubos-engine) - -# Assets -target_compile_definitions(platformer_demo PUBLIC PROJECT_ASSETS_FOLDER="${CMAKE_CURRENT_SOURCE_DIR}/assets") - -target_compile_features(platformer_demo PRIVATE cxx_std_20) - -# Components -cubinhos_generate(platformer_demo "${CMAKE_CURRENT_SOURCE_DIR}") - -# Enable CTest and CPack -set(CPACK_PROJECT_NAME ${PROJECT_NAME}) -set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) -include(CPack) +# Platformer build configuration + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../lib/cubos/cmake") + +include(QuadradosGenerate) + +add_executable(platformer + src/main.cpp + src/player/plugin.cpp + src/player/player.cpp + src/spawn/plugin.cpp + src/spawn/spawn.cpp + src/orbit_camera/plugin.cpp + src/orbit_camera/controller.cpp + src/collider_gizmos/plugin.cpp + src/offset/plugin.cpp + src/offset/offset.cpp + src/death/plugin.cpp + src/death/dead.cpp + src/mover/plugin.cpp + src/mover/mover.cpp + src/victory/plugin.cpp + src/victory/victory.cpp + src/cannon/plugin.cpp + src/cannon/cannon.cpp + src/cannon/bullet.cpp +) + +target_link_libraries(platformer tesseratos) +target_compile_definitions(platformer PUBLIC PROJECT_ASSETS_FOLDER="${CMAKE_CURRENT_SOURCE_DIR}/assets") +target_compile_features(platformer PRIVATE cxx_std_20) +quadrados_generate(platformer "${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/platformer/assets/bindings/player0.bind b/platformer/assets/bindings/player0.bind new file mode 100644 index 0000000..50c6240 --- /dev/null +++ b/platformer/assets/bindings/player0.bind @@ -0,0 +1,69 @@ +{ + "actions": { + "jump": { + "keys": [ + "Space" + ], + "gamepad": [ + "A" + ] + } + }, + "axes": { + "vertical": { + "pos": [ + "s" + ], + "neg": [ + "w" + ], + "gamepad": [ + "LY" + ] + }, + "horizontal": { + "pos": [ + "d" + ], + "neg": [ + "a" + ], + "gamepad": [ + "LX" + ] + }, + "look-vertical": { + "pos": [ + "Down" + ], + "neg": [ + "Up" + ], + "gamepad": [ + "RY" + ] + }, + "look-horizontal": { + "pos": [ + "Right" + ], + "neg": [ + "Left" + ], + "gamepad": [ + "RX" + ] + }, + "look-zoom": { + "pos": [ + "PageUp" + ], + "neg": [ + "PageDown" + ], + "gamepad": [ + "RTrigger" + ] + } + } +} \ No newline at end of file diff --git a/platformer/assets/bindings/player0.bind.meta b/platformer/assets/bindings/player0.bind.meta new file mode 100644 index 0000000..9f83baa --- /dev/null +++ b/platformer/assets/bindings/player0.bind.meta @@ -0,0 +1,3 @@ +{ + "id": "1c2497cc-3aec-4455-889f-492001172273" +} \ No newline at end of file diff --git a/platformer/assets/bindings/player1.bind b/platformer/assets/bindings/player1.bind new file mode 100644 index 0000000..17909af --- /dev/null +++ b/platformer/assets/bindings/player1.bind @@ -0,0 +1,69 @@ +{ + "actions": { + "jump": { + "keys": [ + "p" + ], + "gamepad": [ + "A" + ] + } + }, + "axes": { + "vertical": { + "pos": [ + "g" + ], + "neg": [ + "t" + ], + "gamepad": [ + "LY" + ] + }, + "horizontal": { + "pos": [ + "h" + ], + "neg": [ + "f" + ], + "gamepad": [ + "LX" + ] + }, + "look-vertical": { + "pos": [ + "k" + ], + "neg": [ + "i" + ], + "gamepad": [ + "RY" + ] + }, + "look-horizontal": { + "pos": [ + "l" + ], + "neg": [ + "j" + ], + "gamepad": [ + "RX" + ] + }, + "look-zoom": { + "pos": [ + "u" + ], + "neg": [ + "o" + ], + "gamepad": [ + "RTrigger" + ] + } + } +} \ No newline at end of file diff --git a/platformer/assets/bindings/player1.bind.meta b/platformer/assets/bindings/player1.bind.meta new file mode 100644 index 0000000..80707ef --- /dev/null +++ b/platformer/assets/bindings/player1.bind.meta @@ -0,0 +1,3 @@ +{ + "id": "093597a1-771b-4196-878c-3ef5c3e27845" +} \ No newline at end of file diff --git a/platformer/assets/main.pal b/platformer/assets/main.pal new file mode 100644 index 0000000..ab5103c Binary files /dev/null and b/platformer/assets/main.pal differ diff --git a/platformer/assets/main.pal.meta b/platformer/assets/main.pal.meta new file mode 100644 index 0000000..509d07f --- /dev/null +++ b/platformer/assets/main.pal.meta @@ -0,0 +1,3 @@ +{ + "id": "1aa5e234-28cb-4386-99b4-39386b0fc215" +} \ No newline at end of file diff --git a/platformer/assets/models/cannon/bullet.grd b/platformer/assets/models/cannon/bullet.grd new file mode 100644 index 0000000..3fedc95 Binary files /dev/null and b/platformer/assets/models/cannon/bullet.grd differ diff --git a/platformer/assets/models/cannon/bullet.grd.meta b/platformer/assets/models/cannon/bullet.grd.meta new file mode 100644 index 0000000..6f8ad07 --- /dev/null +++ b/platformer/assets/models/cannon/bullet.grd.meta @@ -0,0 +1,3 @@ +{ + "id": "8f633d2c-618c-40ca-859d-fe24b9ed7200" +} \ No newline at end of file diff --git a/platformer/assets/models/cannon/bullet.qb b/platformer/assets/models/cannon/bullet.qb new file mode 100644 index 0000000..43a0a23 Binary files /dev/null and b/platformer/assets/models/cannon/bullet.qb differ diff --git a/platformer/assets/models/cannon/cannon.grd b/platformer/assets/models/cannon/cannon.grd new file mode 100644 index 0000000..11a4e9f Binary files /dev/null and b/platformer/assets/models/cannon/cannon.grd differ diff --git a/platformer/assets/models/cannon/cannon.grd.meta b/platformer/assets/models/cannon/cannon.grd.meta new file mode 100644 index 0000000..1906e6f --- /dev/null +++ b/platformer/assets/models/cannon/cannon.grd.meta @@ -0,0 +1,3 @@ +{ + "id": "8f633d2c-618c-40ca-859d-fe24b9ed7219" +} \ No newline at end of file diff --git a/platformer/assets/models/cannon/cannon.qb b/platformer/assets/models/cannon/cannon.qb new file mode 100644 index 0000000..29f5c7a Binary files /dev/null and b/platformer/assets/models/cannon/cannon.qb differ diff --git a/platformer/assets/models/platforms/base-16.grd b/platformer/assets/models/platforms/base-16.grd new file mode 100644 index 0000000..bb5fb0f Binary files /dev/null and b/platformer/assets/models/platforms/base-16.grd differ diff --git a/platformer/assets/models/platforms/base-16.grd.meta b/platformer/assets/models/platforms/base-16.grd.meta new file mode 100644 index 0000000..881c0e0 --- /dev/null +++ b/platformer/assets/models/platforms/base-16.grd.meta @@ -0,0 +1,3 @@ +{ + "id": "e8b952de-41ce-4c63-bd0c-af2c6b501882" +} \ No newline at end of file diff --git a/platformer/assets/models/platforms/base-16.qb b/platformer/assets/models/platforms/base-16.qb new file mode 100644 index 0000000..351a834 Binary files /dev/null and b/platformer/assets/models/platforms/base-16.qb differ diff --git a/platformer/assets/models/platforms/goal.grd b/platformer/assets/models/platforms/goal.grd new file mode 100644 index 0000000..59c25e5 Binary files /dev/null and b/platformer/assets/models/platforms/goal.grd differ diff --git a/platformer/assets/models/platforms/goal.grd.meta b/platformer/assets/models/platforms/goal.grd.meta new file mode 100644 index 0000000..853c139 --- /dev/null +++ b/platformer/assets/models/platforms/goal.grd.meta @@ -0,0 +1,3 @@ +{ + "id": "1e314618-950c-4505-a275-5881102f8d71" +} \ No newline at end of file diff --git a/platformer/assets/models/platforms/goal.qb b/platformer/assets/models/platforms/goal.qb new file mode 100644 index 0000000..205202e Binary files /dev/null and b/platformer/assets/models/platforms/goal.qb differ diff --git a/platformer/assets/models/platforms/settings.json b/platformer/assets/models/platforms/settings.json new file mode 100644 index 0000000..e69de29 diff --git a/platformer/assets/models/player/left-foot.grd b/platformer/assets/models/player/left-foot.grd new file mode 100644 index 0000000..f776261 Binary files /dev/null and b/platformer/assets/models/player/left-foot.grd differ diff --git a/platformer/assets/models/player/left-foot.grd.meta b/platformer/assets/models/player/left-foot.grd.meta new file mode 100644 index 0000000..459aecc --- /dev/null +++ b/platformer/assets/models/player/left-foot.grd.meta @@ -0,0 +1,3 @@ +{ + "id": "8f633d2c-618c-40ca-859d-fe24b9ed7207" +} \ No newline at end of file diff --git a/platformer/assets/models/player/left-foot.qb b/platformer/assets/models/player/left-foot.qb new file mode 100644 index 0000000..7c8794e Binary files /dev/null and b/platformer/assets/models/player/left-foot.qb differ diff --git a/platformer/assets/models/player/left-hand.grd b/platformer/assets/models/player/left-hand.grd new file mode 100644 index 0000000..c70f1a6 Binary files /dev/null and b/platformer/assets/models/player/left-hand.grd differ diff --git a/platformer/assets/models/player/left-hand.grd.meta b/platformer/assets/models/player/left-hand.grd.meta new file mode 100644 index 0000000..73fe884 --- /dev/null +++ b/platformer/assets/models/player/left-hand.grd.meta @@ -0,0 +1,3 @@ +{ + "id": "ffbf1f87-6ffb-4395-8a30-92883f14dd4a" +} \ No newline at end of file diff --git a/platformer/assets/models/player/left-hand.qb b/platformer/assets/models/player/left-hand.qb new file mode 100644 index 0000000..5f6fd14 Binary files /dev/null and b/platformer/assets/models/player/left-hand.qb differ diff --git a/platformer/assets/models/player/right-foot.grd b/platformer/assets/models/player/right-foot.grd new file mode 100644 index 0000000..1c2ea84 Binary files /dev/null and b/platformer/assets/models/player/right-foot.grd differ diff --git a/platformer/assets/models/player/right-foot.grd.meta b/platformer/assets/models/player/right-foot.grd.meta new file mode 100644 index 0000000..e53f8d1 --- /dev/null +++ b/platformer/assets/models/player/right-foot.grd.meta @@ -0,0 +1,3 @@ +{ + "id": "6b49fb4e-3d0d-4784-846f-ae4a6fe0bcbf" +} \ No newline at end of file diff --git a/platformer/assets/models/player/right-foot.qb b/platformer/assets/models/player/right-foot.qb new file mode 100644 index 0000000..fdf36ad Binary files /dev/null and b/platformer/assets/models/player/right-foot.qb differ diff --git a/platformer/assets/models/player/right-hand.grd b/platformer/assets/models/player/right-hand.grd new file mode 100644 index 0000000..1b4593a Binary files /dev/null and b/platformer/assets/models/player/right-hand.grd differ diff --git a/platformer/assets/models/player/right-hand.grd.meta b/platformer/assets/models/player/right-hand.grd.meta new file mode 100644 index 0000000..0e34f33 --- /dev/null +++ b/platformer/assets/models/player/right-hand.grd.meta @@ -0,0 +1,3 @@ +{ + "id": "521cec89-3392-450c-90f5-a06e1abd1691" +} \ No newline at end of file diff --git a/platformer/assets/models/player/right-hand.qb b/platformer/assets/models/player/right-hand.qb new file mode 100644 index 0000000..a262eff Binary files /dev/null and b/platformer/assets/models/player/right-hand.qb differ diff --git a/platformer/assets/models/player/torso.grd b/platformer/assets/models/player/torso.grd new file mode 100644 index 0000000..31ec3f2 Binary files /dev/null and b/platformer/assets/models/player/torso.grd differ diff --git a/platformer/assets/models/player/torso.grd.meta b/platformer/assets/models/player/torso.grd.meta new file mode 100644 index 0000000..c7afcf5 --- /dev/null +++ b/platformer/assets/models/player/torso.grd.meta @@ -0,0 +1,3 @@ +{ + "id": "059c16e7-a439-44c7-9bdc-6e069dba0c75" +} \ No newline at end of file diff --git a/platformer/assets/models/player/torso.qb b/platformer/assets/models/player/torso.qb new file mode 100644 index 0000000..2574e22 Binary files /dev/null and b/platformer/assets/models/player/torso.qb differ diff --git a/platformer/assets/scenes/bullet.cubos b/platformer/assets/scenes/bullet.cubos new file mode 100644 index 0000000..accde7c --- /dev/null +++ b/platformer/assets/scenes/bullet.cubos @@ -0,0 +1,26 @@ +{ + "entities": { + "base": { + "demo::Bullet": { + "life": 5.0 + }, + "cubos::engine::RenderableGrid": { + "asset": "8f633d2c-618c-40ca-859d-fe24b9ed7200", + "offset": { + "x": -2, + "y": -2, + "z": -2 + } + }, + "cubos::engine::Scale": 0.4, + "cubos::engine::Position": {}, + "cubos::engine::LocalToWorld": {}, + "cubos::engine::BoxCollisionShape": { + "x": 2, + "y": 2, + "z": 2 + }, + "cubos::engine::Collider": {} + } + } +} \ No newline at end of file diff --git a/platformer/assets/scenes/bullet.cubos.meta b/platformer/assets/scenes/bullet.cubos.meta new file mode 100644 index 0000000..7a3c284 --- /dev/null +++ b/platformer/assets/scenes/bullet.cubos.meta @@ -0,0 +1,3 @@ +{ + "id": "866d4e1e-ea40-4de5-913c-bae62ab9bb27" +} \ No newline at end of file diff --git a/platformer/assets/scenes/cannon.cubos b/platformer/assets/scenes/cannon.cubos new file mode 100644 index 0000000..7994d52 --- /dev/null +++ b/platformer/assets/scenes/cannon.cubos @@ -0,0 +1,28 @@ +{ + "entities": { + "base": { + "demo::Cannon": { + "bullet": "866d4e1e-ea40-4de5-913c-bae62ab9bb27", + "bulletTime": 1.0 + }, + "cubos::engine::RenderableGrid": { + "asset": "8f633d2c-618c-40ca-859d-fe24b9ed7219", + "offset": { + "x": -4, + "y": -4, + "z": -4 + } + }, + "cubos::engine::Scale": 0.5, + "cubos::engine::Position": {}, + "cubos::engine::LocalToWorld": {}, + "cubos::engine::BoxCollisionShape": { + "x": 4, + "y": 4, + "z": 4 + }, + "cubos::engine::Collider": {}, + "cubos::engine::PhysicsVelocity": {} + } + } +} \ No newline at end of file diff --git a/platformer/assets/scenes/cannon.cubos.meta b/platformer/assets/scenes/cannon.cubos.meta new file mode 100644 index 0000000..72ee874 --- /dev/null +++ b/platformer/assets/scenes/cannon.cubos.meta @@ -0,0 +1,3 @@ +{ + "id": "866d4e1e-ea40-4de5-913c-bae62ab9bb26" +} \ No newline at end of file diff --git a/platformer/assets/scenes/goal.cubos b/platformer/assets/scenes/goal.cubos new file mode 100644 index 0000000..b819b18 --- /dev/null +++ b/platformer/assets/scenes/goal.cubos @@ -0,0 +1,23 @@ +{ + "entities": { + "base": { + "cubos::engine::RenderableGrid": { + "asset": "1e314618-950c-4505-a275-5881102f8d71", + "offset": { + "x": -4, + "y": -0.5, + "z": -8 + } + }, + "cubos::engine::Position": {}, + "cubos::engine::LocalToWorld": {}, + "cubos::engine::BoxCollisionShape": { + "x": 4, + "y": 0.5, + "z": 8 + }, + "cubos::engine::Collider": {}, + "cubos::engine::PhysicsVelocity": {} + } + } +} \ No newline at end of file diff --git a/platformer/assets/scenes/goal.cubos.meta b/platformer/assets/scenes/goal.cubos.meta new file mode 100644 index 0000000..4c0617b --- /dev/null +++ b/platformer/assets/scenes/goal.cubos.meta @@ -0,0 +1,3 @@ +{ + "id": "866d4e1e-ea40-4de5-913c-bae62ab9bb25" +} \ No newline at end of file diff --git a/platformer/assets/scenes/level1.cubos b/platformer/assets/scenes/level1.cubos new file mode 100644 index 0000000..e3312eb --- /dev/null +++ b/platformer/assets/scenes/level1.cubos @@ -0,0 +1,125 @@ +{ + "imports": { + "goal": "866d4e1e-ea40-4de5-913c-bae62ab9bb25", + "platform-1": "2b8271b9-6f92-4098-90d9-252aeca49755", + "platform-2": "99ad5197-9bbf-402c-be66-5128ece83270", + "platform-3": "99ad5197-9bbf-402c-be66-5128ece83270", + "platform-4": "2b8271b9-6f92-4098-90d9-252aeca49755", + "cannon-1": "866d4e1e-ea40-4de5-913c-bae62ab9bb26", + "cannon-2": "866d4e1e-ea40-4de5-913c-bae62ab9bb26", + "cannon-3": "866d4e1e-ea40-4de5-913c-bae62ab9bb26", + "cannon-4": "866d4e1e-ea40-4de5-913c-bae62ab9bb26" + }, + "entities": { + "spawn-0": { + "demo::Spawn": { + "playerId": 0, + "bindings": "1c2497cc-3aec-4455-889f-492001172273" + }, + "cubos::engine::Position": { + "x": 10, + "y": 5, + "z": 2.5 + } + }, + "spawn-1": { + "demo::Spawn": { + "playerId": 1, + "bindings": "093597a1-771b-4196-878c-3ef5c3e27845" + }, + "cubos::engine::Position": { + "x": 10, + "y": 5, + "z": -2.5 + } + }, + "goal.base": { + "demo::Victory": 0, + "cubos::engine::Position": { + "x": -70 + } + }, + "cannon-1.base": { + "cubos::engine::Position": { + "x": -10, + "y": 2, + "z": -25 + } + }, + "cannon-2.base": { + "cubos::engine::Position": { + "x": -30, + "y": 2, + "z": -25 + } + }, + "cannon-3.base": { + "cubos::engine::Position": { + "x": -50, + "y": 2, + "z": -25 + } + }, + "cannon-4.base": { + "cubos::engine::Position": { + "x": -70, + "y": 2, + "z": -25 + } + }, + "platform-1.base": { + "demo::Mover": { + "from": { + "x": -10, + "y": 0, + "z": 0 + }, + "to": { + "x": -10, + "y": 0, + "z": -15 + }, + "speed": 5.0 + } + }, + "platform-2.base": { + "cubos::engine::Position": { + "x": 10 + } + }, + "platform-3.base": { + "cubos::engine::Position": { + "x": -30, + "y": 0, + "z": -15 + } + }, + "platform-4.base": { + "demo::Mover": { + "from": { + "x": -50, + "y": 0, + "z": -25 + }, + "to": { + "x": -50, + "y": 0, + "z": -5 + }, + "speed": 5.0 + } + }, + "sun": { + "cubos::engine::Rotation": { + "w": 0.854, + "x": 0.354, + "y": 0.354, + "z": -0.146 + }, + "cubos::engine::LocalToWorld": {}, + "cubos::engine::DirectionalLight": { + "intensity": 0.7 + } + } + } +} \ No newline at end of file diff --git a/platformer/assets/scenes/level1.cubos.meta b/platformer/assets/scenes/level1.cubos.meta new file mode 100644 index 0000000..c165113 --- /dev/null +++ b/platformer/assets/scenes/level1.cubos.meta @@ -0,0 +1,3 @@ +{ + "id": "541d2b6e-6171-4dd3-96a2-bd53d55b1eb1" +} \ No newline at end of file diff --git a/platformer/assets/scenes/moving.cubos b/platformer/assets/scenes/moving.cubos new file mode 100644 index 0000000..f87157c --- /dev/null +++ b/platformer/assets/scenes/moving.cubos @@ -0,0 +1,29 @@ +{ + "entities": { + "base": { + "cubos::engine::RenderableGrid": { + "asset": "e8b952de-41ce-4c63-bd0c-af2c6b501882", + "offset": { + "x": -8, + "y": -0.5, + "z": -8 + } + }, + "cubos::engine::Position": {}, + "cubos::engine::LocalToWorld": {}, + "cubos::engine::BoxCollisionShape": { + "x": 8, + "y": 0.5, + "z": 8 + }, + "cubos::engine::Collider": {}, + "cubos::engine::PhysicsVelocity": {}, + "cubos::engine::PhysicsMass": { + "mass": 1.0, + "inverseMass": 1.0 + }, + "cubos::engine::PreviousPosition": {}, + "cubos::engine::AccumulatedCorrection": {} + } + } +} \ No newline at end of file diff --git a/platformer/assets/scenes/moving.cubos.meta b/platformer/assets/scenes/moving.cubos.meta new file mode 100644 index 0000000..0aa99e7 --- /dev/null +++ b/platformer/assets/scenes/moving.cubos.meta @@ -0,0 +1,3 @@ +{ + "id": "2b8271b9-6f92-4098-90d9-252aeca49755" +} \ No newline at end of file diff --git a/platformer/assets/scenes/platform.cubos b/platformer/assets/scenes/platform.cubos new file mode 100644 index 0000000..c620262 --- /dev/null +++ b/platformer/assets/scenes/platform.cubos @@ -0,0 +1,23 @@ +{ + "entities": { + "base": { + "cubos::engine::RenderableGrid": { + "asset": "e8b952de-41ce-4c63-bd0c-af2c6b501882", + "offset": { + "x": -8, + "y": -0.5, + "z": -8 + } + }, + "cubos::engine::Position": {}, + "cubos::engine::LocalToWorld": {}, + "cubos::engine::BoxCollisionShape": { + "x": 8, + "y": 0.5, + "z": 8 + }, + "cubos::engine::Collider": {}, + "cubos::engine::PhysicsVelocity": {} + } + } +} \ No newline at end of file diff --git a/platformer/assets/scenes/platform.cubos.meta b/platformer/assets/scenes/platform.cubos.meta new file mode 100644 index 0000000..8e2d23e --- /dev/null +++ b/platformer/assets/scenes/platform.cubos.meta @@ -0,0 +1,3 @@ +{ + "id": "99ad5197-9bbf-402c-be66-5128ece83270" +} \ No newline at end of file diff --git a/platformer/assets/scenes/player.cubos b/platformer/assets/scenes/player.cubos new file mode 100644 index 0000000..e2ef84a --- /dev/null +++ b/platformer/assets/scenes/player.cubos @@ -0,0 +1,119 @@ +{ + "entities": { + "player": { + "demo::Player": { + "torso": "torso", + "leftHand": "left-hand", + "rightHand": "right-hand", + "leftFoot": "left-foot", + "rightFoot": "right-foot", + "speed": 15.0, + "animationSpeed": 1.5, + "rotationSpeed": 20.0, + "jumpForce": 2500.0 + }, + "cubos::engine::LocalToWorld": {}, + "cubos::engine::Position": {}, + "cubos::engine::Rotation": {}, + "cubos::engine::Scale": 0.1, + "cubos::engine::PhysicsVelocity": {}, + "cubos::engine::PhysicsMass": { + "mass": 100.0, + "inverseMass": 0.01 + }, + "cubos::engine::PreviousPosition": {}, + "cubos::engine::AccumulatedCorrection": {}, + "cubos::engine::BoxCollisionShape": { + "x": 6, + "y": 11.5, + "z": 4.5 + }, + "cubos::engine::Collider": {} + }, + "camera": { + "demo::OrbitCameraController": { + "target": "player", + "theta": 90.0, + "phi": 15.0, + "distance": 15.0, + "speed": 10.0, + "rotationSpeed": 150.0, + "zoomSpeed": 30.0 + }, + "cubos::engine::Camera": {}, + "cubos::engine::LocalToWorld": {}, + "cubos::engine::Position": {}, + "cubos::engine::Rotation": {} + }, + "torso": { + "demo::Offset": { + "parent": "player" + }, + "cubos::engine::RenderableGrid": { + "asset": "059c16e7-a439-44c7-9bdc-6e069dba0c75", + "offset": { + "x": -6, + "y": -7.5, + "z": -4.5 + } + }, + "cubos::engine::LocalToWorld": {} + }, + "left-hand": { + "demo::Offset": { + "parent": "player" + }, + "cubos::engine::RenderableGrid": { + "asset": "ffbf1f87-6ffb-4395-8a30-92883f14dd4a", + "offset": { + "x": -1.5, + "y": -1.5, + "z": -1.5 + } + }, + "cubos::engine::LocalToWorld": {} + }, + "right-hand": { + "demo::Offset": { + "parent": "player" + }, + "cubos::engine::RenderableGrid": { + "asset": "521cec89-3392-450c-90f5-a06e1abd1691", + "offset": { + "x": -1.5, + "y": -1.5, + "z": -1.5 + } + }, + "cubos::engine::LocalToWorld": {} + }, + "left-foot": { + "demo::Offset": { + "parent": "player" + }, + "cubos::engine::RenderableGrid": { + "asset": "8f633d2c-618c-40ca-859d-fe24b9ed7207", + "offset": { + "x": -2, + "y": -2, + "z": -3 + } + }, + "cubos::engine::LocalToWorld": {} + }, + "right-foot": { + "demo::Offset": { + "parent": "player" + }, + "cubos::engine::RenderableGrid": { + "asset": "6b49fb4e-3d0d-4784-846f-ae4a6fe0bcbf", + "offset": { + "x": -2, + "y": -2, + "z": -3 + } + }, + "cubos::engine::LocalToWorld": {} + } + } +} \ No newline at end of file diff --git a/platformer/assets/scenes/player.cubos.meta b/platformer/assets/scenes/player.cubos.meta new file mode 100644 index 0000000..baef46e --- /dev/null +++ b/platformer/assets/scenes/player.cubos.meta @@ -0,0 +1,3 @@ +{ + "id": "931545f5-6c1e-43bf-bb1d-ba2c1f6e9333" +} \ No newline at end of file diff --git a/platformer/components.hpp b/platformer/components.hpp new file mode 100644 index 0000000..40a6c91 --- /dev/null +++ b/platformer/components.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include + +#include diff --git a/platformer/main.cpp b/platformer/main.cpp deleted file mode 100644 index 067c07f..0000000 --- a/platformer/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -using namespace cubos::engine; - -int main(int argc, char** argv) -{ - Cubos cubos{argc, argv}; - - cubos.run(); -} diff --git a/platformer/src/cannon/bullet.cpp b/platformer/src/cannon/bullet.cpp new file mode 100644 index 0000000..e7cf1d1 --- /dev/null +++ b/platformer/src/cannon/bullet.cpp @@ -0,0 +1,14 @@ +#include "bullet.hpp" + +#include + +#include +#include + +CUBOS_REFLECT_IMPL(demo::Bullet) +{ + return cubos::core::ecs::ComponentTypeBuilder("demo::Bullet") + .withField("velocity", &Bullet::velocity) + .withField("life", &Bullet::life) + .build(); +} diff --git a/platformer/src/cannon/bullet.hpp b/platformer/src/cannon/bullet.hpp new file mode 100644 index 0000000..f083945 --- /dev/null +++ b/platformer/src/cannon/bullet.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +#include + +namespace demo +{ + struct [[cubos::component("")]] Bullet + { + CUBOS_REFLECT; + + glm::vec3 velocity = {0.0F, 0.0F, 0.0F}; + float life = 5.0F; + }; +} // namespace demo diff --git a/platformer/src/cannon/cannon.cpp b/platformer/src/cannon/cannon.cpp new file mode 100644 index 0000000..da7adf0 --- /dev/null +++ b/platformer/src/cannon/cannon.cpp @@ -0,0 +1,14 @@ +#include "cannon.hpp" + +#include + +#include + +CUBOS_REFLECT_IMPL(demo::Cannon) +{ + return cubos::core::ecs::ComponentTypeBuilder("demo::Cannon") + .withField("bullet", &Cannon::bullet) + .withField("bulletTime", &Cannon::bulletTime) + .withField("timer", &Cannon::timer) + .build(); +} diff --git a/platformer/src/cannon/cannon.hpp b/platformer/src/cannon/cannon.hpp new file mode 100644 index 0000000..9bb61d0 --- /dev/null +++ b/platformer/src/cannon/cannon.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +#include + +namespace demo +{ + struct [[cubos::component("")]] Cannon + { + CUBOS_REFLECT; + + cubos::engine::Asset bullet; + float bulletTime = 10.0F; + float timer = 0.0F; + }; +} // namespace demo diff --git a/platformer/src/cannon/plugin.cpp b/platformer/src/cannon/plugin.cpp new file mode 100644 index 0000000..ae81241 --- /dev/null +++ b/platformer/src/cannon/plugin.cpp @@ -0,0 +1,53 @@ +#include "plugin.hpp" +#include "cannon.hpp" +#include "bullet.hpp" + +#include +#include + +using cubos::core::ecs::Commands; +using cubos::core::ecs::Query; +using cubos::core::ecs::Read; +using cubos::core::ecs::Write; + +using namespace cubos::engine; + +using namespace demo; + +static void cannonSystem(Commands cmds, Query, Read> cannons, Read deltaTime, + Write assets) +{ + for (auto [entity, cannon, position] : cannons) + { + cannon->timer -= deltaTime->value; + if (cannon->timer < 0.0F) + { + cmds.spawn(assets->read(cannon->bullet)->blueprint) + .add("base", Position{position->vec}) + .get("base") + .velocity = glm::vec3{0.0F, 0.0F, 15.0F}; + cannon->timer = cannon->bulletTime; + } + } +} + +static void bulletSystem(Commands cmds, Query, Write> bullets, Read deltaTime) +{ + for (auto [entity, bullet, position] : bullets) + { + position->vec += bullet->velocity * deltaTime->value; + bullet->life -= deltaTime->value; + if (bullet->life < 0.0F) + { + cmds.destroy(entity); + } + } +} + +void demo::cannonPlugin(Cubos& cubos) +{ + cubos.addComponent(); + cubos.addComponent(); + cubos.system(cannonSystem); + cubos.system(bulletSystem); +} diff --git a/platformer/src/cannon/plugin.hpp b/platformer/src/cannon/plugin.hpp new file mode 100644 index 0000000..4d0d94e --- /dev/null +++ b/platformer/src/cannon/plugin.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace demo +{ + void cannonPlugin(cubos::engine::Cubos& cubos); +} diff --git a/platformer/src/collider_gizmos/plugin.cpp b/platformer/src/collider_gizmos/plugin.cpp new file mode 100644 index 0000000..1570dad --- /dev/null +++ b/platformer/src/collider_gizmos/plugin.cpp @@ -0,0 +1,24 @@ +#include "plugin.hpp" + +#include +#include + +using cubos::core::ecs::Query; +using cubos::core::ecs::Read; +using cubos::core::ecs::Write; + +using namespace cubos::engine; + +static void gizmosSystem(Write gizmos, Query> colliders) +{ + for (auto [entity, collider] : colliders) + { + gizmos->drawWireBox("collider", collider->worldAABB.diag[0], collider->worldAABB.diag[1]); + } +} + +void demo::colliderGizmosPlugin(Cubos& cubos) +{ + cubos.addPlugin(gizmosPlugin); + cubos.system(gizmosSystem).before("cubos.gizmos.draw").after("cubos.collisions.aabb.update"); +} diff --git a/platformer/src/collider_gizmos/plugin.hpp b/platformer/src/collider_gizmos/plugin.hpp new file mode 100644 index 0000000..b6e8488 --- /dev/null +++ b/platformer/src/collider_gizmos/plugin.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace demo +{ + void colliderGizmosPlugin(cubos::engine::Cubos& cubos); +} diff --git a/platformer/src/death/dead.cpp b/platformer/src/death/dead.cpp new file mode 100644 index 0000000..c7ba894 --- /dev/null +++ b/platformer/src/death/dead.cpp @@ -0,0 +1,8 @@ +#include "dead.hpp" + +#include + +CUBOS_REFLECT_IMPL(demo::Dead) +{ + return cubos::core::ecs::ComponentTypeBuilder("demo::Dead").build(); +} diff --git a/platformer/src/death/dead.hpp b/platformer/src/death/dead.hpp new file mode 100644 index 0000000..1ba92d3 --- /dev/null +++ b/platformer/src/death/dead.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace demo +{ + struct [[cubos::component("")]] Dead + { + CUBOS_REFLECT; + }; +} // namespace demo \ No newline at end of file diff --git a/platformer/src/death/plugin.cpp b/platformer/src/death/plugin.cpp new file mode 100644 index 0000000..eee4712 --- /dev/null +++ b/platformer/src/death/plugin.cpp @@ -0,0 +1,44 @@ +#include "plugin.hpp" + +#include + +#include "../player/player.hpp" +#include "dead.hpp" + +using cubos::core::ecs::Commands; +using cubos::core::ecs::Query; +using cubos::core::ecs::Read; +using cubos::core::ecs::Write; + +using namespace cubos::engine; + +using namespace demo; + +#define DEATH_HEIGHT -10.0F + +static void fallDetectionSystem(Commands cmds, Query, Read> query) +{ + for (auto [entity, player, collider] : query) + { + if (collider->worldAABB.diag[1].y < DEATH_HEIGHT) + { + cmds.add(entity, Dead{}); + } + } +} + +static void killSystem(Commands cmds, Query, Read> query) +{ + for (auto [entity, player, dead] : query) + { + cmds.destroy(entity); + } +} + +void demo::deathPlugin(Cubos& cubos) +{ + cubos.addComponent(); + + cubos.system(fallDetectionSystem).before("kill"); + cubos.system(killSystem).tagged("kill"); +} diff --git a/platformer/src/death/plugin.hpp b/platformer/src/death/plugin.hpp new file mode 100644 index 0000000..82d67f4 --- /dev/null +++ b/platformer/src/death/plugin.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace demo +{ + void deathPlugin(cubos::engine::Cubos& cubos); +} diff --git a/platformer/src/main.cpp b/platformer/src/main.cpp new file mode 100644 index 0000000..ff6d434 --- /dev/null +++ b/platformer/src/main.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "player/plugin.hpp" +#include "orbit_camera/plugin.hpp" +#include "spawn/plugin.hpp" +#include "collider_gizmos/plugin.hpp" +#include "offset/plugin.hpp" +#include "death/plugin.hpp" +#include "mover/plugin.hpp" +#include "victory/plugin.hpp" +#include "cannon/plugin.hpp" + +using cubos::core::ecs::Commands; +using cubos::core::ecs::Query; +using cubos::core::ecs::Read; +using cubos::core::ecs::Write; + +using namespace cubos::engine; + +static const Asset PlatformAsset = AnyAsset("059c16e7-a439-44c7-9bdc-6e069dba0c76"); +static const Asset PaletteAsset = AnyAsset("1aa5e234-28cb-4386-99b4-39386b0fc215"); +static const Asset SceneAsset = AnyAsset("059c16e7-a439-44c7-9bdc-6e069dba0c77"); + +static void settings(Write settings) +{ + settings->setString("assets.io.path", PROJECT_ASSETS_FOLDER); +} + +static void setup(Commands cmds, Write assets, Write renderer, Write activeCameras, + Write env, Write damping, Write gravity) +{ + // Load the palette asset and add two colors to it. + auto palette = assets->write(PaletteAsset); + + // Set the renderer's palette to the one we just modified. + (*renderer)->setPalette(*palette); + + // Spawn the level. + cmds.spawn(assets->read(Asset("541d2b6e-6171-4dd3-96a2-bd53d55b1eb1"))->blueprint); + + env->ambient = {0.4F, 0.4F, 0.4F}; + env->skyGradient[0] = {0.6F, 1.0F, 0.8F}; + env->skyGradient[1] = {0.25F, 0.65F, 1.0F}; + + damping->value = 0.99F; + gravity->value = glm::vec3{0.0F, -100.0F, 0.0F}; +} + +int main(int argc, char** argv) +{ + Cubos cubos{argc, argv}; + + cubos.addPlugin(rendererPlugin); + cubos.addPlugin(voxelsPlugin); + cubos.addPlugin(inputPlugin); + cubos.addPlugin(scenePlugin); + cubos.addPlugin(physicsPlugin); + cubos.addPlugin(collisionsPlugin); + + cubos.addPlugin(tesseratos::plugin); + + cubos.addPlugin(demo::playersPlugin); + cubos.addPlugin(demo::orbitCameraPlugin); + cubos.addPlugin(demo::spawnPlugin); + // cubos.addPlugin(demo::colliderGizmosPlugin); + cubos.addPlugin(demo::offsetPlugin); + cubos.addPlugin(demo::deathPlugin); + cubos.addPlugin(demo::moverPlugin); + cubos.addPlugin(demo::victoryPlugin); + cubos.addPlugin(demo::cannonPlugin); + + cubos.startupSystem(settings).tagged("cubos.settings"); + cubos.startupSystem(setup).tagged("cubos.assets").after("cubos.renderer.init"); + + cubos.run(); +} diff --git a/platformer/src/mover/mover.cpp b/platformer/src/mover/mover.cpp new file mode 100644 index 0000000..d8c88d6 --- /dev/null +++ b/platformer/src/mover/mover.cpp @@ -0,0 +1,17 @@ +#include "mover.hpp" + +#include + +#include +#include + +CUBOS_REFLECT_IMPL(demo::Mover) +{ + return cubos::core::ecs::ComponentTypeBuilder("demo::Mover") + .withField("from", &Mover::from) + .withField("to", &Mover::to) + .withField("speed", &Mover::speed) + .withField("direction", &Mover::direction) + .withField("hasStarted", &Mover::hasStarted) + .build(); +} diff --git a/platformer/src/mover/mover.hpp b/platformer/src/mover/mover.hpp new file mode 100644 index 0000000..b7a6a3e --- /dev/null +++ b/platformer/src/mover/mover.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include + +namespace demo +{ + struct [[cubos::component("")]] Mover + { + CUBOS_REFLECT; + + glm::vec3 from; + glm::vec3 to; + glm::vec3 velocity = {0.0F, 0.0F, 0.0F}; + float speed = 10.0F; + bool direction = false; + bool hasStarted = false; + }; +} // namespace demo diff --git a/platformer/src/mover/plugin.cpp b/platformer/src/mover/plugin.cpp new file mode 100644 index 0000000..4e69822 --- /dev/null +++ b/platformer/src/mover/plugin.cpp @@ -0,0 +1,47 @@ +#include "plugin.hpp" +#include "mover.hpp" + +#include +#include + +#include + +using cubos::core::ecs::Query; +using cubos::core::ecs::Read; +using cubos::core::ecs::Write; + +using namespace cubos::engine; + +using namespace demo; + +static void moverSystem(Query, Write, Write> movers, Read deltaTime) +{ + for (auto [entity, mover, position, velocity] : movers) + { + if (!mover->hasStarted) + { + position->vec = mover->from; + mover->hasStarted = true; + mover->direction = true; + } + + auto source = mover->direction ? mover->from : mover->to; + auto target = mover->direction ? mover->to : mover->from; + + if (glm::dot(target - position->vec, source - position->vec) > 0.0F) + { + mover->direction = !mover->direction; + std::swap(source, target); + } + + velocity->velocity = glm::normalize(target - position->vec) * mover->speed; + velocity->force = {0.0F, 9.81F, 0.0F}; + mover->velocity = velocity->velocity; + } +} + +void demo::moverPlugin(Cubos& cubos) +{ + cubos.addComponent(); + cubos.system(moverSystem).after("cubos.physics.apply_forces"); +} diff --git a/platformer/src/mover/plugin.hpp b/platformer/src/mover/plugin.hpp new file mode 100644 index 0000000..6a76d5c --- /dev/null +++ b/platformer/src/mover/plugin.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace demo +{ + void moverPlugin(cubos::engine::Cubos& cubos); +} diff --git a/platformer/src/offset/offset.cpp b/platformer/src/offset/offset.cpp new file mode 100644 index 0000000..d45f4a3 --- /dev/null +++ b/platformer/src/offset/offset.cpp @@ -0,0 +1,13 @@ +#include "offset.hpp" + +#include + +#include + +CUBOS_REFLECT_IMPL(demo::Offset) +{ + return cubos::core::ecs::ComponentTypeBuilder("demo::Offset") + .withField("vec", &Offset::vec) + .withField("parent", &Offset::parent) + .build(); +} diff --git a/platformer/src/offset/offset.hpp b/platformer/src/offset/offset.hpp new file mode 100644 index 0000000..4955555 --- /dev/null +++ b/platformer/src/offset/offset.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +#include + +namespace demo +{ + struct [[cubos::component("")]] Offset + { + CUBOS_REFLECT; + + glm::vec3 vec; + cubos::core::ecs::Entity parent; + }; +} // namespace demo diff --git a/platformer/src/offset/plugin.cpp b/platformer/src/offset/plugin.cpp new file mode 100644 index 0000000..e504381 --- /dev/null +++ b/platformer/src/offset/plugin.cpp @@ -0,0 +1,37 @@ +#include "plugin.hpp" +#include "offset.hpp" + +#include + +#include + +using cubos::core::ecs::Commands; +using cubos::core::ecs::Query; +using cubos::core::ecs::Read; +using cubos::core::ecs::Write; + +using namespace cubos::engine; + +using namespace demo; + +static void offsetSystem(Commands cmds, Query> offsets, Query> localToWorlds) +{ + for (auto [entity, offset] : offsets) + { + if (!localToWorlds[offset->parent]) + { + cmds.destroy(entity); + continue; + } + + auto [entityLocalToWorld] = *localToWorlds[entity]; + auto [parentLocalToWorld] = *localToWorlds[offset->parent]; + entityLocalToWorld->mat = parentLocalToWorld->mat * glm::translate(glm::mat4(1.0f), offset->vec); + } +} + +void demo::offsetPlugin(Cubos& cubos) +{ + cubos.addComponent(); + cubos.system(offsetSystem).after("cubos.transform.update").before("cubos.renderer.frame"); +} diff --git a/platformer/src/offset/plugin.hpp b/platformer/src/offset/plugin.hpp new file mode 100644 index 0000000..7c86df6 --- /dev/null +++ b/platformer/src/offset/plugin.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace demo +{ + void offsetPlugin(cubos::engine::Cubos& cubos); +} diff --git a/platformer/src/orbit_camera/controller.cpp b/platformer/src/orbit_camera/controller.cpp new file mode 100644 index 0000000..31ac8e4 --- /dev/null +++ b/platformer/src/orbit_camera/controller.cpp @@ -0,0 +1,21 @@ +#include "controller.hpp" + +#include + +#include +#include + +CUBOS_REFLECT_IMPL(demo::OrbitCameraController) +{ + return cubos::core::ecs::ComponentTypeBuilder("demo::OrbitCameraController") + .withField("playerId", &OrbitCameraController::playerId) + .withField("target", &OrbitCameraController::target) + .withField("center", &OrbitCameraController::center) + .withField("speed", &OrbitCameraController::speed) + .withField("rotationSpeed", &OrbitCameraController::rotationSpeed) + .withField("zoomSpeed", &OrbitCameraController::zoomSpeed) + .withField("distance", &OrbitCameraController::distance) + .withField("theta", &OrbitCameraController::theta) + .withField("phi", &OrbitCameraController::phi) + .build(); +} diff --git a/platformer/src/orbit_camera/controller.hpp b/platformer/src/orbit_camera/controller.hpp new file mode 100644 index 0000000..9d1bfa8 --- /dev/null +++ b/platformer/src/orbit_camera/controller.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include + +#include + +namespace demo +{ + struct [[cubos::component("")]] OrbitCameraController + { + CUBOS_REFLECT; + + int playerId = 0; + cubos::core::ecs::Entity target; + glm::vec3 center = {0.0F, 0.0F, 0.0F}; + float speed = 1.0F; + float rotationSpeed = 10.0F; + float zoomSpeed = 10.0F; + float distance = 100.0F; + float theta = 0.0F; + float phi = 45.0F; + }; +} // namespace demo diff --git a/platformer/src/orbit_camera/plugin.cpp b/platformer/src/orbit_camera/plugin.cpp new file mode 100644 index 0000000..7f6cabe --- /dev/null +++ b/platformer/src/orbit_camera/plugin.cpp @@ -0,0 +1,94 @@ +#include "plugin.hpp" +#include "controller.hpp" +#include "../player/player.hpp" + +#include +#include +#include +#include + +#include + +using cubos::core::ecs::Query; +using cubos::core::ecs::Read; +using cubos::core::ecs::Write; + +using namespace cubos::engine; + +using namespace demo; + +static void inputSystem(Read input, Query> cameras, Read deltaTime) +{ + for (auto [entity, camera] : cameras) + { + auto lookHorizontal = input->axis("look-horizontal", camera->playerId); + if (glm::abs(lookHorizontal) < 0.1F) + { + lookHorizontal = 0.0F; + } + + auto lookVertical = input->axis("look-vertical", camera->playerId); + if (glm::abs(lookVertical) < 0.1F) + { + lookVertical = 0.0F; + } + + camera->theta += lookHorizontal * deltaTime->value * camera->rotationSpeed; + camera->phi += lookVertical * deltaTime->value * camera->rotationSpeed; + camera->phi = glm::clamp(camera->phi, 0.1F, 89.0F); + + auto lookZoom = input->axis("look-zoom", camera->playerId); + if (glm::abs(lookZoom) < 0.1F) + { + lookZoom = 0.0F; + } + + camera->distance += lookZoom * deltaTime->value * camera->zoomSpeed; + camera->distance = glm::clamp(camera->distance, 15.0F, 100.0F); + } +} + +static void followSystem(Query, Write> cameras, Query> positions, + Read deltaTime, Query> players) +{ + for (auto [orbitEntity, orbitCamera, orbitRotation] : cameras) + { + auto [orbitPosition] = *positions[orbitEntity]; + if (auto targetComponents = positions[orbitCamera->target]) + { + auto [targetPosition] = *targetComponents; + orbitCamera->center = + glm::mix(orbitCamera->center, targetPosition->vec, orbitCamera->speed * deltaTime->value); + + glm::vec3 offset = {glm::cos(glm::radians(orbitCamera->phi)) * glm::cos(glm::radians(orbitCamera->theta)), + glm::sin(glm::radians(orbitCamera->phi)), + glm::cos(glm::radians(orbitCamera->phi)) * glm::sin(glm::radians(orbitCamera->theta))}; + + orbitPosition->vec = orbitCamera->center + offset * orbitCamera->distance; + orbitRotation->quat = glm::quatLookAt(-offset, {0.0F, 1.0F, 0.0F}); + + if (auto playerComponents = players[orbitCamera->target]) + { + auto [player] = *playerComponents; + player->forward = glm::normalize(glm::vec3(offset.x, 0.0F, offset.z)); + player->right = glm::normalize(glm::cross(player->forward, {0.0F, 1.0F, 0.0F})); + } + } + } +} + +static void registerSystem(Write activeCameras, Query> orbitCameras) +{ + for (auto [orbitEntity, orbitCamera] : orbitCameras) + { + activeCameras->entities[orbitCamera->playerId] = orbitEntity; + } +} + +void demo::orbitCameraPlugin(Cubos& cubos) +{ + cubos.addComponent(); + cubos.system(inputSystem); + cubos.system(followSystem); + cubos.system(registerSystem); +} diff --git a/platformer/src/orbit_camera/plugin.hpp b/platformer/src/orbit_camera/plugin.hpp new file mode 100644 index 0000000..01e8c65 --- /dev/null +++ b/platformer/src/orbit_camera/plugin.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace demo +{ + void orbitCameraPlugin(cubos::engine::Cubos& cubos); +} diff --git a/platformer/src/player/player.cpp b/platformer/src/player/player.cpp new file mode 100644 index 0000000..e21fb90 --- /dev/null +++ b/platformer/src/player/player.cpp @@ -0,0 +1,23 @@ +#include "player.hpp" + +#include + +#include + +CUBOS_REFLECT_IMPL(demo::Player) +{ + return cubos::core::ecs::ComponentTypeBuilder("demo::Player") + .withField("id", &Player::id) + .withField("isOnGround", &Player::isOnGround) + .withField("animationTime", &Player::animationTime) + .withField("animationSpeed", &Player::animationSpeed) + .withField("rotationSpeed", &Player::rotationSpeed) + .withField("speed", &Player::speed) + .withField("jumpForce", &Player::jumpForce) + .withField("torso", &Player::torso) + .withField("leftHand", &Player::leftHand) + .withField("rightHand", &Player::rightHand) + .withField("leftFoot", &Player::leftFoot) + .withField("rightFoot", &Player::rightFoot) + .build(); +} diff --git a/platformer/src/player/player.hpp b/platformer/src/player/player.hpp new file mode 100644 index 0000000..5136993 --- /dev/null +++ b/platformer/src/player/player.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include +#include + +namespace demo +{ + struct [[cubos::component("")]] Player + { + CUBOS_REFLECT; + + int id = 0; + bool isOnGround = false; + float animationTime = 0.0F; + float animationSpeed = 1.0F; + float rotationSpeed = 10.0F; + float jumpForce = 1000.0F; + float speed = 10.0F; + cubos::core::ecs::Entity torso; + cubos::core::ecs::Entity leftHand; + cubos::core::ecs::Entity rightHand; + cubos::core::ecs::Entity leftFoot; + cubos::core::ecs::Entity rightFoot; + glm::vec3 forward = {0.0F, 0.0F, 1.0F}; + glm::vec3 right = {1.0F, 0.0F, 0.0F}; + }; +} // namespace demo diff --git a/platformer/src/player/plugin.cpp b/platformer/src/player/plugin.cpp new file mode 100644 index 0000000..750f8a0 --- /dev/null +++ b/platformer/src/player/plugin.cpp @@ -0,0 +1,162 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include "../offset/offset.hpp" +#include "player.hpp" +#include "plugin.hpp" +#include "../mover/mover.hpp" +#include "../cannon/bullet.hpp" + +using cubos::core::ecs::Commands; +using cubos::core::ecs::Entity; +using cubos::core::ecs::EventReader; +using cubos::core::ecs::Query; +using cubos::core::ecs::Read; +using cubos::core::ecs::Write; + +using namespace cubos::engine; + +using namespace demo; + +static void move(Query, Write, Write, Write> query, + Query> movers, Query> offsets, Read input, Read deltaTime, + Write settings, EventReader collisions, Query> bullets) +{ + glm::vec3 addVelocity[] = {{0.0F, 0.0F, 0.0F}, {0.0F, 0.0F, 0.0F}}; + + for (auto collision : collisions) + { + // Only handle collisions between players and other entities which are not players. + if (!query[collision.entity] /* || query[collision.other]*/) + { + continue; + } + + auto [player, position, velocity, rotation] = *query[collision.entity]; + + if (bullets[collision.other]) + { + auto [bullet] = *bullets[collision.other]; + velocity->velocity += bullet->velocity * 10.0F; + velocity->velocity.y += 10.0F; + player->isOnGround = false; + continue; + } + + position->vec -= collision.normal * collision.penetration; + velocity->velocity -= collision.normal * glm::dot(collision.normal, velocity->velocity); + + if (movers[collision.other]) + { + auto [mover] = *movers[collision.other]; + CUBOS_DEBUG("deslocation: {}, {}, {}", mover->velocity.x, mover->velocity.y, mover->velocity.z); + addVelocity[player->id] = mover->velocity; + } + + if (collision.normal.y < -0.1F) + { + player->isOnGround = true; + } + } + + for (auto [entity, player, position, velocity, rotation] : query) + { + auto moveVertical = input->axis("vertical", player->id); + if (glm::abs(moveVertical) < 0.1F) + { + moveVertical = 0.0F; + } + + auto moveHorizontal = input->axis("horizontal", player->id); + if (glm::abs(moveHorizontal) < 0.1F) + { + moveHorizontal = 0.0F; + } + + auto jump = input->pressed("jump", player->id); + + glm::vec3 move = + moveVertical * player->forward * player->speed - moveHorizontal * player->right * player->speed; + + if (player->isOnGround) + { + velocity->velocity.x = move.x; + velocity->velocity.z = move.z; + velocity->velocity += addVelocity[player->id]; + + if (jump) + { + velocity->impulse += glm::vec3{0.0F, 1.0F, 0.0F} * player->jumpForce; + player->isOnGround = false; + } + } + + glm::vec3 targetTorso = {0.0F, 0.0F, 0.0F}; + glm::vec3 targetLeftHand = {7.0F, -3.0F, 2.0F}; + glm::vec3 targetRightHand = {-7.0F, -3.0F, 2.0F}; + glm::vec3 targetLeftFoot = {3.5F, -10.0F, 1.0F}; + glm::vec3 targetRightFoot = {-3.5F, -10.0F, 1.0F}; + + if (player->isOnGround) + { + player->animationTime += deltaTime->value * player->speed * player->animationSpeed; + + if (moveVertical != 0.0F || moveHorizontal != 0.0F) + { + targetLeftHand.y += glm::cos(player->animationTime); + targetLeftHand.z += glm::sin(player->animationTime); + targetRightHand.y += glm::cos(player->animationTime + glm::pi() / 2.0F); + targetRightHand.z += glm::sin(player->animationTime + glm::pi() / 2.0F); + + targetLeftFoot.y += glm::cos(player->animationTime) * 0.5F + 0.5F; + targetLeftFoot.z += glm::sin(player->animationTime); + targetRightFoot.y += glm::cos(player->animationTime + glm::pi()) * 0.5F + 0.5F; + targetRightFoot.z += glm::sin(player->animationTime + glm::pi()); + + targetTorso.y += glm::sin(player->animationTime) * 0.5F; + } + + player->isOnGround = false; + } + else + { + targetLeftHand.y += 5.0F; + targetRightHand.y += 5.0F; + } + + if (move.x != 0.0F || move.z != 0.0F) + { + auto desired = glm::quatLookAt(-glm::normalize(move), glm::vec3{0.0F, 1.0F, 0.0F}); + rotation->quat = glm::slerp(rotation->quat, desired, player->rotationSpeed * deltaTime->value); + } + + auto [torso] = *offsets[player->torso]; + auto [leftHand] = *offsets[player->leftHand]; + auto [rightHand] = *offsets[player->rightHand]; + auto [leftFoot] = *offsets[player->leftFoot]; + auto [rightFoot] = *offsets[player->rightFoot]; + torso->vec = glm::mix(torso->vec, targetTorso, deltaTime->value * 10.0F); + leftHand->vec = glm::mix(leftHand->vec, targetLeftHand, deltaTime->value * 10.0F); + rightHand->vec = glm::mix(rightHand->vec, targetRightHand, deltaTime->value * 10.0F); + leftFoot->vec = glm::mix(leftFoot->vec, targetLeftFoot, deltaTime->value * 10.0F); + rightFoot->vec = glm::mix(rightFoot->vec, targetRightFoot, deltaTime->value * 10.0F); + } +} + +// handle dead + +void demo::playersPlugin(Cubos& cubos) +{ + cubos.addComponent(); + cubos.system(move).tagged("player.move").tagged("cubos.physics.apply_forces").before("cubos.transform.update"); +} diff --git a/platformer/src/player/plugin.hpp b/platformer/src/player/plugin.hpp new file mode 100644 index 0000000..941590d --- /dev/null +++ b/platformer/src/player/plugin.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace demo +{ + void playersPlugin(cubos::engine::Cubos& cubos); +} diff --git a/platformer/src/spawn/plugin.cpp b/platformer/src/spawn/plugin.cpp new file mode 100644 index 0000000..54fafbf --- /dev/null +++ b/platformer/src/spawn/plugin.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +#include "../player/player.hpp" +#include "../orbit_camera/controller.hpp" +#include "plugin.hpp" +#include "spawn.hpp" + +using cubos::core::ecs::Commands; +using cubos::core::ecs::Query; +using cubos::core::ecs::Read; +using cubos::core::ecs::Write; + +using namespace cubos::engine; + +using namespace demo; + +static void spawnSystem(Commands cmds, Query> players, Query, Read> spawns, + Write assets, Write input) +{ + for (auto [spawnEnt, spawn, position] : spawns) + { + // Check if the player matching this spawn exists + bool foundPlayer = false; + for (auto [playerEnt, player] : players) + { + if (player->id == spawn->playerId) + { + foundPlayer = true; + break; + } + } + + // If it does, do nothing + if (foundPlayer) + { + continue; + } + + // Otherwise, spawn it + auto builder = cmds.spawn(assets->read(Asset("931545f5-6c1e-43bf-bb1d-ba2c1f6e9333"))->blueprint); + builder.get("player").id = spawn->playerId; + builder.get("player") = *position; + builder.get("camera").playerId = spawn->playerId; + input->bind(*assets->read(spawn->bindings), spawn->playerId); + } +} + +void demo::spawnPlugin(Cubos& cubos) +{ + cubos.addComponent(); + cubos.system(spawnSystem); +} diff --git a/platformer/src/spawn/plugin.hpp b/platformer/src/spawn/plugin.hpp new file mode 100644 index 0000000..c95381a --- /dev/null +++ b/platformer/src/spawn/plugin.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace demo +{ + void spawnPlugin(cubos::engine::Cubos& cubos); +} diff --git a/platformer/src/spawn/spawn.cpp b/platformer/src/spawn/spawn.cpp new file mode 100644 index 0000000..38cae41 --- /dev/null +++ b/platformer/src/spawn/spawn.cpp @@ -0,0 +1,13 @@ +#include "spawn.hpp" + +#include + +#include + +CUBOS_REFLECT_IMPL(demo::Spawn) +{ + return cubos::core::ecs::ComponentTypeBuilder("demo::Spawn") + .withField("playerId", &Spawn::playerId) + .withField("bindings", &Spawn::bindings) + .build(); +} diff --git a/platformer/src/spawn/spawn.hpp b/platformer/src/spawn/spawn.hpp new file mode 100644 index 0000000..d9e3b57 --- /dev/null +++ b/platformer/src/spawn/spawn.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include +#include +#include + +namespace demo +{ + struct [[cubos::component("")]] Spawn + { + CUBOS_REFLECT; + + int playerId = 0; + cubos::engine::Asset bindings; + }; +} // namespace demo diff --git a/platformer/src/victory/plugin.cpp b/platformer/src/victory/plugin.cpp new file mode 100644 index 0000000..849c2bf --- /dev/null +++ b/platformer/src/victory/plugin.cpp @@ -0,0 +1,48 @@ +#include "plugin.hpp" + +#include +#include + +#include "../player/player.hpp" +#include "victory.hpp" + +using cubos::core::ecs::Commands; +using cubos::core::ecs::EventReader; +using cubos::core::ecs::Query; +using cubos::core::ecs::Read; +using cubos::core::ecs::Write; + +using namespace cubos::engine; + +using namespace demo; + +static const Asset Scenes[] = {AnyAsset{"541d2b6e-6171-4dd3-96a2-bd53d55b1eb1"}}; + +static void victorySystem(Commands cmds, Query> victories, Query> players, + EventReader collisions, Query<> all, Write assets) +{ + for (auto collision : collisions) + { + if ((!victories[collision.entity] || !players[collision.other]) && + (!victories[collision.other] || !players[collision.entity])) + { + continue; + } + + auto [victory] = *victories[collision.entity]; + auto [player] = *players[collision.other]; + + for (auto [entity] : all) + { + cmds.destroy(entity); + } + cmds.spawn(assets->read(Scenes[victory->nextScene])->blueprint); + break; + } +} + +void demo::victoryPlugin(Cubos& cubos) +{ + cubos.addComponent(); + //cubos.system(victorySystem).after("cubos.collisions"); +} diff --git a/platformer/src/victory/plugin.hpp b/platformer/src/victory/plugin.hpp new file mode 100644 index 0000000..6b63a59 --- /dev/null +++ b/platformer/src/victory/plugin.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace demo +{ + void victoryPlugin(cubos::engine::Cubos& cubos); +} diff --git a/platformer/src/victory/victory.cpp b/platformer/src/victory/victory.cpp new file mode 100644 index 0000000..4e07604 --- /dev/null +++ b/platformer/src/victory/victory.cpp @@ -0,0 +1,11 @@ +#include "victory.hpp" + +#include +#include + +CUBOS_REFLECT_IMPL(demo::Victory) +{ + return cubos::core::ecs::ComponentTypeBuilder("demo::Victory") + .withField("nextScene", &Victory::nextScene) + .build(); +} diff --git a/platformer/src/victory/victory.hpp b/platformer/src/victory/victory.hpp new file mode 100644 index 0000000..42596bb --- /dev/null +++ b/platformer/src/victory/victory.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include + +#include + +namespace demo +{ + struct [[cubos::component("")]] Victory + { + CUBOS_REFLECT; + + int nextScene{}; + }; +} // namespace demo