9 const std::shared_ptr<eng::IAudio> &audio,
const int skinIndex,
bool &showDebug)
10 : AScene(assignedId), m_renderer(renderer), m_audio(audio), m_skinIndex(skinIndex), m_showDebug(showDebug)
12 auto ®istry = AScene::getRegistry();
14 registry.onComponentAdded(
15 [
this, &renderer, &audio, ®istry](
const ecs::Entity e,
const std::type_info &type)
17 const auto *audioComp = registry.getComponent<
ecs::Audio>(e);
18 const auto *colorComp = registry.getComponent<
ecs::Color>(e);
19 const auto *fontComp = registry.getComponent<
ecs::Font>(e);
20 const auto *rectComp = registry.getComponent<
ecs::Rect>(e);
21 const auto *scaleComp = registry.getComponent<
ecs::Scale>(e);
22 const auto *textComp = registry.getComponent<
ecs::Text>(e);
23 const auto *textureComp = registry.getComponent<
ecs::Texture>(e);
25 const auto *hitBox = registry.getComponent<
ecs::Hitbox>(e);
27 if (hitBox && transform)
29 renderer->createCircleShape({.name =
"hitbox_" + std::to_string(e),
30 .radius = hitBox->radius,
31 .color = {.r = 255, .g = 0, .b = 0, .a = 100},
32 .
x = transform->x + hitBox->offsetX,
33 .
y = transform->y + hitBox->offsetY,
34 .outline_thickness = 1.0f,
35 .outline_color = {.r = 255, .g = 0, .b = 0, .a = 200}});
39 if (textComp && transform && fontComp)
44 renderer->createFont(fontComp->
id, fontComp->path);
48 {.font_name = fontComp->
id,
49 .color = {.r = colorComp->r, .g = colorComp->g, .b = colorComp->b, .a = colorComp->a},
50 .content = textComp->content,
51 .size = textComp->font_size,
54 .name = textComp->
id});
59 const float scale_x = scaleComp ? scaleComp->x : 1.F;
60 const float scale_y = scaleComp ? scaleComp->y : 1.F;
65 renderer->createTexture(textureComp->
id, textureComp->path);
69 if (transform && textureComp)
73 renderer->createSprite(textureComp->
id + std::to_string(e), textureComp->
id, transform->x,
74 transform->y, scale_x, scale_y,
static_cast<int>(rectComp->pos_x),
75 static_cast<int>(rectComp->pos_y), rectComp->size_x, rectComp->size_y);
79 renderer->createSprite(textureComp->
id + std::to_string(e), textureComp->
id, transform->x,
88 audio->createAudio(audioComp->path, audioComp->volume, audioComp->loop,
89 audioComp->id + std::to_string(e));
94 registry.createEntity().with<
ecs::Score>(
"score", 0).build();
102 const auto beginSoundEntity = registry.createEntity()
134 if ((playerTransform ==
nullptr) || (playerVelocity ==
nullptr))
139 constexpr float diagonal_speed =
142 playerVelocity->
x = 0.0f;
143 playerVelocity->
y = 0.0f;
150 playerVelocity->
x = diagonal_speed;
151 playerVelocity->
y = -diagonal_speed;
155 playerVelocity->
x = -diagonal_speed;
156 playerVelocity->
y = -diagonal_speed;
158 else if (down && right)
160 playerVelocity->
x = diagonal_speed;
161 playerVelocity->
y = diagonal_speed;
163 else if (down && left)
165 playerVelocity->
x = -diagonal_speed;
166 playerVelocity->
y = diagonal_speed;
180 playerTransform->x += playerVelocity->
x * dt;
181 playerTransform->y += playerVelocity->
y * dt;
182 playerTransform->x = std::max(playerTransform->x, 0.F);
183 playerTransform->y = std::max(playerTransform->y, 0.F);
185 auto [width, height] = m_renderer->getWindowSize();
191 playerTransform->x = std::min(playerTransform->x, maxX);
192 playerTransform->y = std::min(playerTransform->y, maxY);
constexpr auto TEXTURE_STAGE1_FLOOR
constexpr auto TEXTURE_SHOOT
constexpr auto TEXTURE_STAGE1_CEILING
constexpr auto TEXTURE_PLAYER
constexpr auto TEXTURE_SHOOT_CHARGED