X-Git-Url: http://git.localhorst.tv/?p=space.git;a=blobdiff_plain;f=src%2Fapp%2FApplication.cpp;h=e3c6a2b878bc1bb39c4294bd632192d8ebca40df;hp=5820c57ba3eb10aeea807893f3f384a7bc5438a9;hb=ffd31714f3edb64ebe16b65878750c6cc5c7e884;hpb=699437a474de8b87ccb6749d44adf740e680d620 diff --git a/src/app/Application.cpp b/src/app/Application.cpp index 5820c57..e3c6a2b 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -11,9 +11,13 @@ Application::Application(Canvas &c) , univ(Vector(10, 10), Vector(10, 10), Vector(10, 10)) , focus(Vector(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) { + } @@ -30,7 +34,9 @@ void Application::Run() { void Application::Loop(int delta) { HandleEvents(); - Update(delta); + if (!paused) { + Update(delta); + } Render(); canvas.Present(); } @@ -97,6 +103,12 @@ void Application::OnKeyDown(const SDL_KeyboardEvent &e) { case SDLK_x: cam.StartShrink(); break; + case SDLK_c: + apEnabled = !apEnabled; + break; + case SDLK_p: + paused = !paused; + break; default: break; } @@ -142,8 +154,12 @@ void Application::OnKeyUp(const SDL_KeyboardEvent &e) { 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()); @@ -175,13 +191,15 @@ void Application::Render() { canvas.SetColor(entityColor); for (const Ship &s : univ.Ships()) { const Vector direction = s.Dir(); - const Vector position = cam.ToScreen(Vector(s.area * univ.areaSize) + s.pos); + const Vector position = cam.ToScreen(s.pos); const Vector nose = position + Vector(direction * 15.0f); const Vector left = position + Vector((Rotate90(direction) * 8.0f) - (direction * 4.0f)); const Vector right = position + Vector((Rotate270(direction) * 8.0f) - (direction * 4.0f)); canvas.Line(position, nose); canvas.Quad(nose, left, position, right); } + + autopilot.Render(canvas, cam); } }