diff options
author | Andreas Buhr <andreas@andreasbuhr.de> | 2021-03-02 15:25:19 +0100 |
---|---|---|
committer | Andreas Buhr <andreas@andreasbuhr.de> | 2021-03-05 15:21:16 +0100 |
commit | adbeef4d07cb49fa2f4b86582dfb61b545433ecb (patch) | |
tree | b0e3a1ee973c37990bd502f16ca44484d4ad1c02 /examples/bluetooth/pingpong/assets | |
parent | 4f3b347ac71491db7da246b728aaaf7e0c13af58 (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/assets')
-rw-r--r-- | examples/bluetooth/pingpong/assets/Board.qml | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/examples/bluetooth/pingpong/assets/Board.qml b/examples/bluetooth/pingpong/assets/Board.qml index 4409d2e6..ff29bceb 100644 --- a/examples/bluetooth/pingpong/assets/Board.qml +++ b/examples/bluetooth/pingpong/assets/Board.qml @@ -144,8 +144,8 @@ Rectangle { height: leftblock.width radius: width/2 color: "#363636" - x: pingPong.ballX - y: pingPong.ballY + x: pingPong.ballX * scaleFactor + y: pingPong.ballY * scaleFactor } } @@ -175,23 +175,20 @@ Rectangle { } property double leftBlockY: leftblock.y - onLeftBlockYChanged: pingPong.updateLeftBlock(leftblock.y) + onLeftBlockYChanged: pingPong.updateLeftBlock(leftblock.y / scaleFactor) property double leftBlockUpdate: pingPong.leftBlockY - onLeftBlockUpdateChanged: leftblock.y = pingPong.leftBlockY + onLeftBlockUpdateChanged: leftblock.y = pingPong.leftBlockY * scaleFactor property double rightBlockY: rightblock.y - onRightBlockYChanged: pingPong.updateRightBlock(rightblock.y) + onRightBlockYChanged: pingPong.updateRightBlock(rightblock.y / scaleFactor) property double rightBlockUpdate: pingPong.rightBlockY - onRightBlockUpdateChanged: rightblock.y = pingPong.rightBlockY + onRightBlockUpdateChanged: rightblock.y = pingPong.rightBlockY * scaleFactor + Component.onCompleted: { - if (menulist.height == Screen.height && menulist.width == Screen.width) - pingPong.setSize(Screen.width, Screen.height) - else - pingPong.setSize(board.width, board.height) - pingPong.updateLeftBlock(leftblock.y) - pingPong.updateRightBlock(rightblock.y) + pingPong.updateLeftBlock(leftblock.y / scaleFactor) + pingPong.updateRightBlock(rightblock.y / scaleFactor) } } |