Animation du bloc gravité une fois utilisé
This commit is contained in:
parent
89e1f0b30b
commit
ad7cab00c2
|
@ -14,6 +14,8 @@ public:
|
|||
|
||||
private:
|
||||
GravityDirection gravity_direction;
|
||||
sf::Sprite icon_sprite;
|
||||
float opacity;
|
||||
bool used;
|
||||
|
||||
protected:
|
||||
|
@ -38,9 +40,9 @@ public:
|
|||
virtual Object::Ptr clone() const;
|
||||
|
||||
/**
|
||||
* Prépare les textures avant le dessin du bloc
|
||||
* Dessin du bloc dans la fenêtre donnée
|
||||
*/
|
||||
virtual void prepareDraw(ResourceManager& resources);
|
||||
virtual void draw(Level& level);
|
||||
|
||||
/**
|
||||
* Appelé lorsque le bloc de gravité est activé par un objet
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef __SKIZZLE_UTILITY_HPP__
|
||||
#define __SKIZZLE_UTILITY_HPP__
|
||||
|
||||
namespace Utility {
|
||||
/**
|
||||
* Permet d'animer la valeur donnée vers la valeur cible
|
||||
* avec la vitesse donnée
|
||||
*/
|
||||
float animateValue(float current, float speed, float goal);
|
||||
}
|
||||
|
||||
#endif
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -7,6 +7,9 @@
|
|||
const unsigned int Block::TYPE_ID = 2;
|
||||
|
||||
Block::Block() : Object() {
|
||||
sprite.setOrigin(sf::Vector2f(23, 23));
|
||||
select_sprite.setOrigin(sf::Vector2f(23, 23));
|
||||
|
||||
aabb = sf::FloatRect(
|
||||
-Manager::GRID / 2,
|
||||
-Manager::GRID / 2,
|
||||
|
@ -45,10 +48,7 @@ void Block::prepareDraw(ResourceManager& resources) {
|
|||
}
|
||||
|
||||
sprite.setTexture(resources.getTexture(texture_name));
|
||||
sprite.setOrigin(sf::Vector2f(23, 23));
|
||||
|
||||
select_sprite.setTexture(resources.getTexture("block_select.tga"));
|
||||
select_sprite.setOrigin(sf::Vector2f(23, 23));
|
||||
}
|
||||
|
||||
void Block::draw(Level& level) {
|
||||
|
|
|
@ -398,6 +398,15 @@ void Editor::removeObject(Object::Ptr object) {
|
|||
selection.begin(), selection.end(), object
|
||||
), selection.end());
|
||||
|
||||
// si c'était un joueur, il faut renuméroter
|
||||
// les autres pour plus de convenance
|
||||
if (object->getTypeId() == Player::TYPE_ID) {
|
||||
// on réattribue les numéros de joueurs
|
||||
for (unsigned int i = 0; i < getPlayers().size(); i++) {
|
||||
getPlayers()[i]->setPlayerNumber(i);
|
||||
}
|
||||
}
|
||||
|
||||
Level::removeObject(object);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
#include "resource_manager.hpp"
|
||||
#include "manager.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "gravity_block.hpp"
|
||||
#include "game.hpp"
|
||||
|
||||
const unsigned int GravityBlock::TYPE_ID = 3;
|
||||
|
||||
GravityBlock::GravityBlock() : Block(), used(false) {}
|
||||
GravityBlock::GravityBlock() : Block(), opacity(255), used(false) {
|
||||
icon_sprite.setOrigin(sf::Vector2f(23, 23));
|
||||
}
|
||||
|
||||
GravityBlock::~GravityBlock() {}
|
||||
|
||||
Object::Ptr GravityBlock::clone() const {
|
||||
return Object::Ptr(new GravityBlock(*this));
|
||||
}
|
||||
|
||||
void GravityBlock::prepareDraw(ResourceManager& resources) {
|
||||
Block::prepareDraw(resources);
|
||||
void GravityBlock::draw(Level& level) {
|
||||
// sélectionne le sprite d'icône
|
||||
std::string texture_name = "gravity_block_";
|
||||
|
||||
switch (gravity_direction) {
|
||||
|
@ -33,7 +37,20 @@ void GravityBlock::prepareDraw(ResourceManager& resources) {
|
|||
break;
|
||||
}
|
||||
|
||||
sprite.setTexture(resources.getTexture(texture_name + ".tga"));
|
||||
// on dessine le bloc normal
|
||||
Block::draw(level);
|
||||
|
||||
// on anime l'opacité de l'icône
|
||||
opacity = Utility::animateValue(opacity, 2, used ? 0 : 255);
|
||||
icon_sprite.setColor(sf::Color(255, 255, 255, opacity));
|
||||
|
||||
// on dessine l'icône
|
||||
icon_sprite.setTexture(level.getResourceManager().getTexture(
|
||||
texture_name + ".tga"
|
||||
));
|
||||
|
||||
icon_sprite.setPosition(getPosition());
|
||||
level.getWindow().draw(icon_sprite);
|
||||
}
|
||||
|
||||
void GravityBlock::activate(Game& game, Object::Ptr object) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "level.hpp"
|
||||
#include "player.hpp"
|
||||
#include "block.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "gravity_block.hpp"
|
||||
#include "switch_block.hpp"
|
||||
#include "finish_block.hpp"
|
||||
|
@ -285,15 +286,10 @@ void Level::draw() {
|
|||
sf::Vector2u window_size = window.getSize();
|
||||
|
||||
// animation de la rotation de la caméra
|
||||
float goal = std::fmod((float) gravity_direction * 90, 360);
|
||||
float diff = goal - camera_angle;
|
||||
float speed = diff * Manager::FRAME_TIME.asSeconds() * 5;
|
||||
|
||||
if (std::abs(diff) < .05f) {
|
||||
camera_angle = goal;
|
||||
} else {
|
||||
camera_angle += speed;
|
||||
}
|
||||
camera_angle = Utility::animateValue(
|
||||
camera_angle, 5,
|
||||
std::fmod((float) gravity_direction * 90, 360)
|
||||
);
|
||||
|
||||
camera.setRotation(camera_angle + 180);
|
||||
window.setView(camera);
|
||||
|
@ -497,11 +493,6 @@ void Level::removeObject(Object::Ptr object) {
|
|||
players.erase(std::remove(
|
||||
players.begin(), players.end(), player
|
||||
), players.end());
|
||||
|
||||
// on réattribue les numéros de joueurs
|
||||
for (unsigned int i = 0; i < players.size(); i++) {
|
||||
players[i]->setPlayerNumber(i);
|
||||
}
|
||||
}
|
||||
|
||||
// on supprime l'objet de la liste d'objets
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#include "utility.hpp"
|
||||
#include "manager.hpp"
|
||||
#include <cmath>
|
||||
|
||||
float Utility::animateValue(float current, float speed, float goal) {
|
||||
float gap = goal - current;
|
||||
float diff = gap * Manager::FRAME_TIME.asSeconds() * speed;
|
||||
|
||||
// si on est très proches de la fin, on termine
|
||||
if (std::abs(gap) < .05f) {
|
||||
return goal;
|
||||
}
|
||||
|
||||
return current + diff;
|
||||
}
|
Loading…
Reference in New Issue