diff --git a/src/main.cpp b/src/main.cpp index 8a96a61..9009309 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -37,9 +38,12 @@ int main() { Uint64 lastFrameTime = SDL_GetTicksNS(); float deltaTime = 0.0f; + + while (running) { const Uint64 frameStart = SDL_GetTicksNS(); + // Event handling SDL_Event event; while (SDL_PollEvent(&event)) { @@ -49,10 +53,10 @@ int main() { // Check specific button (e.g., left mouse button) if (event.button.button == SDL_BUTTON_LEFT) { printf("Left mouse clicked at (%.1f, %.1f)\nCamera position: (%.1f, " - "%.1f)\nTarget position: (%.1f, %.1f)\n", - event.button.x, event.button.y, camera.view.x, camera.view.y, - camera.view.x + event.button.x, - camera.view.y + event.button.y); + "%.1f)\nTarget position: (%.1f, %.1f)\n", + event.button.x, event.button.y, camera.view.x, camera.view.y, + camera.view.x + event.button.x, + camera.view.y + event.button.y); destroyer.Tposition.x = camera.view.x + event.button.x; destroyer.Tposition.y = camera.view.y + event.button.y; destroyer.gotoT = true; @@ -70,6 +74,16 @@ int main() { lastToggle = SDL_GetTicks(); } + //DEBUG + if (keystate[SDL_SCANCODE_B] && (SDL_GetTicks() - lastToggle > 200)) { + std::clog << "x: " << destroyer.position.x << " y: " << destroyer.position.y << "\n"; + } + if (keystate[SDL_SCANCODE_O] && (SDL_GetTicks() - lastToggle > 200)) { + + destroyer.position.x = 0; + destroyer.position.y = 0; + } + // Player movement int moveX = keystate[SDL_SCANCODE_RIGHT] - keystate[SDL_SCANCODE_LEFT]; int moveY = keystate[SDL_SCANCODE_DOWN] - keystate[SDL_SCANCODE_UP]; @@ -114,13 +128,15 @@ int main() { float step = destroyer.speed * deltaTime; destroyer.position.x += (float)moveX * step; destroyer.position.y += (float)moveY * step; - std::clog << "step: " << step << "\n"; if (destroyer.gotoT) { float dx = destroyer.Tposition.x - destroyer.Central_position().x; float dy = destroyer.Tposition.y - destroyer.Central_position().y; - destroyer.angle = std::atan2(dy, dx) * 180 / M_PI + 90; + if(dx != 0 && dy != 0) { + destroyer.angle = std::atan2(dy, dx) * 180 / M_PI + 90; + } + std::clog << "angle: " << destroyer.angle << "\ncalc: " << std::atan2(dy, dx) * 180 / M_PI << "\n";