From 4d448de222f3aedaaa5326c8c3089392102f4be1 Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Thu, 26 Jan 2023 10:22:35 +0100 Subject: [PATCH] spectator drawn --- src/Game.cpp | 7 ++++--- src/Spectator.cpp | 26 +++++++++++++++++++++++--- src/Spectator.h | 3 +++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Game.cpp b/src/Game.cpp index 1be76fe..8815837 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -6,7 +6,7 @@ void Game::draw(QPixmap &output) { QPainter p(&output); - + p.setRenderHint(QPainter::Antialiasing); for (auto & spectator : spectators) spectator.draw(p); @@ -37,11 +37,12 @@ void Game::removeWalls() { } Game::Game() { - constexpr size_t sCount = 10; + constexpr size_t sCount = 5; const int w = WIDTH / sCount; for (size_t i = 0; i < sCount; i++){ Spectator spec; - spec.pos = QPoint(int(i) * w, SPEC_Y / 2); + spec.pos = QPoint(int(i) * w, 0); + spec.size = QSize(w, SPEC_Y); spectators.push_back(spec); } for (auto & spec : spectators) diff --git a/src/Spectator.cpp b/src/Spectator.cpp index 2d04424..44160e7 100644 --- a/src/Spectator.cpp +++ b/src/Spectator.cpp @@ -4,11 +4,11 @@ #include "Game.h" void Spectator::OnWallJumped(WallJumpEvent *event) { - std::cout << "Wall jump at " << event->time << std::endl; + } void Spectator::OnWallCrashed(WallCrashEvent *event) { - std::cout << "Wall crash at " << event->time << std::endl; + } @@ -16,7 +16,27 @@ void Spectator::draw(QPainter &painter) const { painter.save(); painter.translate(pos); - painter.drawText(0, 0, QString("Hello")); + QSize figureSize = size / 3; + painter.translate(QPoint(figureSize.width() / 2, 0)); + int r = figureSize.width() / 2.5; + painter.drawEllipse(QPoint(0, r + 5), r, r); + int base = 2 * r + 5 + figureSize.height() / 2; + + // main + painter.drawLine(0, 2 * r + 5, 0, base); + + // arms + int armY = (2 * r + 5 + base) / 2; + painter.drawLine(0, armY, -r, armY - figureSize.height() / 3); + painter.drawLine(0, armY, r, armY - figureSize.height() / 3); + + // legs + painter.drawLine(0, base, -r, base + figureSize.height() / 2); + painter.drawLine(0, base, r, base + figureSize.height() / 2); + + painter.translate(QPoint(figureSize.width() / 2, 0)); + QSize textArea = 2 * size / 3; + painter.drawText(QRect(QPoint(), textArea), Qt::AlignCenter, QString::fromStdString(currentMessage)); painter.restore(); } diff --git a/src/Spectator.h b/src/Spectator.h index 2451ad4..43d6009 100644 --- a/src/Spectator.h +++ b/src/Spectator.h @@ -6,7 +6,10 @@ class Spectator : public GameListener { protected: void OnWallJumped(WallJumpEvent * event) override; void OnWallCrashed(WallCrashEvent * event) override; + std::string currentMessage; + public: QPoint pos; + QSize size; void draw(QPainter &painter) const; };