Skip to content

Commit

Permalink
Ported ballcatch activity
Browse files Browse the repository at this point in the history
  • Loading branch information
petitlapin authored and bdoin committed Feb 16, 2014
1 parent 8e3fde5 commit 3c80eb0
Show file tree
Hide file tree
Showing 25 changed files with 2,650 additions and 51 deletions.
1 change: 1 addition & 0 deletions GCompris.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include(src/core/core.pri)
include(src/activities/menu/menu.pri)

# Activity Includes
include(src/activities/ballcatch/ballcatch.pri)
include(src/activities/clickgame/clickgame.pri)
include(src/activities/colors/colors.pri)
include(src/activities/erase/erase.pri)
Expand Down
1 change: 1 addition & 0 deletions src/activities/activities.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# The list of activities that will be loaded at GCompris start.
# Keep it sorted
ballcatch
clickgame
colors
erase
Expand Down
36 changes: 36 additions & 0 deletions src/activities/ballcatch/ActivityInfo.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* gcompris - ActivityInfo.qml
Copyright (C)
2003, 2014: Bruno Coudoin: initial version
2014: Johnny Jazeix: Qt port
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
import GCompris 1.0

ActivityInfo {
name: "ballcatch/Ballcatch.qml"
difficulty: 1
icon: "ballcatch/ballcatch.svg"
author: "Johnny Jazeix <jazeix@gmail.com>"
demo: false
title: qsTr("Make the ball go to Tux")
description: qsTr("Press the two shift keys at the same time, to make the
ball go in a straight line.")
goal: ""
prerequisite: ""
manual: qsTr("Press the two shift keys at the same time,
to make the ball go in a straight line.")
credit: ""
}
96 changes: 96 additions & 0 deletions src/activities/ballcatch/Ball.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* gcompris - Ball.qml
Copyright (C)
2003, 2014: Bruno Coudoin: initial version
2014: Johnny Jazeix: Qt port
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.1
import QtMultimedia 5.0
import "ballcatch.js" as Activity
import GCompris 1.0

Item {
readonly property int initRadius: 130

// If won, ball goes on tux, if loose, depends on the side clicked first
property int finishX

readonly property int finishY: tux.y+tux.height/2
readonly property int finishRadius: initRadius/3

property int radius: initRadius

z: 3

Image {
id: circle
source: "qrc:/gcompris/src/activities/ballcatch/resource/ball.svg"
width: radius
height: width
}

ParallelAnimation {
id: animation

running: false

NumberAnimation { target: ball; property: "x";
to: ball.finishX; duration: 1000 }
NumberAnimation { target: ball; property: "y";
to: ball.finishY; duration: 1000 }
NumberAnimation { target: circle; property: "width";
to: ball.finishRadius; duration: 1000 }
NumberAnimation { target: circle; property: "rotation";
to: 360; duration: 1000 }

onStopped: {
// We are done with the ballon move
if(gameWon) {
// This is a win
background.playSound("tuxok")
bonus.good("tux")
}
else {
// This is a loose
background.playSound("youcannot")
bonus.bad("tux")
}
}
}

function startAnimation() {
if(gameWon) {
finishX = tux.x+tux.width/2-ball.finishRadius/2
}
else if(activity.leftPressed) {
finishX = ball.finishRadius
}
else {
finishX = background.width - 2*ball.finishRadius
}
/* Only start the timer if the game is at init state.
In init state, radius is initRadius */
if(ball.radius == ball.initRadius)
animation.start()
}

function reinitBall() {
x = background.width / 2 - 65;
y = leftHand.y;
circle.width = initRadius;
circle.rotation = 0;
}
}
Loading

0 comments on commit 3c80eb0

Please sign in to comment.