WIP to get new structure working
This commit is contained in:
parent
42a0d56173
commit
6a49628174
4 changed files with 173 additions and 51 deletions
|
@ -5,6 +5,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <filesystem>
|
||||
#include <paradiso/bitmap.hpp>
|
||||
#include <paradiso/bitmap_io.hpp>
|
||||
#include <paradiso/context.hpp>
|
||||
|
@ -16,8 +17,104 @@
|
|||
#include <paradiso/vector.hpp>
|
||||
#include <paradiso/window.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <flat_map>
|
||||
#include <print>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace QuickWings {
|
||||
|
||||
using SpriteName = std::tuple<std::string_view, std::string_view>;
|
||||
using SpriteMap = std::unordered_map<std::string_view, paradiso::Bitmap>;
|
||||
|
||||
struct App {
|
||||
SpriteMap sprites;
|
||||
|
||||
static auto create() -> App {
|
||||
|
||||
paradiso::BitmapIO::get().set_asset_path(
|
||||
paradiso::get_executable_path().parent_path() / "assets");
|
||||
|
||||
auto assets = std::array{
|
||||
SpriteName{"background.bg", "background-day.png"},
|
||||
SpriteName{"background.fg", "base.png"},
|
||||
};
|
||||
|
||||
SpriteMap load_map{};
|
||||
|
||||
for (const auto& [name, filename] : assets) {
|
||||
std::print("{} : {}", name, filename);
|
||||
|
||||
if (auto bm = paradiso::BitmapIO::get().load(filename);
|
||||
bm.has_value()) {
|
||||
load_map[name] = bm.value();
|
||||
std::print(" ok!\n");
|
||||
} else {
|
||||
std::print(" error!\n");
|
||||
}
|
||||
}
|
||||
return {.sprites{load_map}};
|
||||
}
|
||||
|
||||
void run() {
|
||||
auto window = paradiso::Window();
|
||||
|
||||
paradiso::Size size {.width = 640, .height = 480};
|
||||
|
||||
window
|
||||
.set_size(size) // ... Grösse
|
||||
.set_position(
|
||||
paradiso::Point{.x = 1920 / 2 - 500 / 2,
|
||||
.y = 1080 / 2 - 700 / 2}) // ... Position
|
||||
.set_title("PardiSO.Quickwings") // ... Titel
|
||||
.set_visible(true); // ... und jetzt anzeigen!
|
||||
|
||||
// der Fenster Kontext
|
||||
auto ctx = paradiso::Context{};
|
||||
|
||||
// ein Shader (Schattierungsprogramm)
|
||||
auto shader = paradiso::Shader{};
|
||||
|
||||
// wir nutzen einen vorgefertigten shader
|
||||
shader.load_preset(paradiso::Shader::Preset::Sprite);
|
||||
|
||||
// ein viewport stellt die Sicht der Kamera dar, d.h. bei quadratischen
|
||||
// Pixeln sollte hier auch eine dementsprechende Grösse eingestellt
|
||||
// werden
|
||||
ctx.set_viewport(
|
||||
paradiso::Rectangle{.position = paradiso::Point{.x = 0, .y = 0},
|
||||
.size = window.size()});
|
||||
|
||||
// nothing beats a classic look
|
||||
ctx.set_clearcolor(paradiso::RGBA::from_rgb(0x00, 0x00, 0x00));
|
||||
|
||||
while (
|
||||
window.update([&](paradiso::Window& w) -> bool {
|
||||
ctx.set_viewport(paradiso::Rectangle{
|
||||
.position = paradiso::Point{.x = 0, .y = 0},
|
||||
.size = size,
|
||||
});
|
||||
|
||||
// Quit
|
||||
return !(w.keyboard_input().size() &&
|
||||
w.keyboard_input().top().key == 'Q');
|
||||
}){};
|
||||
|
||||
}
|
||||
|
||||
} // namespace QuickWings
|
||||
|
||||
auto main() -> int {
|
||||
auto app = QuickWings::App::create();
|
||||
app.run();
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
// TODO remove all hard coded 'magic' values!
|
||||
|
||||
|
@ -31,7 +128,12 @@ float risky_pos_top_y;
|
|||
float risky_pos_bottom_max_y;
|
||||
float risky_pos_top_max_y;
|
||||
|
||||
|
||||
|
||||
struct Background {
|
||||
|
||||
SpriteMap sprites;
|
||||
|
||||
paradiso::Sprite backgroundLeft;
|
||||
paradiso::Sprite backgroundRight;
|
||||
paradiso::Sprite grassLeft;
|
||||
|
@ -44,7 +146,9 @@ struct Background {
|
|||
// TODO no constructors in rule of zero
|
||||
Background() {
|
||||
auto backgroundImage =
|
||||
paradiso::BitmapIO::get().load("background-day.png");
|
||||
paradiso::BitmapIO::get().load("background-day.png").has_value()
|
||||
? paradiso::BitmapIO::get().load("background-day.png").value()
|
||||
: paradiso::Bitmap();
|
||||
backgroundLeft = paradiso::Sprite{
|
||||
.bitmap = backgroundImage,
|
||||
.pivot = {paradiso::Vector2<float>::make(0.0f, 0.16f)},
|
||||
|
@ -459,7 +563,7 @@ auto main() -> int {
|
|||
.set_size(size) // ... Grösse
|
||||
.set_position(paradiso::Point{.x = 1920 / 2 - 500 / 2,
|
||||
.y = 1080 / 2 - 700 / 2}) // ... Position
|
||||
.set_title("PardiSO.FlappyBird") // ... Titel
|
||||
.set_title("PardiSO.Quickwings") // ... Titel
|
||||
.set_visible(true); // ... und jetzt anzeigen!
|
||||
|
||||
// der Fenster Kontext
|
||||
|
@ -482,7 +586,8 @@ auto main() -> int {
|
|||
|
||||
// Asset loader bekommt den Pfad
|
||||
|
||||
paradiso::BitmapIO::get().set_path("assets");
|
||||
paradiso::BitmapIO::get().set_asset_path(
|
||||
paradiso::get_executable_path().parent_path() / "assets");
|
||||
|
||||
// Load
|
||||
auto background = Background{};
|
||||
|
@ -544,3 +649,4 @@ auto main() -> int {
|
|||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue