Skip to content

Commit

Permalink
woring game with fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kiltum committed Sep 30, 2018
1 parent 9a154df commit 3112abc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pingpong/PingPong/Ball.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import QtMultimedia 5.8
Item {
id: mainBall
property bool run: true
property int speed: 10
property int speed: 1
property bool mute: false
property int velocityX: -speed
property int velocityY: -speed
Expand All @@ -28,7 +28,7 @@ Item {

Timer {
running: parent.run
interval: 50
interval: 40
repeat: true
onTriggered: {
parent.x = parent.x + velocityX
Expand Down
17 changes: 13 additions & 4 deletions pingpong/PingPong/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Window {

property int ballX: main.width/2
property int ballY: main.height/2
property int ballSize: 10
property int ballSize: 30
property int ballSpeed: 10
property int racketY: 30
property int racketX: pole.width - 30
property int racketSize: 150
Expand All @@ -34,6 +35,7 @@ Window {
x: ballX
y: ballY
size: ballSize
speed: ballSpeed
onMoved: {
ballX = x
ballY = y
Expand All @@ -58,14 +60,19 @@ Window {
}

function checkCollide() {
if((ballX + ballSize) >= racketX) { // no need to check if ball far left from racket
if((ballY + ballSize) >= racketY) { // ball below top corner of rocket
if((ballY + ballSize) <= racketY+racketSize) {
if((ballX + ball.size/2) >= racketX) { // no need to check if ball far left from racket
if((ballY + ball.size/2) >= racketY) { // ball below top corner of rocket
if((ballY + ball.size/2) <= racketY+racket.size) {
if (!main.mute) {
rocketHit.play()
}
ball.x = racketX - ball.size/2
main.score = main.score + 1
ball.velocityX = -ball.speed
if(ball.size > 10) {
ball.size=ball.size-1
ball.speed=ball.speed+1
}
}
else {
fail()
Expand Down Expand Up @@ -122,6 +129,8 @@ Window {
main.score=0
ball.x=main.width/2
ball.x=main.height/2
ball.speed=ballSpeed
ball.size=ballSize
}
}
}
Expand Down

0 comments on commit 3112abc

Please sign in to comment.