Skip to content
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ add_executable(waveforge
src/items/water.cpp
src/items/oil.cpp
src/scenes/duckdeath.cpp
src/scenes/help.cpp
src/scenes/level_menu.cpp
src/scenes/level_switch.cpp
src/scenes/level.cpp
Expand Down
18 changes: 18 additions & 0 deletions assets/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,24 @@
"input": "ui/level-link/raw",
"description": "Creating level link texture"
},
{
"id": "ui/help/raw",
"type": "image",
"file": "ui/help.png",
"description": "Loading help background image"
},
{
"id": "ui/help",
"type": "create-texture",
"input": "ui/help/raw",
"description": "Creating help background texture"
},
{
"id": "ui-config/help",
"type": "json",
"file": "ui/help.json",
"description": "Loading help UI configuration"
},
{
"id": "ui-config/level-menu",
"type": "json",
Expand Down
Binary file added assets/prototype/howtoplay.aseprite
Binary file not shown.
Binary file modified assets/prototype/waveforge.aseprite
Binary file not shown.
Binary file added assets/ui/help.aseprite
Binary file not shown.
4 changes: 4 additions & 0 deletions assets/ui/help.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"width": 256,
"height": 192
}
Binary file added assets/ui/help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 9 additions & 40 deletions assets/ui/main-menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,53 +19,22 @@
"play": {
"x": 72,
"y": 80,
"size": 2,
"color": [
0,
0,
0,
200
],
"active-color": [
207,
158,
9,
255
]
"size": 2
},
"settings": {
"x": 72,
"y": 104,
"size": 2,
"color": [
0,
0,
0,
200
],
"active-color": [
207,
158,
9,
255
]
"size": 2
},
"exit": {
"help": {
"x": 72,
"y": 128,
"size": 2,
"color": [
0,
0,
0,
200
],
"active-color": [
207,
158,
9,
255
]
"size": 2
},
"exit": {
"x": 72,
"y": 152,
"size": 2
}
}
}
14 changes: 1 addition & 13 deletions assets/ui/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@
"y": 64,
"width": 192,
"spacing": 12,
"size": 1,
"color": [
0,
0,
0,
255
],
"active-color": [
255,
200,
0,
255
]
"size": 1
}
}
1 change: 1 addition & 0 deletions include/wforge/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BGMManager {
void fadeInCurrent(int duration_ticks, float starting_volume);
void step();
void nextMusic();
void setVolume(float volume);

private:
float _cur_volume;
Expand Down
5 changes: 5 additions & 0 deletions include/wforge/colorpalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ constexpr sf::Color ui_text_color(std::uint8_t a) {
return sf::Color(0, 0, 0, a);
}

constexpr sf::Color ui_active_color{250, 200, 46, 255};
constexpr sf::Color ui_text_bright_color(std::uint8_t a) {
return sf::Color(255, 255, 255, a);
}

// All indexed colors must be here, for dynamic generated textures
// Colors in static assets (e.g. PNG files) can be outside this palette
constexpr ColorPaletteEntry _colors[] = {
Expand Down
1 change: 1 addition & 0 deletions include/wforge/save.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct SaveData {
void save() const;
void resetSettings();
void resetAll();
bool is_first_launch() const noexcept;

SaveData(const SaveData &) = delete;
SaveData &operator=(const SaveData &) = delete;
Expand Down
41 changes: 33 additions & 8 deletions include/wforge/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class SceneManager {
int _scale;
};

struct ButtonDescriptor {
int x;
int y;
int size;
};

namespace scene {

struct LevelPlaying {
Expand All @@ -96,6 +102,9 @@ struct LevelPlaying {
const SceneManager &mgr, sf::RenderTarget &target, int scale
) const;

void pause(SceneManager &mgr) noexcept;
void unpause(SceneManager &mgr) noexcept;

private:
void _restartLevel(SceneManager &mgr, bool is_failed = true);

Expand All @@ -105,6 +114,12 @@ struct LevelPlaying {
int _hint_type;
int _hint_opacity;
PixelFont &font;
bool _paused;

// Paused Menu
int _paused_menu_current_button_index;
bool _show_help;
sf::Texture *_help_texture;
};

struct DuckDeath {
Expand Down Expand Up @@ -242,17 +257,10 @@ struct MainMenu {
const PixelFont &font;
sf::Texture *_background_texture;

struct ButtonDescriptor {
int x;
int y;
int size;
sf::Color color;
sf::Color active_color;
};

int _current_button_index;
ButtonDescriptor _play_button;
ButtonDescriptor _settings_button;
ButtonDescriptor _help_button;
ButtonDescriptor _exit_button;
UITextDescriptor _version_text;
};
Expand Down Expand Up @@ -321,6 +329,23 @@ struct Credits {
std::vector<std::pair<std::string, std::string>> _content;
};

struct Help {
Help();

std::array<int, 2> size() const;
void setup(SceneManager &mgr);
void handleEvent(SceneManager &mgr, sf::Event &evt);
void step(SceneManager &mgr);
void render(
const SceneManager &mgr, sf::RenderTarget &target, int scale
) const;

private:
sf::Texture *_background_texture;
int _width;
int _height;
};

} // namespace scene

} // namespace wf
Expand Down
8 changes: 8 additions & 0 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ void BGMManager::step() {
}
}

void BGMManager::setVolume(float volume) { {
_cur_volume = volume;
if (_cur_bgm) {
_cur_bgm->setVolume(_cur_volume);
}
}
}

void BGMManager::nextMusic() {
if (!_collection) {
return;
Expand Down
32 changes: 23 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <iostream>
#include <proxy/proxy.h>

void entry(const std::string &level_id, int scale_config);
void entry(const std::string &level_id, int scale_config, bool is_first_launch);

std::filesystem::path wf::_executable_path;
int main(int argc, char **argv) {
Expand Down Expand Up @@ -64,7 +64,10 @@ int main(int argc, char **argv) {
}

CPPTRACE_TRY {
entry(program.get<std::string>("level"), program.get<int>("--scale"));
entry(
program.get<std::string>("level"), program.get<int>("--scale"),
save.is_first_launch()
);
}
CPPTRACE_CATCH(const std::exception &e) {
std::cerr << "Unhandled exception: " << e.what() << "\n";
Expand All @@ -75,14 +78,25 @@ int main(int argc, char **argv) {
return 0;
}

void entry(const std::string &level_id, int scale_config) {
void entry(
const std::string &level_id, int scale_config, bool is_first_launch
) {
auto initialScene = [&](const std::string &level_id, bool is_first_launch) {
if (level_id == "-") {
if (is_first_launch) {
return pro::make_proxy<wf::SceneFacade, wf::scene::Help>();
} else {
return pro::make_proxy<wf::SceneFacade, wf::scene::MainMenu>();
}
} else {
return pro::make_proxy<wf::SceneFacade, wf::scene::LevelPlaying>(
level_id
);
}
};

wf::SceneManager scene_mgr(
level_id == "-"
? pro::make_proxy<wf::SceneFacade, wf::scene::MainMenu>()
: pro::make_proxy<wf::SceneFacade, wf::scene::LevelPlaying>(
level_id
),
scale_config
initialScene(level_id, is_first_launch), scale_config
);

auto &window = scene_mgr.window;
Expand Down
6 changes: 5 additions & 1 deletion src/save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ SaveData &SaveData::instance() noexcept {
}
}

// Please don't relay on this saving mechanism
// Please don't rely on this saving mechanism
// it only works as an extra safeguard against data loss
// Please save manually whenever change is made
std::atexit([]() {
Expand Down Expand Up @@ -142,6 +142,10 @@ void SaveData::resetAll() {
save();
}

bool SaveData::is_first_launch() const noexcept {
return completed_levels == 0;
}

UserSettings UserSettings::defaultSettings() noexcept {
return UserSettings{
.scale = 0,
Expand Down
53 changes: 53 additions & 0 deletions src/scenes/help.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "wforge/assets.h"
#include "wforge/scene.h"
#include <nlohmann/json.hpp>

namespace wf::scene {

Help::Help() {
const auto &json_data = AssetsManager::instance().getAsset<nlohmann::json>(
"ui-config/help"
);

_width = json_data.at("width");
_height = json_data.at("height");

_background_texture = &AssetsManager::instance().getAsset<sf::Texture>(
"ui/help"
);
}

std::array<int, 2> Help::size() const {
return {_width, _height};
}

void Help::handleEvent(SceneManager &mgr, sf::Event &evt) {
if (auto kb = evt.getIf<sf::Event::KeyPressed>()) {
switch (kb->code) {
case sf::Keyboard::Key::Escape:
case sf::Keyboard::Key::Enter:
case sf::Keyboard::Key::Space:
UISounds::instance().forward.play();
mgr.changeScene(pro::make_proxy<SceneFacade, MainMenu>());
return;

default:
break;
}
}
}

void Help::setup(SceneManager &mgr) {}
void Help::step(SceneManager &mgr) {}

void Help::render(
const SceneManager &mgr, sf::RenderTarget &target, int scale
) const {
sf::Sprite background_sprite(*_background_texture);
background_sprite.setPosition(sf::Vector2f(0, 0));
background_sprite.setScale(sf::Vector2f(scale, scale));

target.draw(background_sprite);
}

} // namespace wf::scene
Loading