Fix propagate system
This commit is contained in:
@@ -14,4 +14,5 @@ struct SdlHandles
|
||||
struct Game
|
||||
{
|
||||
uint32_t ticks;
|
||||
uint32_t score;
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "sprite.hpp"
|
||||
|
||||
#include <flecs.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
struct Fruit
|
||||
{
|
||||
@@ -78,6 +79,7 @@ struct LevelModule
|
||||
});
|
||||
|
||||
// world.system<WorldPosition const, Fruit>("DespawnFruits")
|
||||
// .kind(flecs::OnValidate)
|
||||
// .each(
|
||||
// [](flecs::entity e, WorldPosition const& pos, Fruit)
|
||||
// {
|
||||
@@ -85,6 +87,11 @@ struct LevelModule
|
||||
// e.destruct();
|
||||
// });
|
||||
|
||||
world.system<Game, Fruit, Collided>("CollectItem")
|
||||
.term_at(0)
|
||||
.singleton()
|
||||
.each([](flecs::entity e, Game& game, Fruit, Collided) { game.score += 10; });
|
||||
|
||||
world.system<ButtonInput const, Position, Size const, Sprite const, Basket>("MoveBasket")
|
||||
.term_at(0)
|
||||
.singleton()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "physics.hpp"
|
||||
#include "definitions.hpp"
|
||||
#include "level.hpp"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
@@ -47,23 +46,6 @@ PhysicsModule::PhysicsModule(flecs::world& world)
|
||||
propagate_to_children(e, world_pos);
|
||||
});
|
||||
|
||||
world.system<SdlHandles const, WorldPosition const, Size const, CollisionBox>("DrawBoxes")
|
||||
.term_at(0)
|
||||
.singleton()
|
||||
.each(
|
||||
[](SdlHandles const& sdl_handles,
|
||||
WorldPosition const& pos,
|
||||
Size const& size,
|
||||
CollisionBox)
|
||||
{
|
||||
SDL_FRect rect{static_cast<float>(pos.x),
|
||||
static_cast<float>(pos.y),
|
||||
static_cast<float>(size.w),
|
||||
static_cast<float>(size.h)};
|
||||
SDL_SetRenderDrawColor(sdl_handles.renderer, 0, 0, 255, 255);
|
||||
SDL_RenderRect(sdl_handles.renderer, &rect);
|
||||
});
|
||||
|
||||
auto basket_query = world.query<Basket>();
|
||||
|
||||
world.system<WorldPosition const, Size const, CollisionBox>("CollisionCheck")
|
||||
@@ -75,8 +57,10 @@ PhysicsModule::PhysicsModule(flecs::world& world)
|
||||
if (e.parent().has<Basket>())
|
||||
return;
|
||||
|
||||
basket_query.first().children(
|
||||
[world_pos, size](flecs::entity basket_child)
|
||||
auto fruit = e.parent();
|
||||
auto basket = basket_query.first();
|
||||
basket.children(
|
||||
[fruit, world_pos, size](flecs::entity basket_child)
|
||||
{
|
||||
if (!basket_child.has<CollisionBox>())
|
||||
return;
|
||||
@@ -89,7 +73,7 @@ PhysicsModule::PhysicsModule(flecs::world& world)
|
||||
basket_child_pos->y + basket_child_size->h >= world_pos.y &&
|
||||
basket_child_pos->y <= world_pos.y + size.h)
|
||||
{
|
||||
spdlog::info("collision");
|
||||
fruit.add<Collided>();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -30,6 +30,10 @@ struct CollisionBox
|
||||
{
|
||||
};
|
||||
|
||||
struct Collided
|
||||
{
|
||||
};
|
||||
|
||||
struct PhysicsModule
|
||||
{
|
||||
PhysicsModule(flecs::world& world);
|
||||
|
||||
Reference in New Issue
Block a user