From dd4edc5643725bfbe76dce6f9311a00ae1babc11 Mon Sep 17 00:00:00 2001 From: TurnMeOn Date: Tue, 19 Dec 2017 19:41:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E9=AB=98=E5=9D=90=E6=A0=87=E7=B2=BE?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cars.cpp | 18 +++++++++--------- cars.h | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cars.cpp b/cars.cpp index acc545a..eb7893d 100644 --- a/cars.cpp +++ b/cars.cpp @@ -27,32 +27,32 @@ Cars::Cars(QGraphicsItem *parent, int dir, Cars::Color color) : QGraphicsPixmapI setTransformOriginPoint(M_WID/2, M_LEN/2); //设置旋转中心 } -void Cars::Forward(int vel) +void Cars::Forward(qreal vel) { - double ang = qDegreesToRadians(rotation()); + qreal ang = qDegreesToRadians(rotation()); this->moveBy(+vel*qSin(ang), -vel*qCos(ang)); } -void Cars::Backward(int vel) +void Cars::Backward(qreal vel) { - double ang = qDegreesToRadians(rotation()); + qreal ang = qDegreesToRadians(rotation()); this->moveBy(-vel*qSin(ang), +vel*qCos(ang)); } -void Cars::moveLeft(int vel) +void Cars::moveLeft(qreal vel) { - double ang = qDegreesToRadians(rotation()); + qreal ang = qDegreesToRadians(rotation()); moveBy(-vel*qCos(ang), -vel*qSin(ang)); } -void Cars::moveRight(int vel) +void Cars::moveRight(qreal vel) { - double ang = qDegreesToRadians(rotation()); + qreal ang = qDegreesToRadians(rotation()); moveBy(vel*qCos(ang), vel*qSin(ang)); } //ang为旋转角度(弧度),正数为顺时针,负数逆时针 -void Cars::Rotate(int ang) +void Cars::Rotate(qreal ang) { setRotation(rotation() + ang); } diff --git a/cars.h b/cars.h index 2125755..b861d90 100644 --- a/cars.h +++ b/cars.h @@ -16,11 +16,11 @@ class Cars : public QGraphicsPixmapItem public: enum Color { Pink, Red, Yellow, RANDOM }; explicit Cars(QGraphicsItem *parent = Q_NULLPTR, int dir = 0, Cars::Color color = RANDOM); - void Forward(int vel = 3); - void Backward(int vel = 3); - void moveLeft(int vel = 3); - void moveRight(int vel = 3); - void Rotate(int ang = 30); + void Forward(qreal vel = 3); + void Backward(qreal vel = 3); + void moveLeft(qreal vel = 3); + void moveRight(qreal vel = 3); + void Rotate(qreal ang = 30); void turnLeft(int r, int ang); void turnRight(int r, int ang);