28 if (!shieldVisualsOpt)
return;
30 auto& shieldVisuals = shieldVisualsOpt.value().get();
32 for (
auto entity : shieldVisuals.entities()) {
33 if (!shieldVisuals.has(entity))
continue;
35 auto& shield = shieldVisuals[entity];
38 const float pulse = std::sin(shield.animationTime * 3.0f) * 0.5f + 0.5f;
39 shield.alpha = 150.0f + pulse * 105.0f;
49 if (!playerTransformsOpt || !playerBoxesOpt || !playerTypesOpt ||
50 !bulletTransformsOpt || !bulletBoxesOpt || !entityTypesOpt) {
54 auto& playerTransforms = playerTransformsOpt.value().get();
55 auto& playerBoxes = playerBoxesOpt.value().get();
56 auto& playerTypes = playerTypesOpt.value().get();
57 auto& bulletTransforms = bulletTransformsOpt.value().get();
58 auto& bulletBoxes = bulletBoxesOpt.value().get();
59 auto& entityTypes = entityTypesOpt.value().get();
61 std::vector<ecs::Entity> shieldsToRemove;
62 std::vector<ecs::Entity> bulletsToDestroy;
64 for (
auto playerEntity : shieldVisuals.entities()) {
65 if (!shieldVisuals.has(playerEntity))
continue;
66 if (!playerTypes.has(playerEntity))
continue;
69 if (!playerTransforms.has(playerEntity))
continue;
70 if (!playerBoxes.has(playerEntity))
continue;
72 const auto& playerTrans = playerTransforms[playerEntity];
73 const auto& playerBox = playerBoxes[playerEntity];
75 for (
auto bulletEntity : entityTypes.entities()) {
76 if (!entityTypes.has(bulletEntity))
continue;
78 if (!bulletTransforms.has(bulletEntity))
continue;
79 if (!bulletBoxes.has(bulletEntity))
continue;
81 const auto& bulletTrans = bulletTransforms[bulletEntity];
82 const auto& bulletBox = bulletBoxes[bulletEntity];
84 const bool collisionX = playerTrans.position.x < bulletTrans.position.x + bulletBox.
width &&
85 playerTrans.position.x + playerBox.width > bulletTrans.position.x;
87 const bool collisionY = playerTrans.position.y < bulletTrans.position.y + bulletBox.height &&
88 playerTrans.position.y + playerBox.height > bulletTrans.position.y;
90 if (collisionX && collisionY) {
91 shieldsToRemove.push_back(playerEntity);
92 bulletsToDestroy.push_back(bulletEntity);
100 for (
const auto& entity : shieldsToRemove) {
104 for (
const auto& entity : bulletsToDestroy) {