forked from Hartmut/paradiso
Make the game go faster after some time
This commit is contained in:
parent
2d7277efec
commit
b412c992ee
1 changed files with 38 additions and 13 deletions
|
@ -22,11 +22,15 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
static const unsigned int FRAME_RATE = 60;
|
static const unsigned int FRAME_RATE = 60;
|
||||||
|
|
||||||
static const unsigned int WINDOW_WIDTH = 800;
|
static const unsigned int WINDOW_WIDTH = 800;
|
||||||
static const unsigned int WINDOW_HEIGHT = 480;
|
static const unsigned int WINDOW_HEIGHT = 480;
|
||||||
static const unsigned int WINDOW_SCALE = 2;
|
static const unsigned int WINDOW_SCALE = 2;
|
||||||
|
|
||||||
static const char ACTION_KEY = ' ';
|
static const char ACTION_KEY = ' ';
|
||||||
|
|
||||||
|
static constexpr float SCROLLING_SPEED_INC_FACTOR = 1.0002f;
|
||||||
|
|
||||||
// x,y+h --- x+w,y+h
|
// x,y+h --- x+w,y+h
|
||||||
// | |
|
// | |
|
||||||
// | |
|
// | |
|
||||||
|
@ -45,7 +49,9 @@ struct AABB {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Background {
|
struct Background {
|
||||||
static constexpr float SCROLLING_SPEED = 0.003f;
|
static constexpr float INIT_SCROLLING_SPEED = 0.003f;
|
||||||
|
|
||||||
|
float scrolling_speed = INIT_SCROLLING_SPEED;
|
||||||
|
|
||||||
std::array<paradiso::Sprite, 2> sprites;
|
std::array<paradiso::Sprite, 2> sprites;
|
||||||
paradiso::Renderer renderer{};
|
paradiso::Renderer renderer{};
|
||||||
|
@ -54,6 +60,9 @@ struct Background {
|
||||||
paradiso::BitmapIO::get().load("PNG/background.png");
|
paradiso::BitmapIO::get().load("PNG/background.png");
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
// For resetting.
|
||||||
|
scrolling_speed = INIT_SCROLLING_SPEED;
|
||||||
|
|
||||||
sprites = {paradiso::Sprite{
|
sprites = {paradiso::Sprite{
|
||||||
.bitmap = image,
|
.bitmap = image,
|
||||||
.pivot = {paradiso::Vector2<float>::make(0.0f, 0.0f)},
|
.pivot = {paradiso::Vector2<float>::make(0.0f, 0.0f)},
|
||||||
|
@ -66,7 +75,7 @@ struct Background {
|
||||||
|
|
||||||
void update() {
|
void update() {
|
||||||
for (auto& sprite : sprites) {
|
for (auto& sprite : sprites) {
|
||||||
sprite.pivot.x() -= SCROLLING_SPEED;
|
sprite.pivot.x() -= scrolling_speed;
|
||||||
if (sprite.pivot.x() <= -2.0f) {
|
if (sprite.pivot.x() <= -2.0f) {
|
||||||
sprite.pivot.x() += 4.0f;
|
sprite.pivot.x() += 4.0f;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +93,9 @@ struct Background {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Ground {
|
struct Ground {
|
||||||
static constexpr float SCROLLING_SPEED = 0.009f;
|
static constexpr float INIT_SCROLLING_SPEED = 0.009f;
|
||||||
|
|
||||||
|
float scrolling_speed = INIT_SCROLLING_SPEED;
|
||||||
|
|
||||||
std::array<paradiso::Sprite, 2> sprites;
|
std::array<paradiso::Sprite, 2> sprites;
|
||||||
paradiso::Renderer renderer{};
|
paradiso::Renderer renderer{};
|
||||||
|
@ -97,6 +108,9 @@ struct Ground {
|
||||||
AABB aabb{};
|
AABB aabb{};
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
// For resetting.
|
||||||
|
scrolling_speed = INIT_SCROLLING_SPEED;
|
||||||
|
|
||||||
// The image's height is 71 px.
|
// The image's height is 71 px.
|
||||||
float scale_y = 71.0f / WINDOW_HEIGHT;
|
float scale_y = 71.0f / WINDOW_HEIGHT;
|
||||||
|
|
||||||
|
@ -120,7 +134,7 @@ struct Ground {
|
||||||
|
|
||||||
void update() {
|
void update() {
|
||||||
for (auto& sprite : sprites) {
|
for (auto& sprite : sprites) {
|
||||||
sprite.pivot.x() -= SCROLLING_SPEED;
|
sprite.pivot.x() -= scrolling_speed;
|
||||||
if (sprite.pivot.x() <= -2.0f) {
|
if (sprite.pivot.x() <= -2.0f) {
|
||||||
sprite.pivot.x() += 4.0f;
|
sprite.pivot.x() += 4.0f;
|
||||||
}
|
}
|
||||||
|
@ -138,9 +152,11 @@ struct Ground {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Rocks {
|
struct Rocks {
|
||||||
static constexpr float SCROLLING_SPEED = 0.006f;
|
static constexpr float INIT_SCROLLING_SPEED = 0.006f;
|
||||||
static constexpr float GAP_SIZE = 1.6f;
|
static constexpr float GAP_SIZE = 1.6f;
|
||||||
|
|
||||||
|
float scrolling_speed = INIT_SCROLLING_SPEED;
|
||||||
|
|
||||||
paradiso::Sprite top_sprite;
|
paradiso::Sprite top_sprite;
|
||||||
paradiso::Sprite bottom_sprite;
|
paradiso::Sprite bottom_sprite;
|
||||||
|
|
||||||
|
@ -157,7 +173,11 @@ struct Rocks {
|
||||||
AABB top_aabb;
|
AABB top_aabb;
|
||||||
AABB bottom_aabb;
|
AABB bottom_aabb;
|
||||||
|
|
||||||
void init(float x) {
|
void init(float x, bool reset_scrolling_speed = false) {
|
||||||
|
if (reset_scrolling_speed) {
|
||||||
|
scrolling_speed = INIT_SCROLLING_SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
// The image's size is 108x239 px.
|
// The image's size is 108x239 px.
|
||||||
float scale_x = 108.0f / WINDOW_WIDTH;
|
float scale_x = 108.0f / WINDOW_WIDTH;
|
||||||
float scale_y = 239.0f / WINDOW_HEIGHT;
|
float scale_y = 239.0f / WINDOW_HEIGHT;
|
||||||
|
@ -198,8 +218,8 @@ struct Rocks {
|
||||||
}
|
}
|
||||||
|
|
||||||
void update() {
|
void update() {
|
||||||
top_sprite.pivot.x() -= SCROLLING_SPEED;
|
top_sprite.pivot.x() -= scrolling_speed;
|
||||||
bottom_sprite.pivot.x() -= SCROLLING_SPEED;
|
bottom_sprite.pivot.x() -= scrolling_speed;
|
||||||
|
|
||||||
// +----------+
|
// +----------+
|
||||||
// | |
|
// | |
|
||||||
|
@ -290,7 +310,7 @@ struct Plane {
|
||||||
.scale = scale},
|
.scale = scale},
|
||||||
};
|
};
|
||||||
|
|
||||||
// For reseting.
|
// For resetting.
|
||||||
position_y = INIT_POSITION_Y;
|
position_y = INIT_POSITION_Y;
|
||||||
velocity_y = INIT_VELOCITY_Y;
|
velocity_y = INIT_VELOCITY_Y;
|
||||||
rotation = INIT_ROTATION;
|
rotation = INIT_ROTATION;
|
||||||
|
@ -528,8 +548,8 @@ auto main() -> int {
|
||||||
|
|
||||||
background.init();
|
background.init();
|
||||||
ground.init();
|
ground.init();
|
||||||
rocks1.init(1.2f);
|
rocks1.init(1.2f, true); // We don't need to set this to true,
|
||||||
rocks2.init(2.4f);
|
rocks2.init(2.4f, true); // but why not?
|
||||||
plane.init();
|
plane.init();
|
||||||
start_text.init();
|
start_text.init();
|
||||||
game_over_text.init();
|
game_over_text.init();
|
||||||
|
@ -571,6 +591,11 @@ auto main() -> int {
|
||||||
|
|
||||||
plane.update(window.keyboard_input());
|
plane.update(window.keyboard_input());
|
||||||
|
|
||||||
|
background.scrolling_speed *= SCROLLING_SPEED_INC_FACTOR;
|
||||||
|
ground.scrolling_speed *= SCROLLING_SPEED_INC_FACTOR;
|
||||||
|
rocks1.scrolling_speed *= SCROLLING_SPEED_INC_FACTOR;
|
||||||
|
rocks2.scrolling_speed *= SCROLLING_SPEED_INC_FACTOR;
|
||||||
|
|
||||||
if (plane.aabb.is_colliding_with(rocks1.top_aabb) ||
|
if (plane.aabb.is_colliding_with(rocks1.top_aabb) ||
|
||||||
plane.aabb.is_colliding_with(rocks1.bottom_aabb) ||
|
plane.aabb.is_colliding_with(rocks1.bottom_aabb) ||
|
||||||
plane.aabb.is_colliding_with(rocks2.top_aabb) ||
|
plane.aabb.is_colliding_with(rocks2.top_aabb) ||
|
||||||
|
@ -586,8 +611,8 @@ auto main() -> int {
|
||||||
// Reset everything.
|
// Reset everything.
|
||||||
background.init();
|
background.init();
|
||||||
ground.init();
|
ground.init();
|
||||||
rocks1.init(1.2f);
|
rocks1.init(1.2f, true);
|
||||||
rocks2.init(2.4f);
|
rocks2.init(2.4f, true);
|
||||||
plane.init();
|
plane.init();
|
||||||
game_state = GameState::Start;
|
game_state = GameState::Start;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue