diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 9d4c49a..713b59e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,3 +1,3 @@ add_subdirectory(simple) add_subdirectory(pong) -add_subdirectory(quickwings) \ No newline at end of file +add_subdirectory(tappyplane) diff --git a/examples/quickwings/CMakeLists.txt b/examples/quickwings/CMakeLists.txt deleted file mode 100644 index 5ac3667..0000000 --- a/examples/quickwings/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -set(quickwings_srcs quickwings.cpp) -set(quickwings_assets - assets/background-day.png - assets/base.png - assets/pipe-green.png - assets/yellowbird-downflap.png - assets/yellowbird-midflap.png - assets/yellowbird-upflap.png - ) - -set_source_files_properties(${quickwings_assets} PROPERTIES HEADER_FILE_ONLY TRUE) - -add_executable(quickwings ${quickwings_srcs} ${quickwings_assets}) - -target_link_libraries(quickwings paradiso_core) - -# -# copy files to bin/../assets folder -# -add_custom_command(TARGET quickwings POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_CURRENT_SOURCE_DIR}/assets/ - $/assets) diff --git a/examples/quickwings/assets/background-day.png b/examples/quickwings/assets/background-day.png deleted file mode 100644 index f9ed139..0000000 Binary files a/examples/quickwings/assets/background-day.png and /dev/null differ diff --git a/examples/quickwings/assets/base.png b/examples/quickwings/assets/base.png deleted file mode 100644 index 26fa391..0000000 Binary files a/examples/quickwings/assets/base.png and /dev/null differ diff --git a/examples/quickwings/assets/gameover.png b/examples/quickwings/assets/gameover.png deleted file mode 100644 index b1df7f5..0000000 Binary files a/examples/quickwings/assets/gameover.png and /dev/null differ diff --git a/examples/quickwings/assets/message.png b/examples/quickwings/assets/message.png deleted file mode 100644 index 9243ab5..0000000 Binary files a/examples/quickwings/assets/message.png and /dev/null differ diff --git a/examples/quickwings/assets/pipe-green.png b/examples/quickwings/assets/pipe-green.png deleted file mode 100644 index 4664401..0000000 Binary files a/examples/quickwings/assets/pipe-green.png and /dev/null differ diff --git a/examples/quickwings/assets/yellowbird-downflap.png b/examples/quickwings/assets/yellowbird-downflap.png deleted file mode 100644 index e9e1c77..0000000 Binary files a/examples/quickwings/assets/yellowbird-downflap.png and /dev/null differ diff --git a/examples/quickwings/assets/yellowbird-midflap.png b/examples/quickwings/assets/yellowbird-midflap.png deleted file mode 100644 index 2ca3c2d..0000000 Binary files a/examples/quickwings/assets/yellowbird-midflap.png and /dev/null differ diff --git a/examples/quickwings/assets/yellowbird-upflap.png b/examples/quickwings/assets/yellowbird-upflap.png deleted file mode 100644 index 2f693da..0000000 Binary files a/examples/quickwings/assets/yellowbird-upflap.png and /dev/null differ diff --git a/examples/quickwings/quickwings.cpp b/examples/quickwings/quickwings.cpp deleted file mode 100644 index dd51112..0000000 --- a/examples/quickwings/quickwings.cpp +++ /dev/null @@ -1,546 +0,0 @@ -/** - * paradiso - Paradigmen der Softwareentwicklung - * - * (c) Copyright 2023-2025 Hartmut Seichter and Contributors - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -// TODO remove all hard coded 'magic' values! - -// TODO - remove global variables -const int frame_rate = 60; -bool game_over = false; -float risky_pos_x; -float risky_pos_max_x; -float risky_pos_bottom_y; -float risky_pos_top_y; -float risky_pos_bottom_max_y; -float risky_pos_top_max_y; - -struct Background { - paradiso::Sprite backgroundLeft; - paradiso::Sprite backgroundRight; - paradiso::Sprite grassLeft; - paradiso::Sprite grassRight; - - paradiso::Sprite* scrolling[2] = {&backgroundLeft, &backgroundRight}; - - paradiso::Renderer renderer{}; - - // TODO no constructors in rule of zero - Background() { - auto backgroundImage = - paradiso::BitmapIO::get().load("background-day.png"); - backgroundLeft = paradiso::Sprite{ - .bitmap = backgroundImage, - .pivot = {paradiso::Vector2::make(0.0f, 0.16f)}, - .scale = {paradiso::Vector2::make(1.01f, 1.3f)}}; - backgroundRight = paradiso::Sprite{ - .bitmap = backgroundImage, - .pivot = {paradiso::Vector2::make(2.018f, 0.16f)}, - .scale = {paradiso::Vector2::make(1.01f, 1.3f)}}; - - auto grassImage = paradiso::BitmapIO::get().load("base.png"); - grassLeft = paradiso::Sprite{ - .bitmap = grassImage, - .pivot = {paradiso::Vector2::make(0.0f, -1.0f)}, - .scale = {paradiso::Vector2::make(1.0f, 0.33333f)}}; - grassRight = paradiso::Sprite{ - .bitmap = grassImage, - .pivot = {paradiso::Vector2::make(2.0f, -1.0f)}, - .scale = {paradiso::Vector2::make(1.0f, 0.33333f)}}; - } - - void draw(const paradiso::Shader& shader) { - for (auto sprite : scrolling) { - if (game_over == false) { - if (sprite->pivot.x() <= -2.0f) { - sprite->pivot.x() += 4.0f; - } - sprite->pivot.x() -= 0.002f; - } - shader.set_uniform("pivot", sprite->pivot); - shader.set_uniform("scale", sprite->scale); - shader.set_uniform("rotation", sprite->rotation); - renderer.draw(*sprite, shader); - } - } -}; - -struct Pipe { - paradiso::Sprite pipe_top{}; - paradiso::Sprite pipe_bottom{}; - - paradiso::Renderer renderer1{}; - paradiso::Renderer renderer2{}; - - bool paused = false; - - int pipe_spawn_rand_int = rand() % 80 + 15; - float pipe_spawn_rand = float(pipe_spawn_rand_int) / 100; - - bool pos_reset = false; - - // TODO no constructors in rule of zero - - Pipe() { - auto pipe_image = paradiso::BitmapIO::get().load("pipe-green.png"); - - pipe_top = paradiso::Sprite{ - .bitmap = pipe_image, - .pivot = {paradiso::Vector2::make(1.4f, - pipe_spawn_rand + 1.0f)}, - .scale = {paradiso::Vector2::make( - ((500.0f - (500.0f - 52.0f)) / 500.0f) * 2.25f, - ((700.0f - (700.0f - 320.0f)) / 700.0f) * 2.25f)}, - .rotation = 3.1415926f}; - pipe_bottom = paradiso::Sprite{ - .bitmap = pipe_image, - .pivot = {paradiso::Vector2::make(1.4f, - pipe_spawn_rand - 1.5f)}, - .scale = {paradiso::Vector2::make( - ((500.0f - (500.0f - 52.0f)) / 500.0f) * 2.25f, - ((700.0f - (700.0f - 320.0f)) / 700.0f) * 2.25f)}}; - - paused = true; - } - - void update() { - - // TODO improve state handling - - if (game_over == true) { - paused = true; - } - - if (paused == true) { - return; - } else { - pipe_spawn_rand_int = rand() % 80 + 15; - pipe_spawn_rand = float(pipe_spawn_rand_int) / 100; - - pipe_top.pivot.x() -= 0.02f; - pipe_bottom.pivot.x() -= 0.02f; - - risky_pos_x = pipe_top.pivot.x(); - risky_pos_max_x = pipe_top.pivot.x() + - ((500.0f - (500.0f - 52.0f)) / 500.0f) * 2.25f; - - risky_pos_top_y = pipe_top.pivot.y(); - risky_pos_top_max_y = pipe_top.pivot.y() + 10.0f; - - risky_pos_bottom_y = pipe_bottom.pivot.y(); - risky_pos_bottom_max_y = pipe_bottom.pivot.y() - 10.0f; - - if (pipe_top.pivot.x() <= -1.4f || pipe_bottom.pivot.x() <= -1.4f) { - pos_reset = true; - - if (pos_reset == true) { - pipe_top.pivot.y() = pipe_spawn_rand + 1.0f; - pipe_bottom.pivot.y() = pipe_spawn_rand - 1.5; - - pos_reset = false; - } - - pipe_top.pivot.x() = 1.4f; - pipe_bottom.pivot.x() = 1.4f; - } - } - } - - void draw(const paradiso::Shader& shader) { - shader.set_uniform("pivot", pipe_bottom.pivot); - shader.set_uniform("scale", pipe_bottom.scale); - renderer1.draw(pipe_bottom, shader); - - shader.set_uniform("pivot", pipe_top.pivot); - shader.set_uniform("scale", pipe_top.scale); - shader.set_uniform("rotation", pipe_top.rotation); - renderer1.draw(pipe_top, shader); - } -}; - -struct Grass { - paradiso::Sprite grassLeft; - paradiso::Sprite grassRight; - paradiso::Sprite* scrolling[2] = {&grassLeft, &grassRight}; - - paradiso::Renderer renderer1{}; - paradiso::Renderer renderer2{}; - - // TODO no constructors in rule of zero - Grass() { - auto grassImage = paradiso::BitmapIO::get().load("base.png"); - grassLeft = paradiso::Sprite{ - .bitmap = grassImage, - .pivot = {paradiso::Vector2::make(0.0f, -0.9f)}, - .scale = {paradiso::Vector2::make( - ((500.0f - (500.0f - 504.0f)) / 500.0f) * 2.25f, - ((700.0f - (700.0f - 112.0f)) / 700.0f) * 2.25f)}}; - grassRight = paradiso::Sprite{ - .bitmap = grassImage, - .pivot = {paradiso::Vector2::make(1.002f, -0.9f)}, - .scale = {paradiso::Vector2::make( - ((500.0f - (500.0f - 504.0f)) / 500.0f) * 2.25f, - ((700.0f - (700.0f - 112.0f)) / 700.0f) * 2.25f)}}; - } - - void draw(const paradiso::Shader& shader) { - if (game_over == false) { - grassLeft.pivot.x() -= 0.02f; - grassRight.pivot.x() -= 0.02f; - - if (grassRight.pivot.x() <= 0.0f) { - grassLeft.pivot.x() = 1.002f; - } - if (grassRight.pivot.x() <= -1.002f) { - grassRight.pivot.x() = 1.002f; - } - } - - shader.set_uniform("pivot", grassLeft.pivot); - shader.set_uniform("scale", grassLeft.scale); - shader.set_uniform("rotation", grassLeft.rotation); - - shader.set_uniform("pivot", grassRight.pivot); - shader.set_uniform("scale", grassRight.scale); - shader.set_uniform("rotation", grassRight.rotation); - - renderer1.draw(grassLeft, shader); - renderer2.draw(grassRight, shader); - } -}; - -struct QuickWings { - paradiso::Renderer renderer1{}; - paradiso::Renderer renderer2{}; - paradiso::Renderer renderer3{}; - - std::array birds; - unsigned int flap = 0; - unsigned int flapSpeed = 15; // How many ticks per flap - unsigned int flapCounter = 0; // How many ticks since last flap - - float velocity = 0.0f; - const float max_velocity = 0.02f; - - const float gravity = -0.002f; - const float move_up_velocity = 0.02f; - - bool move_up = false; - bool paused = true; - - const float max_pos = 0.95f; - const float min_pos = -0.5f; - - float pos = 0.34f; - - float rotation = 0.0f; - - int collision_counter = 0; - - // TODO no constructors in rule of zero - QuickWings() { - float scaleh = 0.08f; - float scalew = 0.158f; - - birds = { - paradiso::Sprite{ - .bitmap = - paradiso::BitmapIO::get().load("yellowbird-downflap.png"), - .pivot = {paradiso::Vector2::make(0.0f, 0.0f)}, - .scale = {paradiso::Vector2::make(scalew, scaleh)}}, - paradiso::Sprite{ - .bitmap = - paradiso::BitmapIO::get().load("yellowbird-midflap.png"), - .pivot = {paradiso::Vector2::make(0.0f, 0.0f)}, - .scale = {paradiso::Vector2::make(scalew, scaleh)}}, - paradiso::Sprite{ - .bitmap = - paradiso::BitmapIO::get().load("yellowbird-upflap.png"), - .pivot = {paradiso::Vector2::make(0.0f, 0.0f)}, - .scale = {paradiso::Vector2::make(scalew, scaleh)}}}; - } - - void draw(const paradiso::Shader& shader) { - // Update flap state - if (flapCounter < flapSpeed) { - flapCounter++; - } else { - flapCounter = 0; - flap = (flap + 1) % birds.size(); - } - - auto bird = birds[flap]; - bird.pivot.y() = pos; - bird.rotation = rotation; - shader.set_uniform("pivot", bird.pivot); - shader.set_uniform("scale", bird.scale); - shader.set_uniform("rotation", bird.rotation); - - switch (flap) { - case 0: - renderer1.draw(bird, shader); - break; - case 1: - renderer2.draw(bird, shader); - break; - case 2: - renderer3.draw(bird, shader); - break; - } - } - - void update() { - - if (game_over == true) { - paused = true; - } - - // Stop game - if (paused) { - return; - } else { - // Apply gravity - velocity += gravity; - - if (move_up) - velocity += move_up_velocity - gravity; - - // Cap velocity - if (velocity > max_velocity) - velocity = max_velocity; - if (velocity < -max_velocity) - velocity = -max_velocity; - - // Cap position - pos += velocity; - if (pos < min_pos) { - pos = min_pos; - velocity = 0.0f; - game_over = true; - } - if (pos > max_pos) { - pos = max_pos; - velocity = 0.0f; - game_over = true; - } - - // Update rotation - rotation = velocity * 10.0f; - } - - float final_risky_pos_top_y = risky_pos_top_y - 1.06f; - float final_risky_pos_bottom_y = risky_pos_bottom_y + 1.06f; - - if (risky_pos_x - 0.3f <= 0.0f && risky_pos_max_x >= 0.0f) { - if (pos >= final_risky_pos_top_y && pos <= risky_pos_top_max_y) { - game_over = true; - } - if (pos <= final_risky_pos_bottom_y && - pos >= risky_pos_bottom_max_y) { - if (collision_counter == 0) { - collision_counter++; - } else { - collision_counter = 2; - } - - if (collision_counter == 2) { - game_over = true; - } - } - } - } - - // keyboard handler - void on_keyboard(const paradiso::Window::KeyboardInputStack& input) { - if (input.size()) { - paused = false; - - if (paused == false) { - bool pressed_up = - input.top().key == ' ' || input.top().key == 'W'; - - if (input.top().action == 1 && pressed_up) { - move_up = true; - } else if (input.top().action == 0 && pressed_up) { - move_up = false; - } - } else { - return; - } - } - } -}; - -struct Message { - paradiso::Sprite messageSprite; - paradiso::Renderer renderer{}; - bool start = false; - float pos = 100.0f; - - Message() { - auto messageImage = paradiso::BitmapIO::get().load("message.png"); - messageSprite = paradiso::Sprite{ - .bitmap = messageImage, - .pivot = {paradiso::Vector2::make(0.0f, 0.0f)}, - .scale = {paradiso::Vector2::make(0.8f, 0.8f)}}; - }; - - void draw(const paradiso::Shader& shader) { - shader.set_uniform("pivot", messageSprite.pivot); - shader.set_uniform("scale", messageSprite.scale); - renderer.draw(messageSprite, shader); - } - - void update() { - if (start == true) { - messageSprite.pivot.y() = pos; - } - } - - void on_keyboard(const paradiso::Window::KeyboardInputStack& input) { - if (input.size()) { - start = true; - } - } -}; - -struct GameOverMessage { - paradiso::Sprite messageSprite; - paradiso::Renderer renderer{}; - - GameOverMessage() { - auto messageImage = paradiso::BitmapIO::get().load("gameover.png"); - messageSprite = paradiso::Sprite{ - .bitmap = messageImage, - .pivot = {paradiso::Vector2::make(0.0f, 0.4f)}, - .scale = {paradiso::Vector2::make( - ((500.0f - (500.0f - 192.0f)) / 500.0f) * 2.25f, - ((700.0f - (700.0f - 42.0f)) / 700.0f) * 2.25f)}}; - }; - - void draw(const paradiso::Shader& shader) { - shader.set_uniform("pivot", messageSprite.pivot); - shader.set_uniform("scale", messageSprite.scale); - renderer.draw(messageSprite, shader); - } -}; - -auto main() -> int { - std::srand(std::time(nullptr)); - - // Ausgabefenster ... sieht aus als wäre es auf dem Stack - auto window = paradiso::Window(); - - auto size = paradiso::Size{.width = 500, .height = 700}; - - /* - window.set_resizecallback([](auto& w) -> void { - w.set_size(paradiso::Size{.width = 405, .height = 720}); - }); - -*/ - window - .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_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 = size}); - - // nothing beats a classic look - ctx.set_clearcolor(paradiso::RGBA::from_rgb(0x00, 0x00, 0x00)); - - // Asset loader bekommt den Pfad - - paradiso::BitmapIO::get().set_path("assets"); - - // Load - auto background = Background{}; - auto grass = Grass{}; - auto quickwingsapp = QuickWings{}; - auto pipe = Pipe{}; - auto message = Message{}; - auto gameover = GameOverMessage{}; - - // timer - - // das update führt den hier mitgegebnen Ausdruck innerhalb der internen - // Updates des Fensters auf. Es wird hier auch explizit ein bool gefordert - // damit das update auch zu jederzeit unterbrochen werden kann - while (window.update([&](paradiso::Window& w) -> bool { - ctx.set_viewport(paradiso::Rectangle{ - .position = paradiso::Point{.x = 0, .y = 0}, .size = size}); - - ctx.clear(); - auto t1 = std::chrono::high_resolution_clock::now(); - - // Keyboard and state change + update - if (quickwingsapp.paused == false) { - pipe.paused = false; - } - - pipe.update(); - - quickwingsapp.on_keyboard(w.keyboard_input()); - quickwingsapp.update(); - - message.on_keyboard(w.keyboard_input()); - message.update(); - - // Draw - background.draw(shader); - pipe.draw(shader); - grass.draw(shader); - message.draw(shader); - - if (game_over == true) { - gameover.draw(shader); - } - - quickwingsapp.draw(shader); - - // wait for frame rate - auto t2 = std::chrono::high_resolution_clock::now(); - auto duration = - std::chrono::duration_cast(t2 - t1); - auto wait = std::chrono::microseconds(1000000 / frame_rate) - duration; - std::this_thread::sleep_for(wait); - - // Quit - return !(w.keyboard_input().size() && - w.keyboard_input().top().key == 'Q'); - })) { - }; - - return 0; -} diff --git a/examples/tappyplane/CMakeLists.txt b/examples/tappyplane/CMakeLists.txt new file mode 100644 index 0000000..7d4f40a --- /dev/null +++ b/examples/tappyplane/CMakeLists.txt @@ -0,0 +1,18 @@ +set(tappyplane_srcs tappyplane.cpp) +set(tappyplane_assets + assets/PNG/background.png + ) + +set_source_files_properties(${tappyplane_assets} PROPERTIES HEADER_FILE_ONLY TRUE) + +add_executable(tappyplane ${tappyplane_srcs} ${tappyplane_assets}) + +target_link_libraries(tappyplane paradiso_core) + +# +# copy files to bin/../assets folder +# +add_custom_command(TARGET tappyplane POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_SOURCE_DIR}/assets/ + $/assets) diff --git a/examples/quickwings/assets/tappybird/Font/kenvector_future.ttf b/examples/tappyplane/assets/Font/kenvector_future.ttf similarity index 100% rename from examples/quickwings/assets/tappybird/Font/kenvector_future.ttf rename to examples/tappyplane/assets/Font/kenvector_future.ttf diff --git a/examples/quickwings/assets/tappybird/Font/kenvector_future_thin.ttf b/examples/tappyplane/assets/Font/kenvector_future_thin.ttf similarity index 100% rename from examples/quickwings/assets/tappybird/Font/kenvector_future_thin.ttf rename to examples/tappyplane/assets/Font/kenvector_future_thin.ttf diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterA.png b/examples/tappyplane/assets/PNG/Letters/letterA.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterA.png rename to examples/tappyplane/assets/PNG/Letters/letterA.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterB.png b/examples/tappyplane/assets/PNG/Letters/letterB.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterB.png rename to examples/tappyplane/assets/PNG/Letters/letterB.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterC.png b/examples/tappyplane/assets/PNG/Letters/letterC.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterC.png rename to examples/tappyplane/assets/PNG/Letters/letterC.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterD.png b/examples/tappyplane/assets/PNG/Letters/letterD.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterD.png rename to examples/tappyplane/assets/PNG/Letters/letterD.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterE.png b/examples/tappyplane/assets/PNG/Letters/letterE.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterE.png rename to examples/tappyplane/assets/PNG/Letters/letterE.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterF.png b/examples/tappyplane/assets/PNG/Letters/letterF.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterF.png rename to examples/tappyplane/assets/PNG/Letters/letterF.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterG.png b/examples/tappyplane/assets/PNG/Letters/letterG.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterG.png rename to examples/tappyplane/assets/PNG/Letters/letterG.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterH.png b/examples/tappyplane/assets/PNG/Letters/letterH.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterH.png rename to examples/tappyplane/assets/PNG/Letters/letterH.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterI.png b/examples/tappyplane/assets/PNG/Letters/letterI.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterI.png rename to examples/tappyplane/assets/PNG/Letters/letterI.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterJ.png b/examples/tappyplane/assets/PNG/Letters/letterJ.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterJ.png rename to examples/tappyplane/assets/PNG/Letters/letterJ.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterK.png b/examples/tappyplane/assets/PNG/Letters/letterK.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterK.png rename to examples/tappyplane/assets/PNG/Letters/letterK.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterL.png b/examples/tappyplane/assets/PNG/Letters/letterL.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterL.png rename to examples/tappyplane/assets/PNG/Letters/letterL.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterM.png b/examples/tappyplane/assets/PNG/Letters/letterM.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterM.png rename to examples/tappyplane/assets/PNG/Letters/letterM.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterN.png b/examples/tappyplane/assets/PNG/Letters/letterN.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterN.png rename to examples/tappyplane/assets/PNG/Letters/letterN.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterO.png b/examples/tappyplane/assets/PNG/Letters/letterO.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterO.png rename to examples/tappyplane/assets/PNG/Letters/letterO.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterP.png b/examples/tappyplane/assets/PNG/Letters/letterP.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterP.png rename to examples/tappyplane/assets/PNG/Letters/letterP.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterQ.png b/examples/tappyplane/assets/PNG/Letters/letterQ.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterQ.png rename to examples/tappyplane/assets/PNG/Letters/letterQ.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterR.png b/examples/tappyplane/assets/PNG/Letters/letterR.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterR.png rename to examples/tappyplane/assets/PNG/Letters/letterR.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterS.png b/examples/tappyplane/assets/PNG/Letters/letterS.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterS.png rename to examples/tappyplane/assets/PNG/Letters/letterS.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterT.png b/examples/tappyplane/assets/PNG/Letters/letterT.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterT.png rename to examples/tappyplane/assets/PNG/Letters/letterT.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterU.png b/examples/tappyplane/assets/PNG/Letters/letterU.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterU.png rename to examples/tappyplane/assets/PNG/Letters/letterU.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterV.png b/examples/tappyplane/assets/PNG/Letters/letterV.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterV.png rename to examples/tappyplane/assets/PNG/Letters/letterV.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterW.png b/examples/tappyplane/assets/PNG/Letters/letterW.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterW.png rename to examples/tappyplane/assets/PNG/Letters/letterW.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterX.png b/examples/tappyplane/assets/PNG/Letters/letterX.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterX.png rename to examples/tappyplane/assets/PNG/Letters/letterX.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterY.png b/examples/tappyplane/assets/PNG/Letters/letterY.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterY.png rename to examples/tappyplane/assets/PNG/Letters/letterY.png diff --git a/examples/quickwings/assets/tappybird/PNG/Letters/letterZ.png b/examples/tappyplane/assets/PNG/Letters/letterZ.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Letters/letterZ.png rename to examples/tappyplane/assets/PNG/Letters/letterZ.png diff --git a/examples/quickwings/assets/tappybird/PNG/Numbers/number0.png b/examples/tappyplane/assets/PNG/Numbers/number0.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Numbers/number0.png rename to examples/tappyplane/assets/PNG/Numbers/number0.png diff --git a/examples/quickwings/assets/tappybird/PNG/Numbers/number1.png b/examples/tappyplane/assets/PNG/Numbers/number1.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Numbers/number1.png rename to examples/tappyplane/assets/PNG/Numbers/number1.png diff --git a/examples/quickwings/assets/tappybird/PNG/Numbers/number2.png b/examples/tappyplane/assets/PNG/Numbers/number2.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Numbers/number2.png rename to examples/tappyplane/assets/PNG/Numbers/number2.png diff --git a/examples/quickwings/assets/tappybird/PNG/Numbers/number3.png b/examples/tappyplane/assets/PNG/Numbers/number3.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Numbers/number3.png rename to examples/tappyplane/assets/PNG/Numbers/number3.png diff --git a/examples/quickwings/assets/tappybird/PNG/Numbers/number4.png b/examples/tappyplane/assets/PNG/Numbers/number4.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Numbers/number4.png rename to examples/tappyplane/assets/PNG/Numbers/number4.png diff --git a/examples/quickwings/assets/tappybird/PNG/Numbers/number5.png b/examples/tappyplane/assets/PNG/Numbers/number5.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Numbers/number5.png rename to examples/tappyplane/assets/PNG/Numbers/number5.png diff --git a/examples/quickwings/assets/tappybird/PNG/Numbers/number6.png b/examples/tappyplane/assets/PNG/Numbers/number6.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Numbers/number6.png rename to examples/tappyplane/assets/PNG/Numbers/number6.png diff --git a/examples/quickwings/assets/tappybird/PNG/Numbers/number7.png b/examples/tappyplane/assets/PNG/Numbers/number7.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Numbers/number7.png rename to examples/tappyplane/assets/PNG/Numbers/number7.png diff --git a/examples/quickwings/assets/tappybird/PNG/Numbers/number8.png b/examples/tappyplane/assets/PNG/Numbers/number8.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Numbers/number8.png rename to examples/tappyplane/assets/PNG/Numbers/number8.png diff --git a/examples/quickwings/assets/tappybird/PNG/Numbers/number9.png b/examples/tappyplane/assets/PNG/Numbers/number9.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Numbers/number9.png rename to examples/tappyplane/assets/PNG/Numbers/number9.png diff --git a/examples/quickwings/assets/tappybird/PNG/Planes/planeBlue1.png b/examples/tappyplane/assets/PNG/Planes/planeBlue1.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Planes/planeBlue1.png rename to examples/tappyplane/assets/PNG/Planes/planeBlue1.png diff --git a/examples/quickwings/assets/tappybird/PNG/Planes/planeBlue2.png b/examples/tappyplane/assets/PNG/Planes/planeBlue2.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Planes/planeBlue2.png rename to examples/tappyplane/assets/PNG/Planes/planeBlue2.png diff --git a/examples/quickwings/assets/tappybird/PNG/Planes/planeBlue3.png b/examples/tappyplane/assets/PNG/Planes/planeBlue3.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Planes/planeBlue3.png rename to examples/tappyplane/assets/PNG/Planes/planeBlue3.png diff --git a/examples/quickwings/assets/tappybird/PNG/Planes/planeGreen1.png b/examples/tappyplane/assets/PNG/Planes/planeGreen1.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Planes/planeGreen1.png rename to examples/tappyplane/assets/PNG/Planes/planeGreen1.png diff --git a/examples/quickwings/assets/tappybird/PNG/Planes/planeGreen2.png b/examples/tappyplane/assets/PNG/Planes/planeGreen2.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Planes/planeGreen2.png rename to examples/tappyplane/assets/PNG/Planes/planeGreen2.png diff --git a/examples/quickwings/assets/tappybird/PNG/Planes/planeGreen3.png b/examples/tappyplane/assets/PNG/Planes/planeGreen3.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Planes/planeGreen3.png rename to examples/tappyplane/assets/PNG/Planes/planeGreen3.png diff --git a/examples/quickwings/assets/tappybird/PNG/Planes/planeRed1.png b/examples/tappyplane/assets/PNG/Planes/planeRed1.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Planes/planeRed1.png rename to examples/tappyplane/assets/PNG/Planes/planeRed1.png diff --git a/examples/quickwings/assets/tappybird/PNG/Planes/planeRed2.png b/examples/tappyplane/assets/PNG/Planes/planeRed2.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Planes/planeRed2.png rename to examples/tappyplane/assets/PNG/Planes/planeRed2.png diff --git a/examples/quickwings/assets/tappybird/PNG/Planes/planeRed3.png b/examples/tappyplane/assets/PNG/Planes/planeRed3.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Planes/planeRed3.png rename to examples/tappyplane/assets/PNG/Planes/planeRed3.png diff --git a/examples/quickwings/assets/tappybird/PNG/Planes/planeYellow1.png b/examples/tappyplane/assets/PNG/Planes/planeYellow1.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Planes/planeYellow1.png rename to examples/tappyplane/assets/PNG/Planes/planeYellow1.png diff --git a/examples/quickwings/assets/tappybird/PNG/Planes/planeYellow2.png b/examples/tappyplane/assets/PNG/Planes/planeYellow2.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Planes/planeYellow2.png rename to examples/tappyplane/assets/PNG/Planes/planeYellow2.png diff --git a/examples/quickwings/assets/tappybird/PNG/Planes/planeYellow3.png b/examples/tappyplane/assets/PNG/Planes/planeYellow3.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/Planes/planeYellow3.png rename to examples/tappyplane/assets/PNG/Planes/planeYellow3.png diff --git a/examples/quickwings/assets/tappybird/PNG/UI/UIbg.png b/examples/tappyplane/assets/PNG/UI/UIbg.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/UI/UIbg.png rename to examples/tappyplane/assets/PNG/UI/UIbg.png diff --git a/examples/quickwings/assets/tappybird/PNG/UI/buttonLarge.png b/examples/tappyplane/assets/PNG/UI/buttonLarge.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/UI/buttonLarge.png rename to examples/tappyplane/assets/PNG/UI/buttonLarge.png diff --git a/examples/quickwings/assets/tappybird/PNG/UI/buttonSmall.png b/examples/tappyplane/assets/PNG/UI/buttonSmall.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/UI/buttonSmall.png rename to examples/tappyplane/assets/PNG/UI/buttonSmall.png diff --git a/examples/quickwings/assets/tappybird/PNG/UI/medalBronze.png b/examples/tappyplane/assets/PNG/UI/medalBronze.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/UI/medalBronze.png rename to examples/tappyplane/assets/PNG/UI/medalBronze.png diff --git a/examples/quickwings/assets/tappybird/PNG/UI/medalGold.png b/examples/tappyplane/assets/PNG/UI/medalGold.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/UI/medalGold.png rename to examples/tappyplane/assets/PNG/UI/medalGold.png diff --git a/examples/quickwings/assets/tappybird/PNG/UI/medalSilver.png b/examples/tappyplane/assets/PNG/UI/medalSilver.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/UI/medalSilver.png rename to examples/tappyplane/assets/PNG/UI/medalSilver.png diff --git a/examples/quickwings/assets/tappybird/PNG/UI/tap.png b/examples/tappyplane/assets/PNG/UI/tap.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/UI/tap.png rename to examples/tappyplane/assets/PNG/UI/tap.png diff --git a/examples/quickwings/assets/tappybird/PNG/UI/tapLeft.png b/examples/tappyplane/assets/PNG/UI/tapLeft.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/UI/tapLeft.png rename to examples/tappyplane/assets/PNG/UI/tapLeft.png diff --git a/examples/quickwings/assets/tappybird/PNG/UI/tapRight.png b/examples/tappyplane/assets/PNG/UI/tapRight.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/UI/tapRight.png rename to examples/tappyplane/assets/PNG/UI/tapRight.png diff --git a/examples/quickwings/assets/tappybird/PNG/UI/tapTick.png b/examples/tappyplane/assets/PNG/UI/tapTick.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/UI/tapTick.png rename to examples/tappyplane/assets/PNG/UI/tapTick.png diff --git a/examples/quickwings/assets/tappybird/PNG/UI/textGameOver.png b/examples/tappyplane/assets/PNG/UI/textGameOver.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/UI/textGameOver.png rename to examples/tappyplane/assets/PNG/UI/textGameOver.png diff --git a/examples/quickwings/assets/tappybird/PNG/UI/textGetReady.png b/examples/tappyplane/assets/PNG/UI/textGetReady.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/UI/textGetReady.png rename to examples/tappyplane/assets/PNG/UI/textGetReady.png diff --git a/examples/quickwings/assets/tappybird/PNG/background.png b/examples/tappyplane/assets/PNG/background.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/background.png rename to examples/tappyplane/assets/PNG/background.png diff --git a/examples/quickwings/assets/tappybird/PNG/groundDirt.png b/examples/tappyplane/assets/PNG/groundDirt.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/groundDirt.png rename to examples/tappyplane/assets/PNG/groundDirt.png diff --git a/examples/quickwings/assets/tappybird/PNG/groundGrass.png b/examples/tappyplane/assets/PNG/groundGrass.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/groundGrass.png rename to examples/tappyplane/assets/PNG/groundGrass.png diff --git a/examples/quickwings/assets/tappybird/PNG/groundIce.png b/examples/tappyplane/assets/PNG/groundIce.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/groundIce.png rename to examples/tappyplane/assets/PNG/groundIce.png diff --git a/examples/quickwings/assets/tappybird/PNG/groundRock.png b/examples/tappyplane/assets/PNG/groundRock.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/groundRock.png rename to examples/tappyplane/assets/PNG/groundRock.png diff --git a/examples/quickwings/assets/tappybird/PNG/groundSnow.png b/examples/tappyplane/assets/PNG/groundSnow.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/groundSnow.png rename to examples/tappyplane/assets/PNG/groundSnow.png diff --git a/examples/quickwings/assets/tappybird/PNG/puffLarge.png b/examples/tappyplane/assets/PNG/puffLarge.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/puffLarge.png rename to examples/tappyplane/assets/PNG/puffLarge.png diff --git a/examples/quickwings/assets/tappybird/PNG/puffSmall.png b/examples/tappyplane/assets/PNG/puffSmall.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/puffSmall.png rename to examples/tappyplane/assets/PNG/puffSmall.png diff --git a/examples/quickwings/assets/tappybird/PNG/rock.png b/examples/tappyplane/assets/PNG/rock.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/rock.png rename to examples/tappyplane/assets/PNG/rock.png diff --git a/examples/quickwings/assets/tappybird/PNG/rockDown.png b/examples/tappyplane/assets/PNG/rockDown.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/rockDown.png rename to examples/tappyplane/assets/PNG/rockDown.png diff --git a/examples/quickwings/assets/tappybird/PNG/rockGrass.png b/examples/tappyplane/assets/PNG/rockGrass.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/rockGrass.png rename to examples/tappyplane/assets/PNG/rockGrass.png diff --git a/examples/quickwings/assets/tappybird/PNG/rockGrassDown.png b/examples/tappyplane/assets/PNG/rockGrassDown.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/rockGrassDown.png rename to examples/tappyplane/assets/PNG/rockGrassDown.png diff --git a/examples/quickwings/assets/tappybird/PNG/rockIce.png b/examples/tappyplane/assets/PNG/rockIce.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/rockIce.png rename to examples/tappyplane/assets/PNG/rockIce.png diff --git a/examples/quickwings/assets/tappybird/PNG/rockIceDown.png b/examples/tappyplane/assets/PNG/rockIceDown.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/rockIceDown.png rename to examples/tappyplane/assets/PNG/rockIceDown.png diff --git a/examples/quickwings/assets/tappybird/PNG/rockSnow.png b/examples/tappyplane/assets/PNG/rockSnow.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/rockSnow.png rename to examples/tappyplane/assets/PNG/rockSnow.png diff --git a/examples/quickwings/assets/tappybird/PNG/rockSnowDown.png b/examples/tappyplane/assets/PNG/rockSnowDown.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/rockSnowDown.png rename to examples/tappyplane/assets/PNG/rockSnowDown.png diff --git a/examples/quickwings/assets/tappybird/PNG/starBronze.png b/examples/tappyplane/assets/PNG/starBronze.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/starBronze.png rename to examples/tappyplane/assets/PNG/starBronze.png diff --git a/examples/quickwings/assets/tappybird/PNG/starGold.png b/examples/tappyplane/assets/PNG/starGold.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/starGold.png rename to examples/tappyplane/assets/PNG/starGold.png diff --git a/examples/quickwings/assets/tappybird/PNG/starSilver.png b/examples/tappyplane/assets/PNG/starSilver.png similarity index 100% rename from examples/quickwings/assets/tappybird/PNG/starSilver.png rename to examples/tappyplane/assets/PNG/starSilver.png diff --git a/examples/quickwings/assets/tappybird/Spritesheet/planes.png b/examples/tappyplane/assets/Spritesheet/planes.png similarity index 100% rename from examples/quickwings/assets/tappybird/Spritesheet/planes.png rename to examples/tappyplane/assets/Spritesheet/planes.png diff --git a/examples/quickwings/assets/tappybird/Spritesheet/planes.xml b/examples/tappyplane/assets/Spritesheet/planes.xml similarity index 100% rename from examples/quickwings/assets/tappybird/Spritesheet/planes.xml rename to examples/tappyplane/assets/Spritesheet/planes.xml diff --git a/examples/quickwings/assets/tappybird/Spritesheet/sheet.png b/examples/tappyplane/assets/Spritesheet/sheet.png similarity index 100% rename from examples/quickwings/assets/tappybird/Spritesheet/sheet.png rename to examples/tappyplane/assets/Spritesheet/sheet.png diff --git a/examples/quickwings/assets/tappybird/Spritesheet/sheet.xml b/examples/tappyplane/assets/Spritesheet/sheet.xml similarity index 100% rename from examples/quickwings/assets/tappybird/Spritesheet/sheet.xml rename to examples/tappyplane/assets/Spritesheet/sheet.xml diff --git a/examples/quickwings/assets/tappybird/Vector/vector.svg b/examples/tappyplane/assets/Vector/vector.svg similarity index 100% rename from examples/quickwings/assets/tappybird/Vector/vector.svg rename to examples/tappyplane/assets/Vector/vector.svg diff --git a/examples/quickwings/assets/tappybird/Vector/vector.swf b/examples/tappyplane/assets/Vector/vector.swf similarity index 100% rename from examples/quickwings/assets/tappybird/Vector/vector.swf rename to examples/tappyplane/assets/Vector/vector.swf diff --git a/examples/quickwings/assets/tappybird/license.txt b/examples/tappyplane/assets/license.txt similarity index 100% rename from examples/quickwings/assets/tappybird/license.txt rename to examples/tappyplane/assets/license.txt diff --git a/examples/quickwings/assets/tappybird/preview.png b/examples/tappyplane/assets/preview.png similarity index 100% rename from examples/quickwings/assets/tappybird/preview.png rename to examples/tappyplane/assets/preview.png diff --git a/examples/quickwings/assets/tappybird/sample.png b/examples/tappyplane/assets/sample.png similarity index 99% rename from examples/quickwings/assets/tappybird/sample.png rename to examples/tappyplane/assets/sample.png index efccaf4..5532803 100644 Binary files a/examples/quickwings/assets/tappybird/sample.png and b/examples/tappyplane/assets/sample.png differ diff --git a/examples/tappyplane/tappyplane.cpp b/examples/tappyplane/tappyplane.cpp new file mode 100644 index 0000000..cda1265 --- /dev/null +++ b/examples/tappyplane/tappyplane.cpp @@ -0,0 +1,456 @@ +/** + * paradiso - Paradigmen der Softwareentwicklung + * + * (c) Copyright 2023-2025 Hartmut Seichter and Contributors + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +static const unsigned int FRAME_RATE = 60; +static const unsigned int WINDOW_WIDTH = 800; +static const unsigned int WINDOW_HEIGHT = 480; +static const unsigned int WINDOW_SCALE = 2; + +// x,y+h --- x+w,y+h +// | | +// | | +// | | +// x,y ----- x+w,y +struct AABB { + paradiso::Vector2 position{}; + paradiso::Vector2 size{}; + + bool is_colliding_with(const AABB& other) { + return position.x() < other.position.x() + other.size.x() && + position.x() + size.x() > other.position.x() && + position.y() < other.position.y() + other.size.y() && + position.y() + size.y() > other.position.y(); + } +}; + +struct Background { + static constexpr float SCROLLING_SPEED = 0.003f; + + std::array sprites; + paradiso::Renderer renderer{}; + + paradiso::Bitmap image = + paradiso::BitmapIO::get().load("PNG/background.png"); + + void init() { + sprites = {paradiso::Sprite{ + .bitmap = image, + .pivot = {paradiso::Vector2::make(0.0f, 0.0f)}, + .scale = {paradiso::Vector2::make(1.0f, 1.0f)}}, + paradiso::Sprite{ + .bitmap = image, + .pivot = {paradiso::Vector2::make(2.0f, 0.0f)}, + .scale = {paradiso::Vector2::make(1.0f, 1.0f)}}}; + } + + void update() { + for (auto& sprite : sprites) { + sprite.pivot.x() -= SCROLLING_SPEED; + if (sprite.pivot.x() <= -2.0f) { + sprite.pivot.x() += 4.0f; + } + } + } + + void draw(const paradiso::Shader& shader) { + for (const auto& sprite : sprites) { + shader.set_uniform("pivot", sprite.pivot); + shader.set_uniform("scale", sprite.scale); + shader.set_uniform("rotation", sprite.rotation); + renderer.draw(sprite, shader); + } + } +}; + +struct Ground { + static constexpr float SCROLLING_SPEED = 0.009f; + + std::array sprites; + paradiso::Renderer renderer{}; + + // Maybe put this into 'init()' because we might use the other textures + // like snow, ice, ... and then we can parameterize this. + paradiso::Bitmap image = + paradiso::BitmapIO::get().load("PNG/groundGrass.png"); + + AABB aabb{}; + + void init() { + // The image's height is 71 px. + float scale_y = 71.0f / (float)WINDOW_HEIGHT; + + float pivot_y = -1.0f + scale_y; + + sprites = { + paradiso::Sprite{ + .bitmap = image, + .pivot = {paradiso::Vector2::make(0.0f, pivot_y)}, + .scale = {paradiso::Vector2::make(1.0f, scale_y)}}, + paradiso::Sprite{ + .bitmap = image, + .pivot = {paradiso::Vector2::make(2.0f, pivot_y)}, + .scale = {paradiso::Vector2::make(1.0f, scale_y)}}}; + + // We'll make the height half the height of the texture. + // (If you want 1:1 size, you need to double the scale of the sprite.) + aabb = AABB{ + .position = {paradiso::Vector2::make(-1.0f, -1.0f)}, + .size = {paradiso::Vector2::make(2.0f, scale_y)} + }; + } + + void update() { + for (auto& sprite : sprites) { + sprite.pivot.x() -= SCROLLING_SPEED; + if (sprite.pivot.x() <= -2.0f) { + sprite.pivot.x() += 4.0f; + } + } + } + + void draw(const paradiso::Shader& shader) { + for (const auto& sprite : sprites) { + shader.set_uniform("pivot", sprite.pivot); + shader.set_uniform("scale", sprite.scale); + shader.set_uniform("rotation", sprite.rotation); + renderer.draw(sprite, shader); + } + } +}; + +struct Rocks { + static constexpr float SCROLLING_SPEED = 0.006f; + static constexpr float GAP_SIZE = 1.6f; + + paradiso::Sprite top_sprite; + paradiso::Sprite bottom_sprite; + + paradiso::Renderer top_renderer{}; + paradiso::Renderer bottom_renderer{}; + + // Maybe put this into 'init()' because we might use the other textures + // like snow, ice, ... and then we can parameterize this. + paradiso::Bitmap top_image = + paradiso::BitmapIO::get().load("PNG/rockGrassDown.png"); + paradiso::Bitmap bottom_image = + paradiso::BitmapIO::get().load("PNG/rockGrass.png"); + + AABB top_aabb; + AABB bottom_aabb; + + void init(float x) { + // The image's size is 108x239 px. + float scale_x = 108.0f / (float)WINDOW_WIDTH; + float scale_y = 239.0f / (float)WINDOW_HEIGHT; + auto scale = paradiso::Vector2{ + paradiso::Vector2::make(scale_x, scale_y)}; + + float top_position_y = + 1.0f - scale_y + ((float)(std::rand() % 60) / 100) + 0.04f; + float bottom_position_y = top_position_y - GAP_SIZE; + + top_sprite = paradiso::Sprite{ + .bitmap = top_image, + .pivot = {paradiso::Vector2::make(x, top_position_y)}, + .scale = scale}; + + bottom_sprite = paradiso::Sprite{ + .bitmap = bottom_image, + .pivot = {paradiso::Vector2::make(x, bottom_position_y)}, + .scale = scale}; + + // We'll make the width half the width of the texture. + // (If you want 1:1 size, you need to double the scale of the sprite.) + auto size = paradiso::Vector2{ + paradiso::Vector2::make(scale_x, scale_y * 2)}; + + auto top_position = + paradiso::Vector2{paradiso::Vector2::make( + top_sprite.pivot.x() - size.x() / 2, + top_sprite.pivot.y() - size.y() / 2)}; + + auto bottom_position = + paradiso::Vector2{paradiso::Vector2::make( + bottom_sprite.pivot.x() - size.x() / 2, + bottom_sprite.pivot.y() - size.y() / 2)}; + + top_aabb = AABB{top_position, size}; + bottom_aabb = AABB{bottom_position, size}; + } + + void update() { + top_sprite.pivot.x() -= SCROLLING_SPEED; + bottom_sprite.pivot.x() -= SCROLLING_SPEED; + + // +----------+ + // | | + // | # #-------- the x it is. + // | \ | + // +----\-----+ + // \ + // *------- the x we need. + + // @Efficiency: We could just scroll it with the sprite. + top_aabb.position.x() = top_sprite.pivot.x() - top_aabb.size.x() / 2; + bottom_aabb.position.x() = + bottom_sprite.pivot.x() - bottom_aabb.size.x() / 2; + + if (top_sprite.pivot.x() <= -1.2f) { + // Reset. + init(1.2f); + return; + } + } + + void draw(const paradiso::Shader& shader) { + shader.set_uniform("pivot", top_sprite.pivot); + shader.set_uniform("scale", top_sprite.scale); + shader.set_uniform("rotation", top_sprite.rotation); + top_renderer.draw(top_sprite, shader); + + shader.set_uniform("pivot", bottom_sprite.pivot); + shader.set_uniform("scale", bottom_sprite.scale); + shader.set_uniform("rotation", bottom_sprite.rotation); + bottom_renderer.draw(bottom_sprite, shader); + } +}; + +struct Plane { + static const unsigned int SPRITE_COUNT = 3; + static constexpr float GRAVITY = -0.001f; + static constexpr float JUMP_VELOCITY = 0.03f; + static constexpr float MAX_VELOCITY = 0.03f; + + std::array sprites; + std::array renderers; + + unsigned int anim_interval = 10; + unsigned int anim_counter = 0; + + // The direction where 'current_sprite' should go because the animation + // shouldn't loop. + int anim_direction = 1; + + unsigned int current_sprite = 0; + + float position_y = 0.5f; + float rotation = 0.0f; + + float velocity_y = 0.0f; + + AABB aabb; + + void init() { + // The image's size is 88x73 px. + float scale_x = 88.0f / (float)WINDOW_WIDTH; + float scale_y = 73.0f / (float)WINDOW_HEIGHT; + + auto pivot = paradiso::Vector2{ + paradiso::Vector2::make(0.0f, position_y)}; + auto scale = paradiso::Vector2{ + paradiso::Vector2::make(scale_x, scale_y)}; + + sprites = { + paradiso::Sprite{.bitmap = paradiso::BitmapIO::get().load( + "PNG/Planes/planeRed1.png"), + .pivot = pivot, + .scale = scale}, + paradiso::Sprite{.bitmap = paradiso::BitmapIO::get().load( + "PNG/Planes/planeRed2.png"), + .pivot = pivot, + .scale = scale}, + paradiso::Sprite{.bitmap = paradiso::BitmapIO::get().load( + "PNG/Planes/planeRed3.png"), + .pivot = pivot, + .scale = scale}, + }; + + // We'll make the size half the size of the texture. + // (If you want 1:1 size, you need to double the scale of the sprite.) + auto size = paradiso::Vector2{ + paradiso::Vector2::make(scale_x, scale_y)}; + + // Center it. + auto position = paradiso::Vector2{paradiso::Vector2::make( + pivot.x() - size.x() / 2, pivot.y() - size.y() / 2)}; + + aabb = AABB{position, size}; + } + + void update(const paradiso::Window::KeyboardInputStack& input) { + if (anim_counter < anim_interval) { + anim_counter++; + } else { + anim_counter = 0; + + current_sprite += anim_direction; + if (current_sprite == SPRITE_COUNT - 1) { + anim_direction = -1; + } else if (current_sprite == 0) { + anim_direction = 1; + } + } + + if (input.size() && input.top().key == ' ' && input.top().action == 1) { + velocity_y += JUMP_VELOCITY; + } else { + velocity_y += GRAVITY; + } + + velocity_y = std::clamp(velocity_y, -MAX_VELOCITY, MAX_VELOCITY); + position_y += velocity_y; + + // +---------+ + // | | + // | #------- the y it is. + // | | + // +----#----+ + // \ + // *----- the y we need. + + // @Efficiency: We could just add the velocity. + aabb.position.y() = position_y - aabb.size.y() / 2; + + rotation = velocity_y * 500.0f; + } + + void draw(const paradiso::Shader& shader) { + auto sprite = sprites[current_sprite]; + sprite.rotation = rotation * (std::numbers::pi / 180.0f); + sprite.pivot.y() = position_y; + + shader.set_uniform("pivot", sprite.pivot); + shader.set_uniform("scale", sprite.scale); + shader.set_uniform("rotation", sprite.rotation); + renderers[current_sprite].draw(sprite, shader); + } +}; + +auto main() -> int { + std::srand(std::time(nullptr)); + + auto canvas_size = paradiso::Size{.width = WINDOW_WIDTH * WINDOW_SCALE, + .height = WINDOW_HEIGHT * WINDOW_SCALE}; + + // Unser Fenster, auf das wir rendern. + auto window = paradiso::Window(); + window + .set_size(canvas_size) // ... Größe + .set_position(paradiso::Point{.x = 200, .y = 200}) // ... Position + .set_title("ParadiSO.TappyPlane") // ... Titel + .set_visible(true); // ... und jetzt anzeigen! + + // Der Fenster Context. + auto context = paradiso::Context{}; + + // Ein Shader (Schattierungsprogramm). + auto shader = paradiso::Shader{}; + + // Wir nutzen einen vorgefertigten Shader, der speziell für Sprites ist. + 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öße eingestellt + // werden. + context.set_viewport(paradiso::Rectangle{ + .position = paradiso::Point{.x = 0, .y = 0}, .size = canvas_size}); + + // Conflower blue + context.set_clearcolor(paradiso::RGBA::from_rgb(0x64, 0x95, 0xED)); + + // Der Asset Loader bekommt den Pfad. + paradiso::BitmapIO::get().set_path("assets"); + + // Wir initialisieren unsere Sachen. + auto background = Background{}; + background.init(); + + auto ground = Ground{}; + ground.init(); + + auto rocks1 = Rocks{}; + rocks1.init(1.2f); + + auto rocks2 = Rocks{}; + rocks2.init(2.4f); + + auto plane = Plane{}; + plane.init(); + + auto top_aabb = + AABB{.position = {paradiso::Vector2::make(-1.0f, 1.0f)}, + .size = {paradiso::Vector2::make(2.0f, 0.5f)}}; + + while (window.update([&](paradiso::Window& window) -> bool { + background.update(); + ground.update(); + + rocks1.update(); + rocks2.update(); + + plane.update(window.keyboard_input()); + + if (plane.aabb.is_colliding_with(rocks1.top_aabb) || + plane.aabb.is_colliding_with(rocks1.bottom_aabb) || + plane.aabb.is_colliding_with(rocks2.top_aabb) || + plane.aabb.is_colliding_with(rocks2.bottom_aabb) || + plane.aabb.is_colliding_with(top_aabb) || + plane.aabb.is_colliding_with(ground.aabb)) { + + std::cout << "COLLIDING" << std::endl; + } + + auto t1 = std::chrono::high_resolution_clock::now(); + + context.set_viewport(paradiso::Rectangle{ + .position = paradiso::Point{.x = 0, .y = 0}, .size = canvas_size}); + context.clear(); + + background.draw(shader); + + plane.draw(shader); + + rocks1.draw(shader); + rocks2.draw(shader); + + ground.draw(shader); + + // Einen kurzen Moment warten, um auf 60 FPS zu kommen. + auto t2 = std::chrono::high_resolution_clock::now(); + auto duration = + std::chrono::duration_cast(t2 - t1); + auto wait = std::chrono::microseconds(1000000 / FRAME_RATE) - duration; + std::this_thread::sleep_for(wait); + + if (window.keyboard_input().size() && + window.keyboard_input().top().key == 'Q') { + // Update-Loop beenden. + return false; + } + + return true; + })) { + }; + + return 0; +}