Skip to content

Add powerup emitter. #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Checks: 'clang-analyzer-*,
portability-*,
readability-*,
-readability-identifier-length,
-readability-magic-numbers
-readability-magic-numbers,
-readability-redundant-member-init,
-readability-uppercase-literal-suffix'
...
57 changes: 57 additions & 0 deletions assets/particles/powerup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"asset_type": "ParticleEmitter",
"texture": "images/foam_bubble.png",
"config": {
"initial": {
"position": {
"lo": [
0.000000,
0.000000
],
"hi": [
0.000000,
0.000000
]
},
"rotation": 0.000000
},
"velocity": {
"linear": {
"angle": {
"lo": -180.000000,
"hi": 180.000000
},
"speed": {
"lo": -360.000000,
"hi": -80.000000
}
},
"angular": {
"lo": -90.000000,
"hi": 90.000000
}
},
"lerp": {
"scale": {
"lo": [
1.000000,
1.000000
],
"hi": [
0.000000,
0.000000
]
}
},
"ttl": {
"lo": 0.500000,
"hi": 1.000000
},
"quad_size": [
50.000000,
50.000000
],
"count": 20,
"respawn": true
}
}
29 changes: 24 additions & 5 deletions src/spaced/spaced/game/powerups/pu_base.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
#include <spaced/game/powerups/pu_base.hpp>
#include <spaced/services/resources.hpp>

namespace spaced {
using bave::Circle;
using bave::ParticleEmitter;
using bave::RoundedQuad;
using bave::Seconds;
using bave::Shader;

PUBase::PUBase(Services const& services, std::string_view const name) : m_services(&services), m_layout(&services.get<ILayout>()), m_name(name) {
auto circle = Circle{.diameter = 50.0f};
shape.set_shape(circle);
auto quad = RoundedQuad{};
quad.size = glm::vec2{40.0f};
quad.corner_radius = 12.5f;
shape.set_shape(quad);

auto const& resources = services.get<Resources>();
if (auto const pu_emitter = resources.get<ParticleEmitter>("particles/powerup.json")) { emitter = *pu_emitter; }

emitter.config.respawn = true;
}

void PUBase::tick(Seconds const dt) {
shape.transform.position.x -= speed * dt.count();
if (shape.transform.position.x < m_layout->get_play_area().lt.x - 0.5f * shape.get_shape().diameter) { m_destroyed = true; }
if (shape.transform.position.x < m_layout->get_play_area().lt.x - 0.5f * shape.get_shape().size.x) { m_destroyed = true; }

emitter.set_position(shape.transform.position);
if (!m_emitter_ticked) {
m_emitter_ticked = true;
emitter.pre_warm();
}
emitter.tick(dt);
}

void PUBase::draw(Shader& shader) const { shape.draw(shader); }
void PUBase::draw(Shader& shader) const {
shape.draw(shader);
emitter.draw(shader);
}

void PUBase::activate(Player& player) {
do_activate(player);
Expand Down
5 changes: 4 additions & 1 deletion src/spaced/spaced/game/powerups/pu_base.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <bave/core/time.hpp>
#include <bave/graphics/particle_system.hpp>
#include <bave/graphics/shape.hpp>
#include <spaced/game/powerup.hpp>
#include <spaced/services/layout.hpp>
Expand All @@ -19,14 +20,16 @@ class PUBase : public IPowerup {
[[nodiscard]] auto is_destroyed() const -> bool final { return m_destroyed; }

float speed{300.0f};
bave::CircleShape shape{};
bave::RoundedQuadShape shape{};
bave::ParticleEmitter emitter{};

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

bave::NotNull<Services const*> m_services;
bave::NotNull<ILayout const*> m_layout;
std::string_view m_name{};
bool m_emitter_ticked{};
bool m_destroyed{};
};
} // namespace spaced
5 changes: 4 additions & 1 deletion src/spaced/spaced/game/powerups/pu_beam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include <spaced/services/styles.hpp>

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

void PUBeam::do_activate(Player& player) {
auto beam = std::make_unique<GunBeam>(*m_services);
Expand Down
1 change: 1 addition & 0 deletions src/spaced/spaced/scenes/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ auto Game::get_manifest() -> AssetManifest {
{
"particles/exhaust.json",
"particles/explode.json",
"particles/powerup.json",
},
};
}
Expand Down