Skip to content

Commit d4a138e

Browse files
authored
Add powerup emitter. (#34)
1 parent 6a42734 commit d4a138e

File tree

6 files changed

+92
-8
lines changed

6 files changed

+92
-8
lines changed

.clang-tidy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Checks: 'clang-analyzer-*,
1212
portability-*,
1313
readability-*,
1414
-readability-identifier-length,
15-
-readability-magic-numbers
15+
-readability-magic-numbers,
16+
-readability-redundant-member-init,
1617
-readability-uppercase-literal-suffix'
1718
...

assets/particles/powerup.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"asset_type": "ParticleEmitter",
3+
"texture": "images/foam_bubble.png",
4+
"config": {
5+
"initial": {
6+
"position": {
7+
"lo": [
8+
0.000000,
9+
0.000000
10+
],
11+
"hi": [
12+
0.000000,
13+
0.000000
14+
]
15+
},
16+
"rotation": 0.000000
17+
},
18+
"velocity": {
19+
"linear": {
20+
"angle": {
21+
"lo": -180.000000,
22+
"hi": 180.000000
23+
},
24+
"speed": {
25+
"lo": -360.000000,
26+
"hi": -80.000000
27+
}
28+
},
29+
"angular": {
30+
"lo": -90.000000,
31+
"hi": 90.000000
32+
}
33+
},
34+
"lerp": {
35+
"scale": {
36+
"lo": [
37+
1.000000,
38+
1.000000
39+
],
40+
"hi": [
41+
0.000000,
42+
0.000000
43+
]
44+
}
45+
},
46+
"ttl": {
47+
"lo": 0.500000,
48+
"hi": 1.000000
49+
},
50+
"quad_size": [
51+
50.000000,
52+
50.000000
53+
],
54+
"count": 20,
55+
"respawn": true
56+
}
57+
}

src/spaced/spaced/game/powerups/pu_base.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
#include <spaced/game/powerups/pu_base.hpp>
2+
#include <spaced/services/resources.hpp>
23

34
namespace spaced {
4-
using bave::Circle;
5+
using bave::ParticleEmitter;
6+
using bave::RoundedQuad;
57
using bave::Seconds;
68
using bave::Shader;
79

810
PUBase::PUBase(Services const& services, std::string_view const name) : m_services(&services), m_layout(&services.get<ILayout>()), m_name(name) {
9-
auto circle = Circle{.diameter = 50.0f};
10-
shape.set_shape(circle);
11+
auto quad = RoundedQuad{};
12+
quad.size = glm::vec2{40.0f};
13+
quad.corner_radius = 12.5f;
14+
shape.set_shape(quad);
15+
16+
auto const& resources = services.get<Resources>();
17+
if (auto const pu_emitter = resources.get<ParticleEmitter>("particles/powerup.json")) { emitter = *pu_emitter; }
18+
19+
emitter.config.respawn = true;
1120
}
1221

1322
void PUBase::tick(Seconds const dt) {
1423
shape.transform.position.x -= speed * dt.count();
15-
if (shape.transform.position.x < m_layout->get_play_area().lt.x - 0.5f * shape.get_shape().diameter) { m_destroyed = true; }
24+
if (shape.transform.position.x < m_layout->get_play_area().lt.x - 0.5f * shape.get_shape().size.x) { m_destroyed = true; }
25+
26+
emitter.set_position(shape.transform.position);
27+
if (!m_emitter_ticked) {
28+
m_emitter_ticked = true;
29+
emitter.pre_warm();
30+
}
31+
emitter.tick(dt);
1632
}
1733

18-
void PUBase::draw(Shader& shader) const { shape.draw(shader); }
34+
void PUBase::draw(Shader& shader) const {
35+
shape.draw(shader);
36+
emitter.draw(shader);
37+
}
1938

2039
void PUBase::activate(Player& player) {
2140
do_activate(player);

src/spaced/spaced/game/powerups/pu_base.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include <bave/core/time.hpp>
3+
#include <bave/graphics/particle_system.hpp>
34
#include <bave/graphics/shape.hpp>
45
#include <spaced/game/powerup.hpp>
56
#include <spaced/services/layout.hpp>
@@ -19,14 +20,16 @@ class PUBase : public IPowerup {
1920
[[nodiscard]] auto is_destroyed() const -> bool final { return m_destroyed; }
2021

2122
float speed{300.0f};
22-
bave::CircleShape shape{};
23+
bave::RoundedQuadShape shape{};
24+
bave::ParticleEmitter emitter{};
2325

2426
protected:
2527
virtual void do_activate(Player& player) = 0;
2628

2729
bave::NotNull<Services const*> m_services;
2830
bave::NotNull<ILayout const*> m_layout;
2931
std::string_view m_name{};
32+
bool m_emitter_ticked{};
3033
bool m_destroyed{};
3134
};
3235
} // namespace spaced

src/spaced/spaced/game/powerups/pu_beam.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
#include <spaced/services/styles.hpp>
55

66
namespace spaced {
7-
PUBeam::PUBeam(Services const& services, int rounds) : PUBase(services, "Beam"), m_rounds(rounds) { shape.tint = services.get<Styles>().rgbas["gun_beam"]; }
7+
PUBeam::PUBeam(Services const& services, int rounds) : PUBase(services, "Beam"), m_rounds(rounds) {
8+
emitter.config.lerp.tint.lo = emitter.config.lerp.tint.hi = shape.tint = services.get<Styles>().rgbas["gun_beam"];
9+
emitter.config.lerp.tint.hi.channels.w = 0;
10+
}
811

912
void PUBeam::do_activate(Player& player) {
1013
auto beam = std::make_unique<GunBeam>(*m_services);

src/spaced/spaced/scenes/game.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ auto Game::get_manifest() -> AssetManifest {
3030
{
3131
"particles/exhaust.json",
3232
"particles/explode.json",
33+
"particles/powerup.json",
3334
},
3435
};
3536
}

0 commit comments

Comments
 (0)