Addded game over to quickwings
This commit is contained in:
parent
500464fa73
commit
7a3afe1281
1 changed files with 66 additions and 26 deletions
|
@ -5,6 +5,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <ostream>
|
||||
#include <paradiso/bitmap.hpp>
|
||||
#include <paradiso/bitmap_io.hpp>
|
||||
#include <paradiso/context.hpp>
|
||||
|
@ -24,6 +25,7 @@
|
|||
// #include "lib/image_loader.hpp"
|
||||
|
||||
const int frame_rate = 60;
|
||||
bool game_over = false;
|
||||
|
||||
struct Background {
|
||||
paradiso::Sprite backgroundLeft;
|
||||
|
@ -187,47 +189,60 @@ struct QuickWings {
|
|||
|
||||
void update() {
|
||||
|
||||
if (game_over == true) {
|
||||
paused = true;
|
||||
}
|
||||
|
||||
// Stop game
|
||||
if (paused)
|
||||
return;
|
||||
else {
|
||||
// Apply gravity
|
||||
velocity += gravity;
|
||||
|
||||
// Apply gravity
|
||||
velocity += gravity;
|
||||
if (move_up)
|
||||
velocity += move_up_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 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;
|
||||
}
|
||||
|
||||
// Cap position
|
||||
pos += velocity;
|
||||
if (pos < min_pos) {
|
||||
pos = min_pos;
|
||||
velocity = 0.0f;
|
||||
// Update rotation
|
||||
rotation = velocity * 10.0f;
|
||||
}
|
||||
if (pos > max_pos) {
|
||||
pos = max_pos;
|
||||
velocity = 0.0f;
|
||||
}
|
||||
|
||||
// Update rotation
|
||||
rotation = velocity * 10.0f;
|
||||
}
|
||||
|
||||
// keyboard handler
|
||||
void on_keyboard(const paradiso::Window::KeyboardInputStack& input) {
|
||||
if (input.size()) {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -317,6 +351,7 @@ auto main() -> int {
|
|||
auto background = Background{};
|
||||
auto grass = Grass{};
|
||||
auto quickwingsapp = QuickWings{};
|
||||
auto gameover = GameOverMessage{};
|
||||
|
||||
// timer
|
||||
|
||||
|
@ -341,6 +376,11 @@ auto main() -> int {
|
|||
background.draw(shader);
|
||||
grass.draw(shader);
|
||||
message.draw(shader);
|
||||
|
||||
if (game_over == true) {
|
||||
gameover.draw(shader);
|
||||
}
|
||||
|
||||
quickwingsapp.draw(shader);
|
||||
|
||||
// wait for frame rate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue