Skip to content

Commit 82d8f9a

Browse files
authored
bgf updates, star field, signals. (#50)
* bgf v0.1.5, faster game restart (avoid scene reload). * Show weapon and rounds on HUD. * Use gradient texture for beam. * Keep `GunBeam` busy until both fire and reload delay have elapsed. * Add `StarField`. * Use vertical color gradient for background. * Remove invalid `sync()` call. * Use `Layout` instead of `IDisplay`. * WIP: bgf v0.1.6 * Add `Signal`, `GameSignals`. Use for HUD weapon icon changes. * Use circles for powerups. * Add game music.
1 parent 3cf1c29 commit 82d8f9a

37 files changed

+435
-170
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ include(FetchContent)
1111
FetchContent_Declare(
1212
bgf
1313
GIT_REPOSITORY https://github.com/karnkaul/bgf
14-
GIT_TAG v0.1.4
14+
15+
# GIT_TAG v0.1.5
16+
GIT_TAG adc217f
1517
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/bgf"
1618
)
1719

assets/images/beam_round.png

4.86 KB
Loading

assets/images/star_blue.png

5.42 KB
Loading

assets/images/star_red.png

4.85 KB
Loading

assets/images/star_yellow.png

5.07 KB
Loading

assets/music/game.mp3

1.75 MB
Binary file not shown.

assets/particles/explode.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
}
2828
},
2929
"angular": {
30-
"lo": -90.000000,
31-
"hi": 90.000000
30+
"lo": -360.000000,
31+
"hi": 360.000000
3232
}
3333
},
3434
"lerp": {
@@ -52,8 +52,8 @@
5252
"hi": 0.800000
5353
},
5454
"quad_size": [
55-
100.000000,
56-
100.000000
55+
150.000000,
56+
150.000000
5757
],
5858
"count": 40,
5959
"respawn": true

assets/styles.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"milk": "#e5cdaeff",
77
"ice": "#d6dbe1e1",
88
"orange": "#f75c03ff",
9-
"gun_beam": "#bc96e6ff"
9+
"gun_beam": "#bc96e6ff",
10+
"bg_top": "#10020eff",
11+
"bg_bottom": "#040003ff"
1012
},
1113
"buttons": {
1214
"default": {

src/spaced/spaced/game/arsenal.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#include <spaced/game/arsenal.hpp>
2+
#include <spaced/services/game_signals.hpp>
23
#include <spaced/services/stats.hpp>
34

45
namespace spaced {
56
using bave::Seconds;
67
using bave::Services;
78
using bave::Shader;
89

9-
Arsenal::Arsenal(Services const& services) : m_primary(services), m_stats(&services.get<Stats>()) {}
10+
Arsenal::Arsenal(Services const& services)
11+
: m_stats(&services.get<Stats>()), m_weapon_changed_signal(&services.get<GameSignals>().weapon_changed), m_primary(services) {
12+
m_weapon_changed_signal->dispatch(get_weapon());
13+
}
1014

1115
auto Arsenal::get_weapon() const -> Weapon const& {
1216
if (m_special) { return *m_special; }
@@ -34,13 +38,19 @@ void Arsenal::tick_weapons(Seconds const dt) {
3438
if (m_special) {
3539
m_special->tick(dt);
3640
// if the special weapon has no more rounds and is idle, reset it.
37-
if (m_special->get_rounds_remaining() == 0 && m_special->is_idle()) { m_special.reset(); }
41+
if (m_special->get_rounds_remaining() == 0 && m_special->is_idle()) {
42+
m_special.reset();
43+
m_weapon_changed_signal->dispatch(get_weapon());
44+
}
3845
}
3946
}
4047

4148
void Arsenal::check_switch_weapon() {
4249
// if there is a next weapon on standby and the current weapon is idle, switch to the next weapon.
43-
if (m_next && get_weapon().is_idle()) { m_special = std::move(m_next); }
50+
if (m_next && get_weapon().is_idle()) {
51+
m_special = std::move(m_next);
52+
m_weapon_changed_signal->dispatch(get_weapon());
53+
}
4454
}
4555

4656
void Arsenal::fire_weapon(glm::vec2 const muzzle_position) {

src/spaced/spaced/game/arsenal.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace spaced {
55
struct Stats;
6+
struct SigWeaponChanged;
67

78
// Arsenal models a main/primary weapon, and an possible special weapon.
89
// Weapons only switch when they are idle.
@@ -26,8 +27,10 @@ class Arsenal {
2627
void fire_weapon(glm::vec2 muzzle_position);
2728
void tick_rounds(IWeaponRound::State const& round_state, bave::Seconds dt);
2829

29-
GunKinetic m_primary; // main weapon
3030
bave::NotNull<Stats*> m_stats;
31+
bave::NotNull<SigWeaponChanged*> m_weapon_changed_signal;
32+
33+
GunKinetic m_primary; // main weapon
3134
std::unique_ptr<Weapon> m_special{}; // special weapon
3235
std::unique_ptr<Weapon> m_next{}; // next special weapon (on standby until current weapon is idle)
3336
std::vector<std::unique_ptr<Weapon::Round>> m_rounds{};

0 commit comments

Comments
 (0)