This repository has been archived on 2019-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
dungeon-gunner/source/abstract/Rectangle.cpp
Felix Ableitner aa6df65e97 Changed sprites to always render as rectangle.
Also created Rectangle/Circle subclasses for sprite to handle
collision detection and moved collision detection from World to
CollisionModel (static methods).
2013-05-08 00:42:26 +02:00

37 lines
977 B
C++

/*
* Rectangle.cpp
*
* Created on: 04.05.2013
* Author: Felix
*/
#include "Rectangle.h"
#include "Circle.h"
#include "../util/Yaml.h"
Rectangle::Rectangle(const sf::Vector2f& position, Category category,
unsigned short mask, const Yaml& config,
const sf::Vector2f& direction) :
Sprite(position, category, mask, config.get(YAML_KEY::SIZE, sf::Vector2f()),
config.get(YAML_KEY::TEXTURE, std::string()), direction) {
}
/**
* Returns true if a collision between this and other occured. It does not
* matter which object is this or other.
*/
bool
Rectangle::testCollision(std::shared_ptr<Sprite> other, int elapsed) {
Rectangle* rect = dynamic_cast<Rectangle*>(other.get());
Circle* circle = dynamic_cast<Circle*>(other.get());
if (circle != nullptr)
return CollisionModel::testCollision(*circle, *this, elapsed);
else if (rect != nullptr)
return CollisionModel::testCollision(*rect, *this, elapsed);
else {
assert(false);
return false;
}
}