Skip to content

bgf updates, star field, signals. #50

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 12 commits into from
Jun 24, 2024
Prev Previous commit
Next Next commit
Use vertical color gradient for background.
  • Loading branch information
karnkaul committed Jun 22, 2024
commit b6b0a2fd9dd08a81a781fe92fc7ec4424dd89f03
4 changes: 3 additions & 1 deletion assets/styles.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"milk": "#e5cdaeff",
"ice": "#d6dbe1e1",
"orange": "#f75c03ff",
"gun_beam": "#bc96e6ff"
"gun_beam": "#bc96e6ff",
"bg_top": "#10020eff",
"bg_bottom": "#040003ff"
},
"buttons": {
"default": {
Expand Down
17 changes: 12 additions & 5 deletions src/spaced/spaced/game/world.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <bave/imgui/im_text.hpp>
#include <bave/services/resources.hpp>
#include <bave/services/styles.hpp>
#include <spaced/game/enemies/creep_factory.hpp>
#include <spaced/game/world.hpp>
#include <spaced/services/layout.hpp>
#include <spaced/services/stats.hpp>

#include <bave/core/random.hpp>
Expand All @@ -17,18 +19,24 @@ using bave::Resources;
using bave::Seconds;
using bave::Services;
using bave::Shader;
using bave::Styles;
using bave::Texture;

World::World(bave::NotNull<Services const*> services, bave::NotNull<IScorer*> scorer)
: m_services(services), m_resources(&services->get<Resources>()), m_audio(&services->get<IAudio>()), m_stats(&services->get<Stats>()), m_scorer(scorer),
m_background(*services), m_star_field(*services) {
m_star_field(*services) {
m_enemy_factories["CreepFactory"] = std::make_unique<CreepFactory>(services);

auto const& resources = services->get<Resources>();

m_background.set_texture(resources.get<Texture>("images/background.png"));
m_background.set_tile_size(glm::vec2{300.0f});
m_background.x_speed = 50.0f;
auto const play_area = services->get<Layout>().play_area;
auto const& rgbas = services->get<Styles>().rgbas;
auto quad = bave::Quad{.size = play_area.size()};
auto geometry = quad.to_geometry();
geometry.vertex_array.vertices[0].rgba = geometry.vertex_array.vertices[1].rgba = rgbas["bg_bottom"].to_vec4();
geometry.vertex_array.vertices[2].rgba = geometry.vertex_array.vertices[3].rgba = rgbas["bg_top"].to_vec4();
m_background.set_geometry(std::move(geometry));
m_background.transform.position = play_area.centre();

auto const config = StarField::Config{.spawn_rate = 0.2s};
m_star_field.add_field(resources.get<Texture>("images/star_blue.png"), config);
Expand All @@ -38,7 +46,6 @@ World::World(bave::NotNull<Services const*> services, bave::NotNull<IScorer*> sc

void World::tick(Seconds const dt, bool const in_play) {
if (in_play) {
m_background.tick(dt);
m_star_field.tick(dt);
for (auto& [_, factory] : m_enemy_factories) {
if (auto enemy = factory->tick(dt)) { m_active_enemies.push_back(std::move(enemy)); }
Expand Down
3 changes: 1 addition & 2 deletions src/spaced/spaced/game/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <spaced/game/scorer.hpp>
#include <spaced/game/star_field.hpp>
#include <spaced/game/target_provider.hpp>
#include <spaced/game/tiled_bg.hpp>

namespace bave {
struct Resources;
Expand Down Expand Up @@ -42,7 +41,7 @@ class World : public ITargetProvider {
bave::NotNull<Stats*> m_stats;
bave::NotNull<IScorer*> m_scorer;

TiledBg m_background;
bave::CustomShape m_background{};
StarField m_star_field;

std::unordered_map<std::string, std::unique_ptr<EnemyFactory>> m_enemy_factories{};
Expand Down