]> git.localhorst.tv Git - orbi.git/blobdiff - src/app/Application.cpp
rotatable arm for character entities
[orbi.git] / src / app / Application.cpp
index 3ba8485db63554d012f05fd0de5a56ca9b37f283..3ddb41443a3d4bd6860603cd69a7e1073b670a87 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "../graphics/Canvas.h"
 #include "../graphics/Color.h"
+#include "../world/Character.h"
 #include "../world/Entity.h"
 #include "../world/Tileset.h"
 #include "../world/World.h"
@@ -157,6 +158,9 @@ void Application::Update(int dt) {
                ? ctrl.Controlled().vbox.Center()
                : target.Pos();
        cam.Update(delta);
+
+       // testing arm rotation
+       //dynamic_cast<Character *>(*world.Entities().begin())->armAngle -= 3 * delta;
 }
 
 
@@ -197,26 +201,28 @@ void Application::RenderEntities() {
        for (const Entity *e : world.Entities()) {
                canvas.SetColor(boundsColor);
                canvas.OutlineRect(
-                       cam.ToScreen(Vector<float>(e->bounds.Left(), e->bounds.Top())),
-                       cam.ToScale(Vector<float>(e->bounds.Size()))
+                       cam.ToScreen(e->bounds.Position()),
+                       cam.ToScale(e->bounds.Size())
                );
+               if (const Character *c = dynamic_cast<const Character *>(e)) {
+                       canvas.OutlineRectRot(
+                               Rect<float>(
+                                       cam.ToScreen(c->bounds.Position() + c->arm.Position()),
+                                       cam.ToScale(c->arm.Size())
+                               ),
+                               cam.ToScreen(c->bounds.Position() + c->armOrigin),
+                               c->armAngle
+                       );
+               }
                canvas.SetColor(vboxColor);
-               canvas.Line(
-                       cam.ToScreen(Vector<float>(e->vbox.Left(), e->vbox.Top())),
-                       cam.ToScreen(Vector<float>(e->vbox.Right(), e->vbox.Top())) - Vector<int>(1, 0)
-               );
-               canvas.Line(
-                       cam.ToScreen(Vector<float>(e->vbox.Left(), e->vbox.Bottom())) - Vector<int>(0, 1),
-                       cam.ToScreen(Vector<float>(e->vbox.Right(), e->vbox.Bottom())) - Vector<int>(1, 1)
+               canvas.OutlineRect(
+                       cam.ToScreen(e->vbox.Position()),
+                       cam.ToScale(e->vbox.Size())
                );
                canvas.SetColor(hboxColor);
-               canvas.Line(
-                       cam.ToScreen(Vector<float>(e->hbox.Left(), e->hbox.Top())),
-                       cam.ToScreen(Vector<float>(e->hbox.Left(), e->hbox.Bottom())) - Vector<int>(0, 1)
-               );
-               canvas.Line(
-                       cam.ToScreen(Vector<float>(e->hbox.Right(), e->hbox.Top())) - Vector<int>(1, 0),
-                       cam.ToScreen(Vector<float>(e->hbox.Right(), e->hbox.Bottom())) - Vector<int>(1, 1)
+               canvas.OutlineRect(
+                       cam.ToScreen(e->hbox.Position()),
+                       cam.ToScale(e->hbox.Size())
                );
        }
 }