]> git.localhorst.tv Git - orbi.git/blobdiff - src/app/Application.cpp
rotatable arm for character entities
[orbi.git] / src / app / Application.cpp
index cbfafd374537935625dbaad63955d4d7edacbcd6..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"
@@ -148,15 +149,18 @@ void Application::OnKeyUp(const SDL_KeyboardEvent &e) {
 
 void Application::Update(int dt) {
        const float delta = dt / 1e3;
-       ctrl.Update(delta);
+       for (int i = 0; i < dt; ++i) {
+               ctrl.Update(1e-3);
+               world.Update(1e-3);
+       }
        target.Update(delta);
        focus = ctrl.Controlling()
-               ? ctrl.Controlled().bounds.Center()
+               ? ctrl.Controlled().vbox.Center()
                : target.Pos();
        cam.Update(delta);
-       for (int i = 0; i < dt; ++i) {
-               world.Update(1e-3);
-       }
+
+       // testing arm rotation
+       //dynamic_cast<Character *>(*world.Entities().begin())->armAngle -= 3 * delta;
 }
 
 
@@ -169,9 +173,13 @@ void Application::Render() {
 
 void Application::RenderBackground() {
        constexpr Color background(0x00, 0x00, 0x00);
+       constexpr Color outlineColor(0x00, 0x00, 0xFA);
 
        canvas.SetColor(background);
        canvas.Fill();
+
+       canvas.SetColor(outlineColor);
+       canvas.Grid(cam.ToScreen(Vector<int>(0, 0)), cam.ToScale(world.Size()), cam.ToScale(world.TileSize()));
 }
 
 void Application::RenderWorld() {
@@ -186,23 +194,42 @@ void Application::RenderWorld() {
 }
 
 void Application::RenderEntities() {
-       constexpr Color entityColor(0x00, 0xFA, 0x00);
-       canvas.SetColor(entityColor);
-
-       for (const Entity &e : world.Entities()) {
-               const Vector<float> pos(e.bounds.Left(), e.bounds.Top());
-               const Vector<float> size(e.bounds.Size());
-               canvas.OutlineRect(cam.ToScreen(pos), cam.ToScale(size));
+       constexpr Color boundsColor(0xFA, 0x00, 0x00);
+       constexpr Color vboxColor(0xFA, 0xFA, 0x00);
+       constexpr Color hboxColor(0x00, 0xFA, 0x00);
+
+       for (const Entity *e : world.Entities()) {
+               canvas.SetColor(boundsColor);
+               canvas.OutlineRect(
+                       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.OutlineRect(
+                       cam.ToScreen(e->vbox.Position()),
+                       cam.ToScale(e->vbox.Size())
+               );
+               canvas.SetColor(hboxColor);
+               canvas.OutlineRect(
+                       cam.ToScreen(e->hbox.Position()),
+                       cam.ToScale(e->hbox.Size())
+               );
        }
 }
 
 void Application::RenderUI() {
-       constexpr Color outlineColor(0x00, 0x00, 0xFA);
        constexpr Color targetColor(0xFA, 0xFA, 0x00);
 
-       canvas.SetColor(outlineColor);
-       canvas.Grid(cam.ToScreen(Vector<int>(0, 0)), cam.ToScale(world.Size()), cam.ToScale(Vector<float>(1, 1)));
-
        canvas.SetColor(targetColor);
        canvas.Cross(cam.ToScreen(target.Pos()), 15);
 }