#include "../graphics/Canvas.h"
#include "../graphics/Color.h"
+#include "../world/Character.h"
#include "../world/Entity.h"
#include "../world/Tileset.h"
#include "../world/World.h"
? ctrl.Controlled().vbox.Center()
: target.Pos();
cam.Update(delta);
+
+ // testing arm rotation
+ //dynamic_cast<Character *>(*world.Entities().begin())->armAngle -= 3 * delta;
}
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())
);
}
}
SDL_RenderDrawLine(canv, from.x, from.y, to.x, to.y);
}
-void Canvas::FillRect(Vector<int> pos, Vector<int> size) {
- SDL_Rect destRect;
- destRect.x = pos.x;
- destRect.y = pos.y;
- destRect.w = size.x;
- destRect.h = size.y;
- SDL_RenderFillRect(canv, &destRect);
+void Canvas::FillRect(Rect<int> rect) {
+ SDL_RenderFillRect(canv, &rect);
}
-void Canvas::OutlineRect(Vector<int> pos, Vector<int> size) {
- SDL_Rect destRect;
- destRect.x = pos.x;
- destRect.y = pos.y;
- destRect.w = size.x;
- destRect.h = size.y;
- SDL_RenderDrawRect(canv, &destRect);
+void Canvas::OutlineRect(Rect<int> rect) {
+ SDL_RenderDrawRect(canv, &rect);
+}
+
+void Canvas::OutlineRectRot(Rect<float> rect, Vector<float> origin, float rot) {
+ const Vector<float> topLeft(rect.x, rect.y);
+ const Vector<float> topRight(rect.x + rect.w - 1, rect.y);
+ const Vector<float> botLeft(rect.x, rect.y + rect.h - 1);
+ const Vector<float> botRight(rect.x + rect.w - 1, rect.y + rect.h - 1);
+
+ Quad(
+ Rotate(topLeft - origin, rot) + origin,
+ Rotate(topRight - origin, rot) + origin,
+ Rotate(botRight - origin, rot) + origin,
+ Rotate(botLeft - origin, rot) + origin
+ );
}
#define ORBI_CANVAS_H_
#include "Color.h"
+#include "Rect.h"
#include "Texture.h"
#include "Vector.h"
void Outline();
void Line(Vector<int> from, Vector<int> to);
- void FillRect(Vector<int> pos, Vector<int> size);
- void OutlineRect(Vector<int> pos, Vector<int> size);
+ void FillRect(Rect<int>);
+ void OutlineRect(Rect<int>);
+ void OutlineRectRot(Rect<float>, Vector<float> origin, float rot);
+
+ void FillRect(Vector<int> pos, Vector<int> size) {
+ FillRect(Rect<int>(pos, size));
+ }
+ void OutlineRect(Vector<int> pos, Vector<int> size) {
+ OutlineRect(Rect<int>(pos, size));
+ }
void Dot(Vector<int> pos);
void Cross(Vector<int> pos, int extent);
constexpr Vector<Scalar> Rotate270(Vector<Scalar> v) {
return Vector<Scalar>(v.y, -v.x);
}
+// angle given in radians
template<class Scalar, class Float>
inline Vector<Scalar> Rotate(Vector<Scalar> v, Float by) {
Float sine(std::sin(by));
#include "graphics/Canvas.h"
#include "graphics/Window.h"
#include "world/AABB.h"
+#include "world/Character.h"
#include "world/Entity.h"
#include "world/Tile.h"
#include "world/Tileset.h"
world.SetTile(Vector<int>(2, 9), Tile(0));
world.SetTile(Vector<int>(3, 9), Tile(0));
- Entity e;
- e.bounds = AABB(0, 0, 2, 3);
- e.vbox = AABB(.1, 0, 1.8, 3);
- e.hbox = AABB(0, .1, 2, 1.8);
- e.Move(Vector<float>(5, 0));
- world.AddEntity(e);
+ Character player;
+ player.bounds = AABB(0, 0, 2, 3);
+ player.vbox = AABB(.1, 0, 1.8, 3);
+ player.hbox = AABB(0, .1, 2, 1.8);
+ player.arm = AABB(.5, 1.4, 1, .5);
+ player.armOrigin = Vector<float>(1.4, 1.65);
+ player.Move(Vector<float>(5, 0));
+ world.AddEntity(player);
Entity mob;
mob.bounds = AABB(0, 0, 2, 1.5);
world.AddEntity(mob);
Application app(canv, world, tiles);
- app.Control(e);
+ app.Control(player);
app.Run();
return 0;
--- /dev/null
+#ifndef ORBI_CHARACTER_H_
+#define ORBI_CHARACTER_H_
+
+#include "Entity.h"
+
+
+namespace orbi {
+
+class Character
+: public Entity {
+
+public:
+ constexpr Character() { }
+
+public:
+ AABB arm;
+ Vector<float> armOrigin;
+ float armAngle = 0;
+
+ int heldItem = -1;
+
+};
+
+}
+
+#endif
public:
constexpr Entity() { }
+ virtual ~Entity() { }
public:
void Update(float dt, Vector<float> extAcc, Vector<float> tv);