Skip to content

Commit

Permalink
docs: add CuboSurfers models and plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Jun 8, 2024
1 parent cc54607 commit 542ec25
Show file tree
Hide file tree
Showing 46 changed files with 461 additions and 59 deletions.
3 changes: 1 addition & 2 deletions engine/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,4 @@ make_sample(DIR "gizmos")
make_sample(DIR "ui")
make_sample(DIR "physics" ASSETS)
make_sample(DIR "complex-physics" ASSETS)

make_sample(DIR "games/subway-surfers" ASSETS)
make_sample(DIR "games/cubosurfers" ASSETS SOURCES "spawner.cpp" "obstacle.cpp" "player.cpp")
21 changes: 21 additions & 0 deletions engine/samples/games/cubosurfers/assets/input.bind
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"actions": {
"left": {
"keys": [
"A",
"Left"
]
},
"right": {
"keys": [
"D",
"Right"
]
},
"restart": {
"keys": [
"R"
]
}
}
}
3 changes: 3 additions & 0 deletions engine/samples/games/cubosurfers/assets/input.bind.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "b20900a4-20ee-4caa-8830-14585050bead"
}
Binary file added engine/samples/games/cubosurfers/assets/main.pal
Binary file not shown.
3 changes: 3 additions & 0 deletions engine/samples/games/cubosurfers/assets/main.pal.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "101da567-3d23-46ae-a391-c10ec00e8718"
}
108 changes: 108 additions & 0 deletions engine/samples/games/cubosurfers/assets/scenes/main.cubos
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"entities": {
"render-target": {
"cubos::engine::RenderTargetDefaults": {}
},
"player": {
"cubos::engine::RenderVoxelGrid": {
"asset": "57d1b886-8543-4b8b-8f78-d911e9c4f896",
"offset": {
"x": -4,
"y": 0,
"z": -4
}
},
"cubos::engine::Position": {
"x": 0,
"y": 0,
"z": 0
},
"cubos::engine::BoxCollisionShape": {
"x": 3.0,
"y": 7.0,
"z": 2.0
},
"cubos::engine::Collider": {},
"Player": {
"speed": 5,
"laneWidth": 9
}
},
"track1": {
"cubos::engine::RenderVoxelGrid": {
"asset": "746088e3-84ec-4483-b4b2-216ae690c3b7",
"offset": {
"x": -16,
"y": -1,
"z": 0
}
},
"cubos::engine::Position": {
"x": 0,
"y": 0,
"z": -48
},
"cubos::engine::Scale": 2
},
"track2": {
"cubos::engine::RenderVoxelGrid": {
"asset": "746088e3-84ec-4483-b4b2-216ae690c3b7",
"offset": {
"x": -16,
"y": -1,
"z": 0
}
},
"cubos::engine::Position": {
"x": 0,
"y": 0,
"z": 208
},
"cubos::engine::Scale": 2
},
"obstacle-spawner": {
"cubos::engine::Position": {
"x": 0,
"y": 0,
"z": 300
},
"Spawner": {
"scene": "b15272c5-08c9-47f5-9b24-1192332580a8",
"sceneRoot": "base",
"period": 1.0,
"laneWidth": 9
}
},
"sun": {
"cubos::engine::DirectionalLight": {
"color": {
"x": 1.0,
"y": 1.0,
"z": 1.0
},
"intensity": 1.0
},
"cubos::engine::Rotation": {
"w": 0.783,
"x": 0.488,
"y": 0.327,
"z": 0.204
}
},
"camera": {
"cubos::engine::PerspectiveCamera": {},
"cubos::engine::DrawsTo@render-target": {},
"cubos::engine::Position": {
"x": 0,
"y": 12.5,
"z": -25
},
"cubos::engine::Rotation": {
"x": 0,
"y": 1,
"z": 0,
"w": 0
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "ee5bb451-05b7-430f-a641-a746f7009eef"
}
34 changes: 34 additions & 0 deletions engine/samples/games/cubosurfers/assets/scenes/obstacle.cubos
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"entities": {
"base": {
"cubos::engine::RenderVoxelGrid": {
"asset": "fe862296-fab7-4bf9-b62e-3cc28448dff1",
"offset": {
"x": -4,
"y": 0,
"z": -4
}
},
"cubos::engine::Rotation": {
"x": 0,
"y": 1,
"z": 0,
"w": 0
},
"cubos::engine::BoxCollisionShape": {
"x": 3.0,
"y": 7.0,
"z": 2.0
},
"cubos::engine::Collider": {},
"Obstacle": {
"velocity": {
"x": 0,
"y": 0,
"z": -100
},
"killZ": -10
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "b15272c5-08c9-47f5-9b24-1192332580a8"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "fe862296-fab7-4bf9-b62e-3cc28448dff1"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "57d1b886-8543-4b8b-8f78-d911e9c4f896"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "c7263b46-be18-47c2-b3ef-05592b2e9dec"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "4892c2f3-10b3-4ca7-9de3-822b77a0ba7e"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "732498a6-7675-4efa-86ef-8f35d3bec485"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "fd89da0f-72d2-4ef9-9297-f73ff2ca5c63"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "746088e3-84ec-4483-b4b2-216ae690c3b7"
}
Binary file not shown.
Binary file not shown.
69 changes: 69 additions & 0 deletions engine/samples/games/cubosurfers/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <cubos/engine/assets/plugin.hpp>
#include <cubos/engine/collisions/colliding_with.hpp>
#include <cubos/engine/defaults/plugin.hpp>
#include <cubos/engine/input/plugin.hpp>
#include <cubos/engine/render/lights/environment.hpp>
#include <cubos/engine/render/voxels/palette.hpp>
#include <cubos/engine/scene/plugin.hpp>
#include <cubos/engine/settings/plugin.hpp>
#include <cubos/engine/voxels/plugin.hpp>

#include "obstacle.hpp"
#include "player.hpp"
#include "spawner.hpp"

using namespace cubos::engine;

static const Asset<Scene> SceneAsset = AnyAsset("ee5bb451-05b7-430f-a641-a746f7009eef");
static const Asset<VoxelPalette> PaletteAsset = AnyAsset("101da567-3d23-46ae-a391-c10ec00e8718");
static const Asset<InputBindings> InputBindingsAsset = AnyAsset("b20900a4-20ee-4caa-8830-14585050bead");

int main()
{
Cubos cubos{};

cubos.plugin(defaultsPlugin);
cubos.plugin(spawnerPlugin);
cubos.plugin(obstaclePlugin);
cubos.plugin(playerPlugin);

cubos.startupSystem("configure settings").tagged(settingsTag).call([](Settings& settings) {
settings.setString("assets.io.path", SAMPLE_ASSETS_FOLDER);
});

cubos.startupSystem("set the palette, environment, input bindings and spawn the scene")
.tagged(assetsTag)
.call([](Commands commands, const Assets& assets, RenderPalette& palette, Input& input,
RenderEnvironment& environment) {
palette.asset = PaletteAsset;
environment.ambient = {0.1F, 0.1F, 0.1F};
environment.skyGradient[0] = {0.2F, 0.4F, 0.8F};
environment.skyGradient[1] = {0.6F, 0.6F, 0.8F};
input.bind(*assets.read(InputBindingsAsset));
commands.spawn(assets.read(SceneAsset)->blueprint);
});

cubos.system("restart the game on input")
.call([](Commands cmds, const Assets& assets, const Input& input, Query<Entity> all) {
if (input.justPressed("restart"))
{
for (auto [ent] : all)
{
cmds.destroy(ent);
}

cmds.spawn(assets.read(SceneAsset)->blueprint);
}
});

cubos.system("detect player vs obstacle collisions")
.call([](Query<const Player&, const CollidingWith&, const Obstacle&> collisions) {
for (auto [player, collidingWith, obstacle] : collisions)
{
CUBOS_INFO("Player collided with an obstacle!");
(void)player; // here to shut up 'unused variable warning', you can remove it
}
});

cubos.run();
}
41 changes: 41 additions & 0 deletions engine/samples/games/cubosurfers/obstacle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "obstacle.hpp"

#include <cubos/core/ecs/reflection.hpp>
#include <cubos/core/reflection/external/glm.hpp>
#include <cubos/core/reflection/external/primitives.hpp>
#include <cubos/core/reflection/external/string.hpp>

#include <cubos/engine/assets/plugin.hpp>
#include <cubos/engine/transform/plugin.hpp>

using namespace cubos::engine;

CUBOS_REFLECT_IMPL(Obstacle)
{
return cubos::core::ecs::TypeBuilder<Obstacle>("Obstacle")
.withField("velocity", &Obstacle::velocity)
.withField("killZ", &Obstacle::killZ)
.build();
}

void obstaclePlugin(cubos::engine::Cubos& cubos)
{
cubos.depends(assetsPlugin);
cubos.depends(transformPlugin);

cubos.component<Obstacle>();

cubos.system("move obstacles")
.call([](Commands cmds, const DeltaTime& dt, Query<Entity, const Obstacle&, Position&> obstacles) {
for (auto [ent, obstacle, position] : obstacles)
{
position.vec += obstacle.velocity * dt.value();
position.vec.y = glm::abs(glm::sin(position.vec.z * 0.15F)) * 1.5F;

if (position.vec.z < obstacle.killZ)
{
cmds.destroy(ent);
}
}
});
}
15 changes: 15 additions & 0 deletions engine/samples/games/cubosurfers/obstacle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <glm/vec3.hpp>

#include <cubos/engine/prelude.hpp>

struct Obstacle
{
CUBOS_REFLECT;

glm::vec3 velocity{0.0F, 0.0F, -1.0F};
float killZ{0.0F};
};

void obstaclePlugin(cubos::engine::Cubos& cubos);
Loading

0 comments on commit 542ec25

Please sign in to comment.