summaryrefslogtreecommitdiffstats
path: root/examples/bluetooth/pingpong/pingpong.h
diff options
context:
space:
mode:
authorAndreas Buhr <andreas@andreasbuhr.de>2021-03-02 15:25:19 +0100
committerAndreas Buhr <andreas@andreasbuhr.de>2021-03-05 15:21:16 +0100
commitadbeef4d07cb49fa2f4b86582dfb61b545433ecb (patch)
treeb0e3a1ee973c37990bd502f16ca44484d4ad1c02 /examples/bluetooth/pingpong/pingpong.h
parent4f3b347ac71491db7da246b728aaaf7e0c13af58 (diff)
Pingpong example: Gamelogic works on unit square
The two parties playing pingpong agreed on a screen size in the past. This patch changes the logic to work on the unit square (0,1)x(0,1). Visualization scales this up to window size. This patch also simplifies the position update loop Change-Id: Ie89b1eaa5fc14daf6b56cd42458a16ae0a923568 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'examples/bluetooth/pingpong/pingpong.h')
-rw-r--r--examples/bluetooth/pingpong/pingpong.h40
1 files changed, 15 insertions, 25 deletions
diff --git a/examples/bluetooth/pingpong/pingpong.h b/examples/bluetooth/pingpong/pingpong.h
index 315f270b..8a813005 100644
--- a/examples/bluetooth/pingpong/pingpong.h
+++ b/examples/bluetooth/pingpong/pingpong.h
@@ -81,7 +81,6 @@ public:
float leftBlockY() const;
float rightBlockY() const;
void checkBoundaries();
- void updateDirection();
bool showDialog() const;
QString message() const;
void setMessage(const QString &message);
@@ -93,7 +92,6 @@ public:
public slots:
void startGame();
void update();
- void setSize(const float &x, const float &y);
void updateBall(const float &bX, const float &bY);
void updateLeftBlock(const float &lY);
void updateRightBlock(const float &rY);
@@ -119,32 +117,24 @@ Q_SIGNALS:
void resultChanged();
private:
- QBluetoothServer *m_serverInfo;
+ QBluetoothServer *m_serverInfo = nullptr;
QBluetoothServiceInfo m_serviceInfo;
- QBluetoothSocket *socket;
- QBluetoothServiceDiscoveryAgent *discoveryAgent;
+ QBluetoothSocket *socket = nullptr;
+ QBluetoothServiceDiscoveryAgent *discoveryAgent = nullptr;
- float m_ballX;
- float m_ballY;
- float m_ballPreviousX;
- float m_ballPreviousY;
- float m_leftBlockY;
- float m_rightBlockY;
- QTimer *m_timer;
- float m_boardWidth;
- float m_boardHeight;
- float m_direction;
- float m_targetX;
- float m_targetY;
- int interval;
- int m_resultLeft;
- int m_resultRight;
- bool m_showDialog;
+ float m_ballX = 0.5f;
+ float m_ballY = 0.9f;
+ float m_leftBlockY = 0.4f;
+ float m_rightBlockY = 0.4f;
+ QTimer *m_timer = nullptr;
+ float m_speedy = 0.002f;
+ float m_speedx = 0.002f;
+ int m_resultLeft = 0;
+ int m_resultRight = 0;
+ bool m_showDialog = false;
QString m_message;
- int m_role;
- float m_proportionX;
- float m_proportionY;
- bool m_serviceFound;
+ int m_role = 0;
+ bool m_serviceFound = false;
};
#endif // PINGPONG_H