Загрузка данных


#include <iostream>
#include "string"
#include <chrono>
#include <thread>
#include <atomic>
#include <windows.h>

using namespace std;

atomic<int> frameCount(0);
atomic<int> currentFPS(0);

void timerFunction() {
    while (true) {
        std::this_thread::sleep_for(std::chrono::seconds(1));
        currentFPS = frameCount.load();
        frameCount = 0;
    }
}

int main()
{
    int delay = 10;
    float speed = 4;
    float s = 1.5f;
    float x, y;
    float vx, vy;
    vy = vx = 0;
    x = y = 0;
    int w, h;
    h = 60; w = 200;
    string output;
    const int keys[] = { 'W', 'A', 'S', 'D', VK_ESCAPE };

    std::thread t(timerFunction);
    t.detach();

    while (true) {
        frameCount++;

        for (int key : keys) {
            if (GetAsyncKeyState(key) & 0x8000) { // Если клавиша зажата

                switch (key) {
                case 'W':
                    vy-=speed;
                    break;
                case 'A':
                    vx-=speed;
                    break;
                case 'S':
                    vy+=speed;
                    break;
                case 'D':
                    vx+=speed;
                    break;
                case VK_ESCAPE:
                    std::cout << "Escape..." << std::endl;
                    return 0;
                }
            }
        }

        vx /= s;
        vy /= s;

        x += vx;
        y += vy;
        
        if (x > w) {
            x = 0;
        }
        else if (x < 0) {
            x = w;
        }

        if (y > h) {
            y = 0;
        }
        else if (y < 0) {
            y = h;
        }

        for (int i = 0; i < h; i++) {
            if (int(y) == i) {
                output.append(string(int(x), ' ') + '#' + string(w - int(x), ' '));
            }
            else {
                output.append(string(w, ' '));
            }
            output.append("\n");
        }
        output.append("FPS: " + to_string(currentFPS.load()) + "\n" + "vx: " + to_string(vx) + " vy: " + to_string(vy));
        cout << output;
        output = "";

        std::this_thread::sleep_for(std::chrono::milliseconds(delay));

        system("cls");
    }
}