diff --git a/src/activities/target/TargetItem.qml b/src/activities/target/TargetItem.qml index 0d721426a..65babd32b 100644 --- a/src/activities/target/TargetItem.qml +++ b/src/activities/target/TargetItem.qml @@ -1,159 +1,160 @@ /* GCompris - TargetItem.qml * * Copyright (C) 2014 Bruno coudoin * * Authors: * Bruno Coudoin (GTK+ version) * Bruno Coudoin (Qt Quick 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 . */ import QtQuick 2.6 import GCompris 1.0 import "../../core" import "target.js" as Activity Image { id: targetItem fillMode: Image.PreserveAspectCrop source: Activity.url + "target_background.svg" width: parent.width * zoom height: parent.height * zoom sourceSize.width: Math.max(parent.width, parent.height) * zoom anchors.centerIn: parent property int zoom: 2 property alias model: targetModel property bool stopMe: false property var scores: [] property string scoreText property int scoreTotal signal start signal stop signal attachArrow(Item arrow) onStart: { scores = [] scoreText = "" scoreTotal = 0 stopMe = false targetItem.anchors.horizontalCenterOffset = getRandomOffset(0) targetItem.anchors.verticalCenterOffset = getRandomOffset(0) } onStop: { stopMe = true targetItem.anchors.horizontalCenterOffset = 0 targetItem.anchors.verticalCenterOffset = 0 } // Avoid taking the same value or the animation won't restart function getRandomOffset(oldValue) { if(oldValue != 0 && Math.random() < 0.5) return 0 var maxSize = targetModel.get(0).size * ApplicationInfo.ratio do { var newValue = Math.floor(Math.random() * maxSize) - maxSize / 2 } while(oldValue == newValue) return newValue } onAttachArrow: { arrow.anchors.centerIn = undefined var coordArrow = parent.mapToItem(targetItem, arrow.x, arrow.y) arrow.parent = targetItem arrow.x = coordArrow.x arrow.y = coordArrow.y var arrowCenterX = arrow.x + arrow.width / 2 var arrowCenterY = arrow.y + arrow.height / 2 var centerX = targetItem.width / 2 var centerY = targetItem.height / 2 // Calc the arrow score var dist = Math.sqrt(Math.pow(arrowCenterX - centerX, 2) + Math.pow(arrowCenterY - centerY, 2)) dist *= zoom / ApplicationInfo.ratio var score = 0 for(var i = targetModel.count - 1; i >= 0; --i) { if(dist < targetModel.get(i).size) { score = targetModel.get(i).score break } } scores.push(score) scoreTotal += score scoreText = scores.join(" + ") parent.targetReached() } Behavior on anchors.horizontalCenterOffset { id: horizontal NumberAnimation { id: anim1 duration: 3000 easing.type: Easing.InOutQuad onRunningChanged: { if(!anim1.running) { var newValue = getRandomOffset(targetItem.anchors.horizontalCenterOffset) if(!stopMe) targetItem.anchors.horizontalCenterOffset = newValue } } } } Behavior on anchors.verticalCenterOffset { id: vertical NumberAnimation { id: anim2 duration: 3000 easing.type: Easing.InOutQuad onRunningChanged: { if(!anim2.running) { var newValue = getRandomOffset(targetItem.anchors.verticalCenterOffset) if(!stopMe) targetItem.anchors.verticalCenterOffset = newValue } } } } ListModel { id: targetModel } Repeater { id: repeater model: targetModel Rectangle { anchors.centerIn: targetItem width: size * ApplicationInfo.ratio height: size * ApplicationInfo.ratio color: model.color radius: width / 2 border.width: 1 * ApplicationInfo.ratio - border.color: "black" + border.color: "#40000000" GCText { anchors.horizontalCenter: parent.horizontalCenter anchors.bottom: parent.bottom text: score + color: "#A0000000" } } } } diff --git a/src/activities/target/target.js b/src/activities/target/target.js index 329abbe3f..8f16cbd96 100644 --- a/src/activities/target/target.js +++ b/src/activities/target/target.js @@ -1,152 +1,152 @@ /* GCompris - target.js * * Copyright (C) 2014 Bruno coudoin * * Authors: * Bruno Coudoin (GTK+ version) * Bruno Coudoin (Qt Quick 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 . */ .pragma library .import QtQuick 2.6 as Quick var url = "qrc:/gcompris/src/activities/target/resource/" var colors = [ - "#ff1b00", - "#7edee2", - "#f1f500", - "#3dff00", - "#b7d2d4", - "#6db5ba" + "#ee7f7f", + "#eebf7f", + "#e0ee7f", + "#7fee8f", + "#7fcbee", + "#b8c8f6" ] var levels = [ [ {size: 50, color: colors[0], score: 5}, {size: 100, color: colors[1], score: 4}, {size: 150, color: colors[2], score: 3}, {size: 200, color: colors[3], score: 2}, {size: 250, color: colors[4], score: 1} ], [ {size: 50, color: colors[0], score: 10}, {size: 100, color: colors[1], score: 5}, {size: 150, color: colors[2], score: 3}, {size: 200, color: colors[3], score: 2}, {size: 250, color: colors[4], score: 1} ], [ {size: 50, color: colors[0], score: 20}, {size: 100, color: colors[1], score: 10}, {size: 150, color: colors[2], score: 8}, {size: 200, color: colors[3], score: 5}, {size: 250, color: colors[4], score: 3}, {size: 300, color: colors[5], score: 2} ], [ {size: 50, color: colors[0], score: 30}, {size: 100, color: colors[1], score: 20}, {size: 150, color: colors[2], score: 10}, {size: 200, color: colors[3], score: 5}, {size: 250, color: colors[4], score: 3}, {size: 300, color: colors[5], score: 2} ], [ {size: 50, color: colors[0], score: 50}, {size: 100, color: colors[1], score: 30}, {size: 150, color: colors[2], score: 20}, {size: 200, color: colors[3], score: 8}, {size: 250, color: colors[4], score: 3}, {size: 300, color: colors[5], score: 2} ], [ {size: 50, color: colors[0], score: 100}, {size: 100, color: colors[1], score: 50}, {size: 150, color: colors[2], score: 12}, {size: 200, color: colors[3], score: 8}, {size: 250, color: colors[4], score: 3}, {size: 300, color: colors[5], score: 2} ], [ {size: 50, color: colors[0], score: 500}, {size: 100, color: colors[1], score: 100}, {size: 150, color: colors[2], score: 50}, {size: 200, color: colors[3], score: 15}, {size: 250, color: colors[4], score: 7}, {size: 300, color: colors[5], score: 3} ], [ {size: 50, color: colors[0], score: 64}, {size: 100, color: colors[1], score: 32}, {size: 150, color: colors[2], score: 16}, {size: 200, color: colors[3], score: 8}, {size: 250, color: colors[4], score: 4}, {size: 300, color: colors[5], score: 2} ] ] var currentLevel = 0 var numberOfLevel = levels.length var items function start(items_) { items = items_ currentLevel = 0 items.currentSubLevel = 0 items.numberOfSubLevel = 5 initLevel() } function stop() { } function initLevel() { items.bar.level = currentLevel + 1 items.targetModel.clear() items.arrowFlying = false for(var i = levels[currentLevel].length - 1; i >= 0 ; --i) { items.targetModel.append(levels[currentLevel][i]) } // Reset the arrows first items.nbArrow = 0 items.nbArrow = Math.min(currentLevel + 3, 6) items.targetItem.start() items.userEntry.text = "" } function nextSubLevel() { if(items.numberOfSubLevel <= ++items.currentSubLevel ) { nextLevel() } else { initLevel(); } } function nextLevel() { items.currentSubLevel = 0 if(numberOfLevel <= ++currentLevel ) { currentLevel = 0 } initLevel(); } function previousLevel() { items.currentSubLevel = 0 if(--currentLevel < 0) { currentLevel = numberOfLevel - 1 } initLevel(); }