parent
4a98d250d7
commit
20e5edb82c
12 changed files with 113 additions and 9 deletions
@ -0,0 +1,28 @@ |
|||||||
|
#include "Coin.h" |
||||||
|
#include "Game.h" |
||||||
|
|
||||||
|
void Coin::draw(QPainter &painter) const { |
||||||
|
painter.save(); |
||||||
|
|
||||||
|
painter.translate(pos); |
||||||
|
painter.setBrush(QBrush(Qt::yellow, Qt::SolidPattern)); |
||||||
|
painter.drawEllipse(QPoint(), radius, radius); |
||||||
|
|
||||||
|
painter.drawText(QRect(-radius, -radius, radius * 2, radius * 2), Qt::AlignCenter, QString::fromStdString(std::to_string(value))); |
||||||
|
|
||||||
|
painter.restore(); |
||||||
|
} |
||||||
|
|
||||||
|
bool Coin::isLost() const { |
||||||
|
return pos.x() < -100; |
||||||
|
} |
||||||
|
|
||||||
|
Coin::Coin() { |
||||||
|
int y = int(Game::Random(SPEC_Y, GROUND_Y)); |
||||||
|
pos = {WIDTH, y}; |
||||||
|
value = int(Game::Random(30, 37)); |
||||||
|
} |
||||||
|
|
||||||
|
void Coin::update(float dTime) { |
||||||
|
pos.setX(float(pos.x()) - velocity * dTime); |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <QPainter> |
||||||
|
|
||||||
|
class Coin { |
||||||
|
public: |
||||||
|
explicit Coin(); |
||||||
|
bool collected = false; |
||||||
|
QPoint pos; |
||||||
|
float velocity = 150; |
||||||
|
int value; |
||||||
|
int radius = 15; |
||||||
|
bool isLost() const; |
||||||
|
void draw(QPainter &painter) const; |
||||||
|
void update(float dTime); |
||||||
|
}; |
Loading…
Reference in new issue