forked from Hartmut/paradiso
properly use std::clamp
This commit is contained in:
parent
b9c7ce3b48
commit
e92dadaf4d
1 changed files with 20 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* paradiso - Paradigmen der Softwareentwicklung
|
* paradiso - Paradigmen der Softwareentwicklung
|
||||||
*
|
*
|
||||||
* (c) Copyright 2023 Hartmut Seichter
|
* (c) Copyright 2023-2024 Hartmut Seichter
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include <iomanip>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
struct PongStage {
|
struct PongStage {
|
||||||
|
@ -86,7 +85,7 @@ struct PongPaddle {
|
||||||
velocity_horizontal *= whoopiness;
|
velocity_horizontal *= whoopiness;
|
||||||
sprite.pivot.x() += velocity_horizontal;
|
sprite.pivot.x() += velocity_horizontal;
|
||||||
|
|
||||||
std::clamp(sprite.pivot.x(), -0.5f, 0.5f);
|
sprite.pivot.x() = std::clamp(sprite.pivot.x(), -0.5f, 0.5f);
|
||||||
|
|
||||||
// update shader uniforms
|
// update shader uniforms
|
||||||
shader.set_uniform("pivot", sprite.pivot);
|
shader.set_uniform("pivot", sprite.pivot);
|
||||||
|
@ -151,7 +150,7 @@ struct PongBall {
|
||||||
|
|
||||||
void draw(const paradiso::Shader& shader) {
|
void draw(const paradiso::Shader& shader) {
|
||||||
|
|
||||||
std::clamp(sprite.pivot.x(), -0.5f, 0.5f);
|
sprite.pivot.x() = std::clamp(sprite.pivot.x(), -0.5f, 0.5f);
|
||||||
|
|
||||||
// update shader uniforms
|
// update shader uniforms
|
||||||
shader.set_uniform("pivot", sprite.pivot);
|
shader.set_uniform("pivot", sprite.pivot);
|
||||||
|
@ -166,6 +165,9 @@ struct PongBall {
|
||||||
paradiso::Renderer renderer{};
|
paradiso::Renderer renderer{};
|
||||||
|
|
||||||
constexpr void push(const auto& impulse) noexcept { velocity += impulse; }
|
constexpr void push(const auto& impulse) noexcept { velocity += impulse; }
|
||||||
|
|
||||||
|
constexpr void whoop(const auto& whoopiness) noexcept { velocity *= whoopiness; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto main() -> int {
|
auto main() -> int {
|
||||||
|
@ -234,6 +236,19 @@ auto main() -> int {
|
||||||
ball.sprite.pivot.x() = 0.0f;
|
ball.sprite.pivot.x() = 0.0f;
|
||||||
ball.sprite.pivot.y() = 0.9f;
|
ball.sprite.pivot.y() = 0.9f;
|
||||||
}
|
}
|
||||||
|
// speed adjust
|
||||||
|
if (w.keyboard_input().top().key == 'N') {
|
||||||
|
|
||||||
|
std::cout << "Speed Up!\n";
|
||||||
|
|
||||||
|
ball.push(paradiso::Vector2<float>::make(0.f,0.01f));
|
||||||
|
|
||||||
|
} else if (w.keyboard_input().top().key == 'M') {
|
||||||
|
|
||||||
|
ball.push(paradiso::Vector2<float>::make(0.f,-0.01f));
|
||||||
|
|
||||||
|
std::cout << "Speed Lower!\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ball.interact(stage);
|
ball.interact(stage);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue