98 auto ® = getRegistry();
100 if (
auto *playerNameText = reg.getComponent<
ecs::Text>(m_playerNameValueEntity))
102 playerNameText->content = m_playerName.empty() ?
"Player" : m_playerName;
103 m_renderer->setTextContent(
"player_name_value", playerNameText->content);
106 if (
auto *skinText = reg.getComponent<
ecs::Text>(m_skinValueEntity))
108 skinText->content = std::to_string(m_skinIndex + 1);
109 m_renderer->setTextContent(
"skin_value", skinText->content);
112 if (
auto *skinRect = reg.getComponent<
ecs::Rect>(m_skinSpriteEntity))
114 const std::vector<float> shipLines = {0.0f, 17.0f, 34.0f, 51.0f};
115 if (m_skinIndex >= 0 && m_skinIndex <
static_cast<int>(shipLines.size()))
117 const float skinPosY = shipLines[
static_cast<size_t>(m_skinIndex)];
118 skinRect->pos_y = skinPosY;
119 skinRect->pos_x = 0.0f;
120 skinRect->size_x = 33U;
121 skinRect->size_y = 17U;
122 const std::string spriteName =
"player_preview_texture" + std::to_string(m_skinSpriteEntity);
123 m_renderer->setSpriteFrame(spriteName, 0,
static_cast<int>(skinPosY), 33, 17);
129 : AScene(assignedId), m_renderer(renderer)
131 auto ®istry = AScene::getRegistry();
133 registry.onComponentAdded(
134 [&renderer, ®istry](
const ecs::Entity e,
const std::type_info &type)
136 const auto *colorComp = registry.getComponent<
ecs::Color>(e);
137 const auto *fontComp = registry.getComponent<
ecs::Font>(e);
138 const auto *rectComp = registry.getComponent<
ecs::Rect>(e);
139 const auto *scaleComp = registry.getComponent<
ecs::Scale>(e);
140 const auto *textComp = registry.getComponent<
ecs::Text>(e);
141 const auto *textureComp = registry.getComponent<
ecs::Texture>(e);
146 if (textComp && transform && fontComp)
148 renderer->createFont(fontComp->
id, fontComp->path);
149 renderer->createText(
150 {.font_name = fontComp->
id,
151 .color = {.r = colorComp->r, .g = colorComp->g, .b = colorComp->b, .a = colorComp->a},
152 .content = textComp->content,
153 .size = textComp->font_size,
156 .name = textComp->
id});
161 const float scale_x = scaleComp ? scaleComp->x : 1.F;
162 const float scale_y = scaleComp ? scaleComp->y : 1.F;
164 renderer->createTexture(textureComp->
id, textureComp->path);
166 if (transform && textureComp)
170 renderer->createSprite(textureComp->
id + std::to_string(e), textureComp->
id, transform->x,
171 transform->y, scale_x, scale_y,
static_cast<int>(rectComp->pos_x),
172 static_cast<int>(rectComp->pos_y), rectComp->size_x, rectComp->size_y);
176 renderer->createSprite(textureComp->
id + std::to_string(e), textureComp->
id, transform->x,
184 registry.createEntity()
186 .with<ecs::Transform>(
"transform_title", 100.F, 60.F, 0.F)
189 .with<ecs::Text>(
"title", std::string(
"FLAPPY BIRD"), 80U)
194 registry.createEntity()
196 .with<ecs::Transform>(
"transform_menu", 100.F, 200.F + i * 60.F, 0.F)
204 registry.createEntity()
206 .with<ecs::Transform>(
"transform_player_name_value", 580.F, 200.F, 0.F)
210 .with<ecs::Text>(
"player_name_value",
m_playerName, 24U)
214 registry.createEntity()
216 .with<ecs::Transform>(
"transform_skin_value", 580.F, 260.F, 0.F)
220 .with<ecs::Text>(
"skin_value", std::to_string(
m_skinIndex + 1), 24U)
224 registry.createEntity()
225 .with<
ecs::Transform>(
"transform_player_preview", 750.F, 260.F, 0.F)
226 .with<ecs::Rect>(
"player_preview_rect", 0.F, 0.F, 33, 17)
227 .with<
ecs::Scale>(
"player_preview_scale", 3.0F, 3.0F)
238 auto ® = getRegistry();
243 m_animationTime += dt;
244 m_titlePulseTime += dt;
246 if (
auto *titleColor = reg.getComponent<
ecs::Color>(m_titleEntity))
248 const float pulse = (std::sin(m_titlePulseTime * 1.2f) + 1.0f) * 0.5f;
253 if (
auto *titleTransform = reg.getComponent<
ecs::Transform>(m_titleEntity))
255 titleTransform->y = 60.0f + std::sin(m_titlePulseTime * 0.8f) * 2.0f;
258 for (
auto &[entity, text] : texts)
260 if (text.content ==
"Player Name" || text.content ==
"Skin" || text.content ==
"Start Game" ||
261 text.content ==
"Go back to menu")
263 auto &color = colors.at(entity);
265 if (i == m_selectedIndex)
267 const float glowIntensity = std::sin(m_animationTime * 2.5f);
269 color.g =
static_cast<unsigned char>(191U + (glowIntensity * 50));
292 m_selectedIndex = (m_selectedIndex == 0) ?
static_cast<int>(m_menuOptions.size()) - 1 : m_selectedIndex - 1;
297 m_selectedIndex = (m_selectedIndex ==
static_cast<int>(m_menuOptions.size()) - 1) ? 0 : m_selectedIndex + 1;
301 const std::string &selectedOption = m_menuOptions[m_selectedIndex];
302 if (onOptionSelected)
304 onOptionSelected(selectedOption, m_playerName, m_skinIndex);
309 if (m_selectedIndex == 3)
311 std::string ¤tField = getCurrentEditField();
312 if (!currentField.empty())
314 currentField.pop_back();
315 updateValueDisplay();
321 if (m_selectedIndex >= 0 && m_selectedIndex <
static_cast<int>(m_menuOptions.size()))
323 const std::string &selectedOption = m_menuOptions[m_selectedIndex];
324 if (m_selectedIndex == 2)
328 m_skinIndex = (m_skinIndex == 0) ? 3 : m_skinIndex - 1;
332 m_skinIndex = (m_skinIndex == 3) ? 0 : m_skinIndex + 1;
334 updateValueDisplay();
340 if (m_selectedIndex == 3)
344 std::string ¤tField = getCurrentEditField();
345 if (currentField.length() < 16)
348 updateValueDisplay();
constexpr auto TEXTURE_PLAYER