Améliore l'animation de rotation
This commit is contained in:
parent
8d4a003e97
commit
c303814346
|
@ -20,7 +20,6 @@ class Level : public State {
|
||||||
private:
|
private:
|
||||||
sf::View camera;
|
sf::View camera;
|
||||||
float camera_angle;
|
float camera_angle;
|
||||||
float camera_angle_animate;
|
|
||||||
GravityDirection gravity_direction;
|
GravityDirection gravity_direction;
|
||||||
|
|
||||||
sf::String name;
|
sf::String name;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
#include "block.hpp"
|
#include "block.hpp"
|
||||||
#include "gravity_block.hpp"
|
#include "gravity_block.hpp"
|
||||||
|
#include <iostream>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
@ -29,8 +30,7 @@ std::map<unsigned int, std::function<ObjectPtr(std::ifstream&)>> object_type_map
|
||||||
{GravityBlock::TYPE_ID, GravityBlock::load}
|
{GravityBlock::TYPE_ID, GravityBlock::load}
|
||||||
};
|
};
|
||||||
|
|
||||||
Level::Level(Manager& manager) : State(manager),
|
Level::Level(Manager& manager) : State(manager), camera_angle(180.f),
|
||||||
camera_angle(0.f), camera_angle_animate(0.f),
|
|
||||||
gravity_direction(GravityDirection::SOUTH) {}
|
gravity_direction(GravityDirection::SOUTH) {}
|
||||||
Level::~Level() {}
|
Level::~Level() {}
|
||||||
|
|
||||||
|
@ -153,8 +153,17 @@ void Level::draw() {
|
||||||
sf::RenderWindow& window = getWindow();
|
sf::RenderWindow& window = getWindow();
|
||||||
|
|
||||||
// animation de la rotation de la caméra
|
// animation de la rotation de la caméra
|
||||||
float change = (180 + (float) gravity_direction * 90 - camera_angle) * Constants::PHYSICS_TIME.asSeconds();
|
float goal = std::fmod((float) gravity_direction * 90, 360);
|
||||||
camera.rotate(change);
|
float diff = goal - camera_angle;
|
||||||
|
float speed = diff * Constants::PHYSICS_TIME.asSeconds() * 5;
|
||||||
|
|
||||||
|
if (std::abs(diff) < .05f) {
|
||||||
|
camera_angle = goal;
|
||||||
|
} else {
|
||||||
|
camera_angle += speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
camera.setRotation(camera_angle + 180);
|
||||||
window.setView(camera);
|
window.setView(camera);
|
||||||
|
|
||||||
// efface la scène précédente et dessine la couche de fond
|
// efface la scène précédente et dessine la couche de fond
|
||||||
|
|
Loading…
Reference in New Issue