Addded game over to quickwings

This commit is contained in:
_brxxh 2023-11-23 18:59:30 +01:00
parent 500464fa73
commit 7a3afe1281

View file

@ -5,6 +5,7 @@
* *
*/ */
#include <ostream>
#include <paradiso/bitmap.hpp> #include <paradiso/bitmap.hpp>
#include <paradiso/bitmap_io.hpp> #include <paradiso/bitmap_io.hpp>
#include <paradiso/context.hpp> #include <paradiso/context.hpp>
@ -24,6 +25,7 @@
// #include "lib/image_loader.hpp" // #include "lib/image_loader.hpp"
const int frame_rate = 60; const int frame_rate = 60;
bool game_over = false;
struct Background { struct Background {
paradiso::Sprite backgroundLeft; paradiso::Sprite backgroundLeft;
@ -187,10 +189,14 @@ struct QuickWings {
void update() { void update() {
if (game_over == true) {
paused = true;
}
// Stop game // Stop game
if (paused) if (paused)
return; return;
else {
// Apply gravity // Apply gravity
velocity += gravity; velocity += gravity;
@ -208,20 +214,25 @@ struct QuickWings {
if (pos < min_pos) { if (pos < min_pos) {
pos = min_pos; pos = min_pos;
velocity = 0.0f; velocity = 0.0f;
game_over = true;
} }
if (pos > max_pos) { if (pos > max_pos) {
pos = max_pos; pos = max_pos;
velocity = 0.0f; velocity = 0.0f;
game_over = true;
} }
// Update rotation // Update rotation
rotation = velocity * 10.0f; rotation = velocity * 10.0f;
} }
}
// keyboard handler // keyboard handler
void on_keyboard(const paradiso::Window::KeyboardInputStack& input) { void on_keyboard(const paradiso::Window::KeyboardInputStack& input) {
if (input.size()) { if (input.size()) {
paused = false; paused = false;
if (paused == false) {
bool pressed_up = input.top().key == ' ' || input.top().key == 'W'; bool pressed_up = input.top().key == ' ' || input.top().key == 'W';
if (input.top().action == 1 && pressed_up) { if (input.top().action == 1 && pressed_up) {
@ -230,6 +241,10 @@ struct QuickWings {
move_up = false; move_up = false;
} }
} }
else {
return;
}
}
} }
}; };
@ -269,6 +284,25 @@ struct Message {
} }
}; };
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<float>::make(0.0f, 0.4f)},
.scale = {paradiso::Vector2<float>::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 { auto main() -> int {
@ -317,6 +351,7 @@ auto main() -> int {
auto background = Background{}; auto background = Background{};
auto grass = Grass{}; auto grass = Grass{};
auto quickwingsapp = QuickWings{}; auto quickwingsapp = QuickWings{};
auto gameover = GameOverMessage{};
// timer // timer
@ -341,6 +376,11 @@ auto main() -> int {
background.draw(shader); background.draw(shader);
grass.draw(shader); grass.draw(shader);
message.draw(shader); message.draw(shader);
if (game_over == true) {
gameover.draw(shader);
}
quickwingsapp.draw(shader); quickwingsapp.draw(shader);
// wait for frame rate // wait for frame rate