Skip to content

Commit 5bdea86

Browse files
authored
Sprites part1 (#47)
* bgf v0.1.1 * Prepare to migrate assets/ code to bgf. * bgf v0.1.2 * Add player_ship sprite. * bgf v0.1.3, fixup world vs UI space in layout. * Add `TiledBg`. * Fixup hud positioning.
1 parent 00dba6a commit 5bdea86

32 files changed

+245
-389
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ imgui.ini
1515
bave*.log
1616
/spaced
1717
/notes.txt
18+
/local_store

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ include(FetchContent)
1111
FetchContent_Declare(
1212
bgf
1313
GIT_REPOSITORY https://github.com/karnkaul/bgf
14-
GIT_TAG v0.1.0
14+
GIT_TAG v0.1.3
1515
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/bgf"
1616
)
1717

assets/images/background.png

2.81 KB
Loading

assets/images/player_ship.png

6.93 KB
Loading

assets/particles/exhaust.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
},
3434
"lerp": {
3535
"tint": {
36-
"lo": "#231d2aff",
37-
"hi": "#231d2aff"
36+
"lo": "#f48018ff",
37+
"hi": "#ffffff00"
3838
},
3939
"scale": {
4040
"lo": [
@@ -48,14 +48,14 @@
4848
}
4949
},
5050
"ttl": {
51-
"lo": 2.000000,
52-
"hi": 3.000000
51+
"lo": 0.300000,
52+
"hi": 1.000000
5353
},
5454
"quad_size": [
55-
80.000000,
56-
80.000000
55+
20.000000,
56+
20.000000
5757
],
58-
"count": 80,
58+
"count": 200,
5959
"respawn": true
6060
}
6161
}

assets/styles.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"sliders": {
5959
"default": {
6060
"progress_bar": "default",
61-
"knob_diameter": 30,
61+
"knob_diameter": 50,
6262
"knob_tint": "#9f2b68ff"
6363
}
6464
},

attribution.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SpaceShooterRedux: https://opengameart.org/content/space-shooter-redux, https://www.kenney.nl

src/spaced/spaced/assets/asset_list.cpp

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/spaced/spaced/assets/asset_list.hpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/spaced/spaced/assets/asset_loader.cpp

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/spaced/spaced/assets/asset_loader.hpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/spaced/spaced/assets/asset_manifest.hpp

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/spaced/spaced/game/controllers/player_controller.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ void PlayerController::stop_firing() {
6868
}
6969

7070
auto PlayerController::is_in_move_area(glm::vec2 const position) const -> bool {
71-
auto const n_pos = position.x / m_display->get_world_space().x;
72-
return n_pos <= -n_move_area;
71+
auto const width = m_display->get_world_space().x;
72+
auto const n_pos = (position.x + 0.5f * width) / width;
73+
return n_pos <= n_move_area;
7374
}
7475

7576
void PlayerController::tick_gamepad(Seconds const dt) {

src/spaced/spaced/game/controllers/player_controller.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class PlayerController : public FollowController {
3333

3434
float max_y{};
3535
float min_y{};
36-
float n_move_area{0.25f}; // from left
36+
float n_move_area{0.3f}; // from left
3737

3838
float gamepad_sensitivity{2000.0f};
3939

src/spaced/spaced/game/enemy.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ using bave::Services;
1313
using bave::Shader;
1414
using bave::Styles;
1515

16-
namespace ui = bave::ui;
17-
1816
Enemy::Enemy(Services const& services, std::string_view const type) : m_layout(&services.get<Layout>()), m_health_bar(services), m_type(type) {
1917
static constexpr auto init_size_v = glm::vec2{100.0f};
2018
auto const play_area = m_layout->play_area;

src/spaced/spaced/game/hud.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
#include <fmt/format.h>
22
#include <bave/services/styles.hpp>
3+
#include <bave/ui/button.hpp>
34
#include <spaced/game/hud.hpp>
45
#include <spaced/services/layout.hpp>
56

67
namespace spaced {
8+
using bave::IDisplay;
9+
using bave::Seconds;
710
using bave::Services;
811
using bave::Styles;
912
using bave::TextHeight;
1013

1114
namespace ui = bave::ui;
1215

13-
Hud::Hud(Services const& services) : ui::View(services), m_styles(&services.get<Styles>()), m_area(services.get<Layout>().hud_area) {
16+
Hud::Hud(Services const& services)
17+
: ui::View(services), m_display(&services.get<IDisplay>()), m_layout(&services.get<Layout>()), m_styles(&services.get<Styles>()) {
1418
create_background();
1519
create_score(services);
1620

1721
block_input_events = false;
22+
render_view = m_display->get_world_view();
1823
}
1924

2025
void Hud::set_score(std::int64_t const score) { m_score->text.set_string(fmt::format("{}", score)); }
@@ -25,8 +30,8 @@ void Hud::create_background() {
2530
auto background = std::make_unique<ui::OutlineQuad>();
2631
m_background = background.get();
2732
background->set_outline_width(0.0f);
28-
background->set_size(m_area.size());
29-
background->set_position(m_area.centre());
33+
background->set_size(m_layout->hud_area.size());
34+
background->set_position(m_layout->hud_area.centre());
3035
background->set_tint(m_styles->rgbas["milk"]);
3136
push(std::move(background));
3237
}
@@ -37,24 +42,24 @@ void Hud::create_score(Services const& services) {
3742
auto make_text = [&] {
3843
auto text = std::make_unique<ui::Text>(services);
3944
text->text.set_height(TextHeight{60});
40-
text->text.transform.position = m_area.centre();
45+
text->text.transform.position = m_layout->hud_area.centre();
4146
text->text.tint = rgbas["grey"];
4247
return text;
4348
};
4449

4550
auto text = make_text();
4651
m_score = text.get();
4752
text->text.set_string("9999999999");
48-
auto const text_bounds_size = text->text.get_bounds().size();
49-
text->text.transform.position.y -= 0.5f * text_bounds_size.y;
53+
m_text_bounds_size = text->text.get_bounds().size();
54+
text->text.transform.position.y -= 0.5f * m_text_bounds_size.y;
5055
set_score(0);
5156

5257
push(std::move(text));
5358

5459
text = make_text();
5560
m_hi_score = text.get();
56-
text->text.transform.position.x = m_area.rb.x - 50.0f;
57-
text->text.transform.position.y -= 0.5f * text_bounds_size.y;
61+
text->text.transform.position.x = m_layout->hud_area.rb.x - 50.0f;
62+
text->text.transform.position.y -= 0.5f * m_text_bounds_size.y;
5863
text->text.set_align(bave::Text::Align::eLeft);
5964
set_hi_score(0);
6065

0 commit comments

Comments
 (0)