Cleanup
This commit is contained in:
parent
b6805f7164
commit
47bfead825
1 changed files with 28 additions and 5 deletions
|
@ -22,6 +22,11 @@
|
|||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
|
||||
// @ToDo: Introduce a struct that automates a sprite's scale. Right now we are
|
||||
// doing this all by hand by doing IMAGE_SIZE / WINDOW_SIZE.
|
||||
|
||||
// @ToDo: Introduce Delta-Time for each update function?
|
||||
|
||||
namespace TappyPlane {
|
||||
|
||||
using SpriteName = std::tuple<std::string_view, std::string_view>;
|
||||
|
@ -66,10 +71,12 @@ struct Background {
|
|||
sprites = {paradiso::Sprite{
|
||||
.bitmap = sprite_map["background"],
|
||||
.pivot = {paradiso::Vector2<float>::make(0.0f, 0.0f)},
|
||||
// The background sprite is as big as the window.
|
||||
.scale = {paradiso::Vector2<float>::make(1.0f, 1.0f)}},
|
||||
paradiso::Sprite{
|
||||
.bitmap = sprite_map["background"],
|
||||
.pivot = {paradiso::Vector2<float>::make(2.0f, 0.0f)},
|
||||
// The background sprite is as big as the window.
|
||||
.scale = {paradiso::Vector2<float>::make(1.0f, 1.0f)}}};
|
||||
}
|
||||
|
||||
|
@ -308,6 +315,7 @@ struct Plane {
|
|||
static constexpr paradiso::Vector2<float> INIT_PIVOT{
|
||||
paradiso::Vector2<float>::make(0.0f, INIT_POSITION_Y)};
|
||||
|
||||
// Every 10th frame.
|
||||
static const unsigned int ANIM_INTERVAL = 10;
|
||||
|
||||
// The image's size is 88x73 px.
|
||||
|
@ -636,7 +644,7 @@ struct App {
|
|||
};
|
||||
|
||||
for (const auto& [name, filename] : assets) {
|
||||
std::print("{} : {} -> ", name, filename);
|
||||
std::print("{:<20} : {:<30} -> ", name, filename);
|
||||
|
||||
auto bitmap = paradiso::BitmapIO::get().load(filename);
|
||||
app.sprites[name] = bitmap;
|
||||
|
@ -708,7 +716,8 @@ struct App {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (game_state == GameState::Start) {
|
||||
switch (game_state) {
|
||||
case GameState::Start:
|
||||
if (window.keyboard_input().size() &&
|
||||
window.keyboard_input().top().key == ACTION_KEY &&
|
||||
window.keyboard_input().top().action == 1) {
|
||||
|
@ -724,7 +733,8 @@ struct App {
|
|||
plane.update_animation(); // Only the animation.
|
||||
ground.update();
|
||||
start_ui.update();
|
||||
} else if (game_state == GameState::Playing) {
|
||||
break;
|
||||
case GameState::Playing:
|
||||
background.update();
|
||||
ground.update();
|
||||
rocks1.update();
|
||||
|
@ -740,7 +750,8 @@ struct App {
|
|||
plane.aabb.is_colliding_with(ground.aabb)) {
|
||||
game_state = GameState::GameOver;
|
||||
}
|
||||
} else if (game_state == GameState::GameOver) {
|
||||
break;
|
||||
case GameState::GameOver:
|
||||
if (window.keyboard_input().size() &&
|
||||
window.keyboard_input().top().key == ACTION_KEY) {
|
||||
|
||||
|
@ -752,6 +763,7 @@ struct App {
|
|||
plane.reset();
|
||||
game_state = GameState::Start;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
context.set_viewport(
|
||||
|
@ -773,7 +785,18 @@ struct App {
|
|||
game_over_ui.draw(shader);
|
||||
}
|
||||
|
||||
// Einen kurzen Moment warten, um auf 60 FPS zu kommen.
|
||||
//
|
||||
// Einen kurzen Moment warten, um FRAME_RATE (siehe oben) zu
|
||||
// erreichen.
|
||||
//
|
||||
// Wichtig: Das beeinflusst auch die allgemeine
|
||||
// Geschwindigkeit des Spiels, da das Aktualisieren des Game-States
|
||||
// nicht unabhängig von der Frame-Rate läuft.
|
||||
//
|
||||
// Man könnte Delta-Time einführen oder das Aktualisieren des
|
||||
// Game-States auf eine bestimmte Geschwindigkeit (Tick-Speed)
|
||||
// bringen und zwischen den Frames interpolieren.
|
||||
//
|
||||
auto t2 = std::chrono::high_resolution_clock::now();
|
||||
auto duration =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue