, univ(Vector<int>(10, 10), Vector<int>(10, 10), Vector<int>(10, 10))
, focus(Vector<float>(500, 500), 500)
, cam(c.Size(), focus.Pos())
+, controlled(univ.AddShip(Ship()))
+, linGauge(
+ Vector<int>(15, 100),
+ Vector<int>(10, 10),
+ Color(0xFF, 0xFF, 0xFF),
+ Color(0x00, 0x00, 0x00),
+ Color(0x00, 0xFF, 0x00),
+ Color(0xFF, 0x00, 0x00))
+, rotGauge(
+ Vector<int>(15, 100),
+ Vector<int>(27, 10),
+ Color(0xFF, 0xFF, 0xFF),
+ Color(0x00, 0x00, 0x00),
+ Color(0x33, 0x33, 0xFF),
+ Color(0x00, 0x00, 0xFF))
+, autopilot(*controlled, focus.Pos())
+, apEnabled(false)
, last(SDL_GetTicks())
-, running(false) {
- controlled = univ.AddEntity(Entity());
+, running(false)
+, paused(false) {
+ univ.AddResource(Resource("Liquid Hydrogen", 70));
+ univ.AddResource(Resource("Liquid Qxygen", 1141));
+ univ.AddResource(Resource("Water", 999));
}
void Application::Loop(int delta) {
HandleEvents();
- Update(delta);
+ if (delta == 0) {
+ SDL_Delay(1);
+ return;
+ }
+
+ if (!paused) {
+ Update(delta);
+ }
Render();
canvas.Present();
}
case SDLK_x:
cam.StartShrink();
break;
+ case SDLK_c:
+ apEnabled = !apEnabled;
+ break;
+ case SDLK_p:
+ paused = !paused;
+ break;
default:
break;
}
void Application::Update(int dt) {
const float delta = dt / 1e3;
- controlled->acc = Vector<float>(control * 10);
+ if (apEnabled) {
+ autopilot.Update(delta);
+ } else {
+ controlled->rotThrottle = control.x;
+ controlled->linThrottle = -control.y;
+ }
cam.Update(delta);
univ.Update(delta);
focus.SetSpeed(500 / cam.Zoom());
void Application::Render() {
+ RenderBackground();
+ RenderGrid();
+ RenderShips();
+ RenderUI();
+}
+
+void Application::RenderBackground() {
constexpr Color background(0x00, 0x00, 0x00);
- constexpr Color univGrid(0xEE, 0xEE, 0xEE);
- constexpr Color secGrid(0x77, 0x77, 0x77);
- constexpr Color entityColor(0x00, 0xAA, 0xAA);
- constexpr Color focusColor(0xFA, 0xFA, 0x00);
canvas.SetColor(background);
canvas.Fill();
+}
+
+void Application::RenderGrid() {
+ constexpr Color univGrid(0xEE, 0xEE, 0xEE);
+ constexpr Color secGrid(0x77, 0x77, 0x77);
canvas.Grid2(
cam.ToScreen(Vector<float>(0, 0)),
univ.secSize,
secGrid,
univGrid);
+}
+
+void Application::RenderShips() {
+ constexpr Color shipColor(0x00, 0xAA, 0xAA);
+
+ canvas.SetColor(shipColor);
+ for (const Ship &s : univ.Ships()) {
+ const Vector<float> direction = s.Dir();
+ const Vector<int> position = cam.ToScreen(s.pos);
+ const Vector<int> nose = position + Vector<int>(direction * 15.0f);
+ const Vector<int> left = position + Vector<int>((Rotate90(direction) * 8.0f) - (direction * 4.0f));
+ const Vector<int> right = position + Vector<int>((Rotate270(direction) * 8.0f) - (direction * 4.0f));
+ canvas.Line(position, nose);
+ canvas.Quad(nose, left, position, right);
+ }
+}
+
+void Application::RenderUI() {
+ constexpr Color focusColor(0xFA, 0xFA, 0x00);
+
+ autopilot.Render(canvas, cam);
+
+ linGauge.Render(canvas, controlled->linThrottle);
+ rotGauge.Render(canvas, controlled->rotThrottle);
canvas.SetColor(focusColor);
canvas.Cross(cam.ToScreen(focus.Pos()), 15);
-
- canvas.SetColor(entityColor);
- for (const Entity &e : univ.Entities()) {
- canvas.Cross(
- cam.ToScreen(Vector<float>(e.area * univ.areaSize) + e.pos),
- 10);
- }
}
}