-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platformer): add death and respawn
- Loading branch information
1 parent
558cb1a
commit d5e91cc
Showing
7 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "dead.hpp" | ||
|
||
#include <cubos/core/ecs/component/reflection.hpp> | ||
|
||
CUBOS_REFLECT_IMPL(demo::Dead) | ||
{ | ||
return cubos::core::ecs::ComponentTypeBuilder<Dead>("demo::Dead").build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include <cubos/core/reflection/reflect.hpp> | ||
|
||
namespace demo | ||
{ | ||
struct [[cubos::component("")]] Dead | ||
{ | ||
CUBOS_REFLECT; | ||
}; | ||
} // namespace demo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "plugin.hpp" | ||
|
||
#include <cubos/engine/collisions/collider.hpp> | ||
|
||
#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<Write<Player>, Read<Collider>> 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<Player>, Read<Dead>> query) | ||
{ | ||
for (auto [entity, player, dead] : query) | ||
{ | ||
cmds.destroy(entity); | ||
} | ||
} | ||
|
||
void demo::deathPlugin(Cubos& cubos) | ||
{ | ||
cubos.addComponent<Dead>(); | ||
|
||
cubos.system(fallDetectionSystem).before("kill"); | ||
cubos.system(killSystem).tagged("kill"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include <cubos/engine/cubos.hpp> | ||
|
||
namespace demo | ||
{ | ||
void deathPlugin(cubos::engine::Cubos& cubos); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters