spectator drawn

main
Benjamin Kraft 2 years ago
parent cc27b166e1
commit 4d448de222
  1. 7
      src/Game.cpp
  2. 26
      src/Spectator.cpp
  3. 3
      src/Spectator.h

@ -6,7 +6,7 @@
void Game::draw(QPixmap &output) { void Game::draw(QPixmap &output) {
QPainter p(&output); QPainter p(&output);
p.setRenderHint(QPainter::Antialiasing);
for (auto & spectator : spectators) for (auto & spectator : spectators)
spectator.draw(p); spectator.draw(p);
@ -37,11 +37,12 @@ void Game::removeWalls() {
} }
Game::Game() { Game::Game() {
constexpr size_t sCount = 10; constexpr size_t sCount = 5;
const int w = WIDTH / sCount; const int w = WIDTH / sCount;
for (size_t i = 0; i < sCount; i++){ for (size_t i = 0; i < sCount; i++){
Spectator spec; 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); spectators.push_back(spec);
} }
for (auto & spec : spectators) for (auto & spec : spectators)

@ -4,11 +4,11 @@
#include "Game.h" #include "Game.h"
void Spectator::OnWallJumped(WallJumpEvent *event) { void Spectator::OnWallJumped(WallJumpEvent *event) {
std::cout << "Wall jump at " << event->time << std::endl;
} }
void Spectator::OnWallCrashed(WallCrashEvent *event) { 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.save();
painter.translate(pos); 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(); painter.restore();
} }

@ -6,7 +6,10 @@ class Spectator : public GameListener {
protected: protected:
void OnWallJumped(WallJumpEvent * event) override; void OnWallJumped(WallJumpEvent * event) override;
void OnWallCrashed(WallCrashEvent * event) override; void OnWallCrashed(WallCrashEvent * event) override;
std::string currentMessage;
public: public:
QPoint pos; QPoint pos;
QSize size;
void draw(QPainter &painter) const; void draw(QPainter &painter) const;
}; };

Loading…
Cancel
Save