Skip to content

Commit

Permalink
Add new powerup icons
Browse files Browse the repository at this point in the history
  • Loading branch information
aleokdev committed Jul 13, 2024
1 parent 03794c7 commit dab8540
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 12 deletions.
Binary file added assets/assets/images/beam_powerup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/assets/images/extra_life.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions src/spaced/spaced/game/powerup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ using bave::Resources;
using bave::Seconds;
using bave::Services;
using bave::Shader;
using bave::Texture;

Powerup::Powerup(Services const& services, std::string_view const name)
: m_services(&services), m_layout(&services.get<Layout>()), m_audio(&services.get<IAudio>()), m_name(name) {
auto circle = Circle{};
circle.diameter = 40.0f;
shape.set_shape(circle);

sprite.set_size({80., 80.});

auto const& resources = services.get<Resources>();
if (auto const pu_emitter = resources.get<ParticleEmitter>("assets/particles/powerup.json")) { emitter = *pu_emitter; }
Expand All @@ -23,10 +23,10 @@ Powerup::Powerup(Services const& services, std::string_view const name)
}

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

emitter.set_position(shape.transform.position);
emitter.set_position(sprite.transform.position);
if (!m_emitter_ticked) {
m_emitter_ticked = true;
emitter.pre_warm();
Expand All @@ -35,8 +35,8 @@ void Powerup::tick(Seconds const dt) {
}

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

void Powerup::activate(Player& player) {
Expand Down
4 changes: 2 additions & 2 deletions src/spaced/spaced/game/powerup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class Powerup : public bave::IDrawable {
void tick(bave::Seconds dt);
void draw(bave::Shader& shader) const final;

[[nodiscard]] auto get_bounds() const -> bave::Rect<> { return shape.get_bounds(); }
[[nodiscard]] auto get_bounds() const -> bave::Rect<> { return sprite.get_bounds(); }
void activate(Player& player);

[[nodiscard]] auto is_destroyed() const -> bool { return m_destroyed; }

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

protected:
Expand Down
8 changes: 7 additions & 1 deletion src/spaced/spaced/game/powerups/beam.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#include <bave/services/resources.hpp>
#include <bave/services/styles.hpp>
#include <spaced/game/player.hpp>
#include <spaced/game/powerups/beam.hpp>
#include <spaced/game/weapons/gun_beam.hpp>

namespace spaced::powerup {
using bave::Resources;
using bave::Services;
using bave::Styles;
using bave::Texture;

Beam::Beam(Services const& services, int rounds) : Powerup(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.lo = emitter.config.lerp.tint.hi = services.get<Styles>().rgbas["gun_beam"];
emitter.config.lerp.tint.hi.channels.w = 0;

auto const& resources = services.get<Resources>();
sprite.set_texture(resources.get<Texture>("assets/images/beam_powerup.png"));
}

void Beam::do_activate(Player& player) {
Expand Down
8 changes: 7 additions & 1 deletion src/spaced/spaced/game/powerups/one_up.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#include <bave/services/resources.hpp>
#include <bave/services/styles.hpp>
#include <spaced/game/player.hpp>
#include <spaced/game/powerups/one_up.hpp>

namespace spaced::powerup {
using bave::Resources;
using bave::Services;
using bave::Styles;
using bave::Texture;

OneUp::OneUp(Services const& services) : Powerup(services, "OneUp") {
emitter.config.lerp.tint.lo = emitter.config.lerp.tint.hi = shape.tint = services.get<Styles>().rgbas["exhaust"];
emitter.config.lerp.tint.lo = emitter.config.lerp.tint.hi = services.get<Styles>().rgbas["exhaust"];
emitter.config.lerp.tint.hi.channels.w = 0;

auto const& resources = services.get<Resources>();
sprite.set_texture(resources.get<Texture>("assets/images/extra_life.png"));
}

void OneUp::do_activate(Player& player) { player.one_up(); }
Expand Down
2 changes: 1 addition & 1 deletion src/spaced/spaced/scenes/endless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void EndlessScene::on_player_scored(Enemy const& enemy) {

if (!powerup) { return; }

powerup->shape.transform.position = enemy.get_position();
powerup->sprite.transform.position = enemy.get_position();
push_powerup(std::move(powerup));
m_since_powerup = 0s;
}
Expand Down
2 changes: 2 additions & 0 deletions src/spaced/spaced/scenes/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ auto GameScene::get_asset_manifest() -> AssetManifest {
"assets/images/round_kinetic_green.png",
"assets/images/round_kinetic_red.png",
"assets/images/round_beam.png",
"assets/images/beam_powerup.png",
"assets/images/extra_life.png",
},
.audio_clips =
{
Expand Down

0 comments on commit dab8540

Please sign in to comment.