main
Benjamin Kraft 2 years ago
parent 3a1e1ce094
commit 01fcc2ac84
  1. 2
      src/Game.cpp
  2. 2
      src/Game.h
  3. 8
      src/Window.cpp
  4. 4
      src/Window.h

@ -1,10 +1,12 @@
#include <QPainter>
#include "Game.h"
#include "InputWindow.h"
#include "Window.h"
void Game::draw(QPixmap &output) {
QPainter p(&output);
p.drawText(50, 50, QString::fromStdString(std::to_string(int(window->currentFPS))));
for (auto & spectator : spectators)
spectator.draw(p);
player.draw(p);

@ -9,10 +9,12 @@
#define GROUND_Y 400
#define SPEC_Y 150
class Window;
class Game {
Player player;
std::vector<Spectator> spectators {5};
public:
Window * window;
float eTime = 0;
static Game * instance;
static GameQueue * eventQueue;

@ -5,9 +5,9 @@ Window::Window() {
timer = new QTimer(this);
timer->setInterval(17);
connect(timer, &QTimer::timeout, this, [this]{
update();
game.update(17.f / 1000);
});
game.window = this;
timer->start();
label = new QLabel(this);
label->resize(size());
@ -18,6 +18,12 @@ void Window::paintEvent(QPaintEvent *event) {
output.fill(Qt::white);
game.draw(output);
label->setPixmap(output.scaled(label->size()));
update();
auto now = std::chrono::high_resolution_clock::now();
auto diff = duration_cast<std::chrono::nanoseconds>((now - tp));
double seconds = double(diff.count()) / 1000. / 1000. / 1000. ;
currentFPS = 1 / seconds;
tp = now;
}
void Window::resizeEvent(QResizeEvent *e) {

@ -8,11 +8,15 @@
#include "Game.h"
#include <QLabel>
using namespace std::chrono;
class Window : public InputWindow {
Game game;
QLabel * label;
QTimer * timer;
time_point<system_clock, duration<double>> tp;
public:
double currentFPS = 0;
explicit Window();
protected:
void paintEvent(QPaintEvent *) override;

Loading…
Cancel
Save