, 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()))
+, autopilot(*controlled, focus.Pos())
+, apEnabled(false)
, last(SDL_GetTicks())
-, running(false) {
- controlled = univ.AddShip(Ship());
+, running(false)
+, paused(false) {
+
}
void Application::Loop(int delta) {
HandleEvents();
- Update(delta);
+ 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->rotThrottle = control.x;
- controlled->linThrottle = -control.y;
+ 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());
canvas.SetColor(entityColor);
for (const Ship &s : univ.Ships()) {
const Vector<float> direction = s.Dir();
- const Vector<int> position = cam.ToScreen(Vector<float>(s.area * univ.areaSize) + s.pos);
+ 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);
}
+
+ autopilot.Render(canvas, cam);
}
}