forked from Hartmut/paradiso
Add different world and plane types
This commit is contained in:
parent
c46779d92c
commit
80a0919c3f
1 changed files with 97 additions and 29 deletions
|
@ -166,11 +166,11 @@ struct Rocks {
|
|||
static constexpr float GAP_SIZE = 1.5f;
|
||||
|
||||
// The image's size is 108x239 px.
|
||||
static constexpr float INIT_SCALE_X = 108.0f / WINDOW_WIDTH;
|
||||
static constexpr float INIT_SCALE_Y = 239.0f / WINDOW_HEIGHT;
|
||||
static constexpr float SCALE_X = 108.0f / WINDOW_WIDTH;
|
||||
static constexpr float SCALE_Y = 239.0f / WINDOW_HEIGHT;
|
||||
|
||||
static constexpr paradiso::Vector2<float> INIT_SCALE{
|
||||
paradiso::Vector2<float>::make(INIT_SCALE_X, INIT_SCALE_Y)};
|
||||
static constexpr paradiso::Vector2<float> SCALE{
|
||||
paradiso::Vector2<float>::make(SCALE_X, SCALE_Y)};
|
||||
|
||||
float scrolling_speed = INIT_SCROLLING_SPEED;
|
||||
|
||||
|
@ -186,14 +186,14 @@ struct Rocks {
|
|||
float init_pivot_x = 0.0f;
|
||||
|
||||
auto get_random_top_position_y() -> float {
|
||||
return 1.0f - INIT_SCALE_Y + (std::rand() % 50) / 100.0f + 0.01f;
|
||||
return 1.0f - SCALE_Y + (std::rand() % 50) / 100.0f + 0.01f;
|
||||
}
|
||||
|
||||
void init_aabbs() {
|
||||
// We'll make the width a quarter the width of the texture.
|
||||
// (If you want 1:1 size, you need to double the scale of the sprite.)
|
||||
auto size = paradiso::Vector2<float>{
|
||||
paradiso::Vector2<float>::make(INIT_SCALE_X / 2, INIT_SCALE_Y * 2)};
|
||||
paradiso::Vector2<float>::make(SCALE_X / 2, SCALE_Y * 2)};
|
||||
|
||||
auto top_position =
|
||||
paradiso::Vector2<float>{paradiso::Vector2<float>::make(
|
||||
|
@ -218,13 +218,13 @@ struct Rocks {
|
|||
top_sprite = paradiso::Sprite{.bitmap = sprite_map["rocks.top"],
|
||||
.pivot = {paradiso::Vector2<float>::make(
|
||||
init_pivot_x, top_position_y)},
|
||||
.scale = INIT_SCALE};
|
||||
.scale = SCALE};
|
||||
|
||||
bottom_sprite =
|
||||
paradiso::Sprite{.bitmap = sprite_map["rocks.bottom"],
|
||||
.pivot = {paradiso::Vector2<float>::make(
|
||||
init_pivot_x, bottom_position_y)},
|
||||
.scale = INIT_SCALE};
|
||||
.scale = SCALE};
|
||||
|
||||
init_aabbs();
|
||||
}
|
||||
|
@ -305,17 +305,17 @@ struct Plane {
|
|||
static constexpr float INIT_VELOCITY_Y = 0.0f;
|
||||
static constexpr float INIT_ROTATION = 0.0f;
|
||||
|
||||
static constexpr paradiso::Vector2<float> INIT_PIVOT{
|
||||
paradiso::Vector2<float>::make(0.0f, INIT_POSITION_Y)};
|
||||
|
||||
static const unsigned int ANIM_INTERVAL = 10;
|
||||
|
||||
// The image's size is 88x73 px.
|
||||
static constexpr float INIT_SCALE_X = 88.0f / WINDOW_WIDTH;
|
||||
static constexpr float INIT_SCALE_Y = 73.0f / WINDOW_HEIGHT;
|
||||
static constexpr float SCALE_X = 88.0f / WINDOW_WIDTH;
|
||||
static constexpr float SCALE_Y = 73.0f / WINDOW_HEIGHT;
|
||||
|
||||
static constexpr paradiso::Vector2<float> INIT_SCALE{
|
||||
paradiso::Vector2<float>::make(INIT_SCALE_X, INIT_SCALE_Y)};
|
||||
|
||||
static constexpr paradiso::Vector2<float> INIT_PIVOT{
|
||||
paradiso::Vector2<float>::make(0.0f, INIT_POSITION_Y)};
|
||||
static constexpr paradiso::Vector2<float> SCALE{
|
||||
paradiso::Vector2<float>::make(SCALE_X, SCALE_Y)};
|
||||
|
||||
// Animation sprites
|
||||
std::array<paradiso::Sprite, 3> sprites;
|
||||
|
@ -338,9 +338,10 @@ struct Plane {
|
|||
void init_aabb() {
|
||||
// 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.)
|
||||
// We could use INIT_SCALE here, but we'll keep this for clarity.
|
||||
// We could use 'SCALE' here, but we'll keep this for clarity.
|
||||
// (Although, now we no longer need 'SCALE' as a constant in this entire struct.)
|
||||
auto size = paradiso::Vector2<float>{
|
||||
paradiso::Vector2<float>::make(INIT_SCALE_X, INIT_SCALE_Y)};
|
||||
paradiso::Vector2<float>::make(SCALE_X, SCALE_Y)};
|
||||
|
||||
// Center it.
|
||||
auto position = paradiso::Vector2<float>{paradiso::Vector2<float>::make(
|
||||
|
@ -352,13 +353,13 @@ struct Plane {
|
|||
void init(SpriteMap& sprite_map) {
|
||||
sprites = {paradiso::Sprite{.bitmap = sprite_map["plane.1"],
|
||||
.pivot = INIT_PIVOT,
|
||||
.scale = INIT_SCALE},
|
||||
.scale = SCALE},
|
||||
paradiso::Sprite{.bitmap = sprite_map["plane.2"],
|
||||
.pivot = INIT_PIVOT,
|
||||
.scale = INIT_SCALE},
|
||||
.scale = SCALE},
|
||||
paradiso::Sprite{.bitmap = sprite_map["plane.3"],
|
||||
.pivot = INIT_PIVOT,
|
||||
.scale = INIT_SCALE}};
|
||||
.scale = SCALE}};
|
||||
|
||||
init_aabb();
|
||||
}
|
||||
|
@ -366,7 +367,6 @@ struct Plane {
|
|||
void reset() {
|
||||
for (auto& sprite : sprites) {
|
||||
sprite.pivot = INIT_PIVOT;
|
||||
sprite.scale = INIT_SCALE;
|
||||
}
|
||||
|
||||
position_y = INIT_POSITION_Y;
|
||||
|
@ -547,20 +547,84 @@ enum class GameState { Start, Playing, GameOver };
|
|||
struct App {
|
||||
SpriteMap sprites;
|
||||
|
||||
static auto create() -> App {
|
||||
enum class WorldType { Dirt, Grass, Ice, Rock, Snow };
|
||||
enum class PlaneType { Blue, Green, Red, Yellow };
|
||||
|
||||
static auto create(WorldType world_type = WorldType::Grass, PlaneType plane_type = PlaneType::Red) -> App {
|
||||
auto app = App{};
|
||||
|
||||
paradiso::BitmapIO::get().set_path(
|
||||
paradiso::get_executable_path().parent_path().string() + "/assets");
|
||||
|
||||
// Yes, I'm lazy, how did you know?
|
||||
const char *ground_filename = nullptr;
|
||||
const char *rocks_top_filename = nullptr;
|
||||
const char *rocks_bottom_filename = nullptr;
|
||||
switch (world_type) {
|
||||
case WorldType::Dirt:
|
||||
ground_filename = "PNG/groundDirt.png";
|
||||
rocks_top_filename = "PNG/rockDown.png";
|
||||
rocks_bottom_filename = "PNG/rock.png";
|
||||
break;
|
||||
case WorldType::Ice:
|
||||
ground_filename = "PNG/groundIce.png";
|
||||
rocks_top_filename = "PNG/rockIceDown.png";
|
||||
rocks_bottom_filename = "PNG/rockIce.png";
|
||||
break;
|
||||
case WorldType::Rock:
|
||||
ground_filename = "PNG/groundRock.png";
|
||||
rocks_top_filename = "PNG/rockDown.png";
|
||||
rocks_bottom_filename = "PNG/rock.png";
|
||||
break;
|
||||
case WorldType::Snow:
|
||||
ground_filename = "PNG/groundSnow.png";
|
||||
rocks_top_filename = "PNG/rockSnowDown.png";
|
||||
rocks_bottom_filename = "PNG/rockSnow.png";
|
||||
break;
|
||||
default:
|
||||
case WorldType::Grass:
|
||||
ground_filename = "PNG/groundGrass.png";
|
||||
rocks_top_filename = "PNG/rockGrassDown.png";
|
||||
rocks_bottom_filename = "PNG/rockGrass.png";
|
||||
break;
|
||||
}
|
||||
|
||||
// Yes, I'm lazy, how did you know?
|
||||
const char *plane_1_filename = nullptr;
|
||||
const char *plane_2_filename = nullptr;
|
||||
const char *plane_3_filename = nullptr;
|
||||
switch (plane_type) {
|
||||
case PlaneType::Blue:
|
||||
plane_1_filename = "PNG/Planes/planeBlue1.png";
|
||||
plane_2_filename = "PNG/Planes/planeBlue2.png";
|
||||
plane_3_filename = "PNG/Planes/planeBlue3.png";
|
||||
break;
|
||||
case PlaneType::Green:
|
||||
plane_1_filename = "PNG/Planes/planeGreen1.png";
|
||||
plane_2_filename = "PNG/Planes/planeGreen2.png";
|
||||
plane_3_filename = "PNG/Planes/planeGreen3.png";
|
||||
break;
|
||||
case PlaneType::Yellow:
|
||||
plane_1_filename = "PNG/Planes/planeYellow1.png";
|
||||
plane_2_filename = "PNG/Planes/planeYellow2.png";
|
||||
plane_3_filename = "PNG/Planes/planeYellow3.png";
|
||||
break;
|
||||
default:
|
||||
case PlaneType::Red:
|
||||
plane_1_filename = "PNG/Planes/planeRed1.png";
|
||||
plane_2_filename = "PNG/Planes/planeRed2.png";
|
||||
plane_3_filename = "PNG/Planes/planeRed3.png";
|
||||
break;
|
||||
}
|
||||
|
||||
auto assets = std::array{
|
||||
SpriteName{"background", "PNG/background.png"},
|
||||
SpriteName{"ground", "PNG/groundGrass.png"},
|
||||
SpriteName{"rocks.top", "PNG/rockGrassDown.png"},
|
||||
SpriteName{"rocks.bottom", "PNG/rockGrass.png"},
|
||||
SpriteName{"plane.1", "PNG/Planes/planeRed1.png"},
|
||||
SpriteName{"plane.2", "PNG/Planes/planeRed2.png"},
|
||||
SpriteName{"plane.3", "PNG/Planes/planeRed3.png"},
|
||||
SpriteName{"ground", ground_filename},
|
||||
SpriteName{"rocks.top", rocks_top_filename},
|
||||
SpriteName{"rocks.bottom", rocks_bottom_filename},
|
||||
SpriteName{"plane.1", plane_1_filename},
|
||||
SpriteName{"plane.2", plane_2_filename},
|
||||
SpriteName{"plane.3", plane_3_filename},
|
||||
SpriteName{"tap_sign.left", "PNG/UI/tapRight.png"},
|
||||
SpriteName{"tap_sign.right", "PNG/UI/tapLeft.png"},
|
||||
SpriteName{"tap.normal", "PNG/UI/tap.png"},
|
||||
|
@ -725,7 +789,11 @@ struct App {
|
|||
|
||||
auto main() -> int {
|
||||
std::srand(std::time(nullptr));
|
||||
auto app = TappyPlane::App::create();
|
||||
|
||||
auto world_type = TappyPlane::App::WorldType::Grass;
|
||||
auto plane_type = TappyPlane::App::PlaneType::Red;
|
||||
|
||||
auto app = TappyPlane::App::create(world_type, plane_type);
|
||||
app.run();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue