GameKit  0.0.1a
C++ gamedev tools
HitboxView.cpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: HitboxView.cpp
5  *
6  * Description:
7  *
8  * Created: 21/04/2018 09:24:07
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
19 
20 namespace gk {
21 
22 void HitboxView::draw(const SceneObject &object, RenderTarget &target, RenderStates states) {
23  if (object.has<LifetimeComponent>() && object.get<LifetimeComponent>().dead(object))
24  return;
25 
26  if (object.has<PositionComponent>()) {
27  states.transform.translate(object.get<PositionComponent>().x, object.get<PositionComponent>().y);
28  }
29 
30  if (object.has<HitboxComponent>()) {
31  const FloatRect *hitbox = object.get<HitboxComponent>().currentHitbox();
32  if(hitbox) {
33  RectangleShape rect;
34  rect.setPosition(hitbox->x, hitbox->y);
35  rect.setSize(hitbox->width, hitbox->height);
36  rect.setWireframeMode(true); // FIXME
37  rect.setColor(Color::White);
38 
39  target.draw(rect, states);
40  }
41  }
42 }
43 
44 } // namespace gk
45 
Transform & translate(float x, float y, float z=0)
Definition: Transform.cpp:28
void setPosition(float x, float y, float z=0)
T y
Top coordinate of the rectangle.
Definition: Rect.hpp:216
void draw(const IDrawable &drawable, const RenderStates &states=RenderStates::Default)
Transform transform
void setColor(const Color &color)
static const Color White
White predefined color.
Definition: Color.hpp:117
void setSize(float width, float height)
T x
Left coordinate of the rectangle.
Definition: Rect.hpp:215
void setWireframeMode(bool wireframeMode)
T width
Width of the rectangle.
Definition: Rect.hpp:217
void draw(const SceneObject &object, RenderTarget &target, RenderStates states)
Definition: HitboxView.cpp:22
T height
Height of the rectangle.
Definition: Rect.hpp:218