]> git.localhorst.tv Git - space.git/blobdiff - src/app/Application.cpp
added autopilot that sucks
[space.git] / src / app / Application.cpp
index 5820c57ba3eb10aeea807893f3f384a7bc5438a9..e3c6a2b878bc1bb39c4294bd632192d8ebca40df 100644 (file)
@@ -11,9 +11,13 @@ Application::Application(Canvas &c)
 , 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) {
+
 }
 
 
@@ -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<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);
 }
 
 }