Added test pipe sprite to quickwings (random pos)

This commit is contained in:
brxxh 2023-11-23 20:10:35 +01:00
parent 6ae437ef75
commit 68915cb24b

View file

@ -5,6 +5,7 @@
*
*/
#include <cstdlib>
#include <ostream>
#include <paradiso/bitmap.hpp>
#include <paradiso/bitmap_io.hpp>
@ -21,6 +22,8 @@
#include <iostream>
#include <thread>
#include <unordered_map>
#include <cstdlib>
#include <ctime>
// #include "lib/image_loader.hpp"
@ -74,12 +77,49 @@ struct Background {
paradiso::Renderer renderer{};
};
struct Pipe {
paradiso::Sprite pipe_top;
paradiso::Sprite pipe_bottom;
paradiso::Renderer renderer1{};
paradiso::Renderer renderer2{};
int pipe_spawn_rand_int = rand() % 80 + 25;
float pipe_spawn_rand = float(pipe_spawn_rand_int) / 100;
Pipe() {
auto pipe_image = paradiso::BitmapIO::get().load("pipe-green.png");
pipe_top = paradiso::Sprite{
.bitmap = pipe_image,
.pivot = {paradiso::Vector2<float>::make(0.0f, pipe_spawn_rand + 1.0f)},
.scale = {paradiso::Vector2<float>::make(((500.0f - (500.0f - 52.0f)) / 500.0f) * 2.25f, ((700.0f - (700.0f - 320.0f)) / 700.0f) * 2.25f)},
.rotation = 3.1415926f};
pipe_bottom = paradiso::Sprite{
.bitmap = pipe_image,
.pivot = {paradiso::Vector2<float>::make(0.0f, pipe_spawn_rand - 1.6f)},
.scale = {paradiso::Vector2<float>::make(((500.0f - (500.0f - 52.0f)) / 500.0f) * 2.25f, ((700.0f - (700.0f - 320.0f)) / 700.0f) * 2.25f)}};
}
void draw(const paradiso::Shader& shader) {
shader.set_uniform("pivot", pipe_bottom.pivot);
shader.set_uniform("scale", pipe_bottom.scale);
renderer1.draw(pipe_bottom, shader);
shader.set_uniform("pivot", pipe_top.pivot);
shader.set_uniform("scale", pipe_top.scale);
shader.set_uniform("rotation", pipe_top.rotation);
renderer1.draw(pipe_top, shader);
}
};
struct Grass {
paradiso::Sprite grassLeft;
paradiso::Sprite grassRight;
paradiso::Sprite* scrolling[2] = {&grassLeft, &grassRight};
paradiso::Renderer renderer{};
Grass() {
auto grassImage = paradiso::BitmapIO::get().load("base.png");
grassLeft = paradiso::Sprite{
@ -104,13 +144,10 @@ struct Grass {
renderer.draw(*sprite, shader);
}
}
paradiso::Renderer renderer{};
};
struct QuickWings {
paradiso::Renderer renderer1{};
paradiso::Renderer renderer2{};
paradiso::Renderer renderer3{};
@ -248,8 +285,6 @@ struct QuickWings {
}
};
// TODO: finish this
struct Message {
paradiso::Sprite messageSprite;
paradiso::Renderer renderer{};
@ -305,6 +340,7 @@ struct GameOverMessage {
};
auto main() -> int {
std::srand(std::time(nullptr));
// Ausgabefenster ... sieht aus als wäre es auf dem Stack
auto window = paradiso::Window();
@ -347,10 +383,11 @@ auto main() -> int {
paradiso::BitmapIO::get().set_path("assets");
// Load
auto message = Message{};
auto background = Background{};
auto grass = Grass{};
auto quickwingsapp = QuickWings{};
auto pipe = Pipe{};
auto message = Message{};
auto gameover = GameOverMessage{};
// timer
@ -374,6 +411,7 @@ auto main() -> int {
// Draw
background.draw(shader);
pipe.draw(shader);
grass.draw(shader);
message.draw(shader);