2016-03-08 21:49:52 +00:00
|
|
|
#include "block.hpp"
|
2016-03-14 20:20:40 +00:00
|
|
|
#include "constants.hpp"
|
2016-03-08 16:46:33 +00:00
|
|
|
|
2016-03-15 16:08:21 +00:00
|
|
|
Block::Block(float x, float y) : Object(x, y),
|
|
|
|
shape(sf::Vector2f(Constants::GRID, Constants::GRID)) {
|
|
|
|
// par défaut, les blocs ne sont pas déplaçables
|
|
|
|
// et ont donc une masse infinie
|
|
|
|
setMass(0.f);
|
|
|
|
|
2016-03-14 20:20:40 +00:00
|
|
|
shape.setOrigin(sf::Vector2f(Constants::GRID / 2, Constants::GRID / 2));
|
2016-03-14 20:11:09 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 17:07:34 +00:00
|
|
|
void Block::draw(sf::RenderWindow& window) {
|
2016-03-15 16:08:21 +00:00
|
|
|
Object::draw(window);
|
|
|
|
|
2016-03-12 13:15:27 +00:00
|
|
|
// chargement de la texture de test
|
2016-03-12 22:15:03 +00:00
|
|
|
if (!texture.loadFromFile("./res/block.png")) {
|
2016-03-12 13:15:27 +00:00
|
|
|
// erreur
|
2016-03-12 10:22:10 +00:00
|
|
|
}
|
2016-03-12 13:15:27 +00:00
|
|
|
|
|
|
|
shape.setTexture(&texture);
|
2016-03-12 10:22:10 +00:00
|
|
|
|
2016-03-15 16:08:21 +00:00
|
|
|
if (getCharge() > 0) {
|
2016-03-12 22:15:03 +00:00
|
|
|
shape.setFillColor(sf::Color(180, 180, 255));
|
2016-03-15 16:08:21 +00:00
|
|
|
} else if (getCharge() < 0) {
|
2016-03-12 22:15:03 +00:00
|
|
|
shape.setFillColor(sf::Color(255, 180, 180));
|
2016-03-11 15:15:27 +00:00
|
|
|
} else {
|
2016-03-12 22:15:03 +00:00
|
|
|
shape.setFillColor(sf::Color::White);
|
2016-03-11 15:15:27 +00:00
|
|
|
}
|
|
|
|
|
2016-03-15 16:08:21 +00:00
|
|
|
shape.setPosition(getPosition());
|
2016-03-10 21:16:07 +00:00
|
|
|
window.draw(shape);
|
2016-03-08 17:07:34 +00:00
|
|
|
}
|
2016-03-08 18:50:55 +00:00
|
|
|
|
2016-03-13 18:07:35 +00:00
|
|
|
std::unique_ptr<sf::FloatRect> Block::getAABB() {
|
|
|
|
return std::unique_ptr<sf::FloatRect>(new sf::FloatRect(
|
2016-03-15 16:08:21 +00:00
|
|
|
getPosition().x - Constants::GRID / 2,
|
|
|
|
getPosition().y - Constants::GRID / 2,
|
2016-03-14 20:20:40 +00:00
|
|
|
Constants::GRID, Constants::GRID
|
2016-03-13 18:07:35 +00:00
|
|
|
));
|
|
|
|
}
|