10 auto ®istry = AScene::getRegistry();
12 registry.onComponentAdded(
13 [&renderer, ®istry](
const ecs::Entity e,
const std::type_info &type)
15 const auto *colorComp = registry.getComponent<
ecs::Color>(e);
16 const auto *fontComp = registry.getComponent<
ecs::Font>(e);
17 const auto *rectComp = registry.getComponent<
ecs::Rect>(e);
18 const auto *scaleComp = registry.getComponent<
ecs::Scale>(e);
19 const auto *textComp = registry.getComponent<
ecs::Text>(e);
20 const auto *textureComp = registry.getComponent<
ecs::Texture>(e);
25 if (textComp && transform && fontComp)
27 renderer->createFont(fontComp->
id, fontComp->path);
29 {.font_name = fontComp->
id,
30 .color = {.r = colorComp->r, .g = colorComp->g, .b = colorComp->b, .a = colorComp->a},
31 .content = textComp->content,
32 .size = textComp->font_size,
35 .name = textComp->
id});
40 const float scale_x = scaleComp ? scaleComp->x : 1.F;
41 const float scale_y = scaleComp ? scaleComp->y : 1.F;
43 renderer->createTexture(textureComp->
id, textureComp->path);
45 if (transform && textureComp)
49 renderer->createSprite(textureComp->
id + std::to_string(e), textureComp->
id, transform->x,
50 transform->y, scale_x, scale_y,
static_cast<int>(rectComp->pos_x),
51 static_cast<int>(rectComp->pos_y), rectComp->size_x, rectComp->size_y);
55 renderer->createSprite(textureComp->
id + std::to_string(e), textureComp->
id, transform->x,
63 registry.createEntity()
65 .with<ecs::Transform>(
"transform_title", 100.F, 60.F, 0.F)
68 .with<ecs::Text>(
"id", std::string(
"SOLO"), 80U)
73 registry.createEntity()
75 .with<ecs::Transform>(
"transform_menu", 100.F, 200.F + i * 60.F, 0.F)
86 auto ® = getRegistry();
91 m_animationTime += dt;
92 m_titlePulseTime += dt;
94 if (
auto *titleColor = reg.getComponent<
ecs::Color>(m_titleEntity))
96 const float pulse = (std::sin(m_titlePulseTime * 1.2f) + 1.0f) * 0.5f;
101 if (
auto *titleTransform = reg.getComponent<
ecs::Transform>(m_titleEntity))
103 titleTransform->y = 60.0f + std::sin(m_titlePulseTime * 0.8f) * 2.0f;
106 for (
auto &[entity, text] : texts)
108 if (text.content ==
"Level easy" || text.content ==
"Level medium" || text.content ==
"Go back to menu")
110 auto &color = colors.at(entity);
112 if (i == m_selectedIndex)
114 const float glowIntensity = std::sin(m_animationTime * 2.5f);
116 color.g =
static_cast<unsigned char>(191U + (glowIntensity * 50));
129 if (
auto *titleColor = reg.getComponent<
ecs::Color>(m_titleEntity))
131 const float pulsation = std::sin(m_titlePulseTime * 2.0f) * 0.4f + 0.6f;
136 if (
auto *fpsText = reg.getComponent<
ecs::Text>(m_fpsEntity))
138 fpsText->content =
"FPS: " + std::to_string(
static_cast<int>(1 / dt));