Warning, /education/gcompris/src/activities/submarine/Whale.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - Whale.qml 0002 * 0003 * SPDX-FileCopyrightText: 2017 RUDRA NIL BASU <rudra.nil.basu.1996@gmail.com> 0004 * 0005 * Authors: 0006 * Pascal Georges <pascal.georges1@free.fr> (GTK+ version) 0007 * Rudra Nil Basu <rudra.nil.basu.1996@gmail.com> (Qt Quick port) 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 import QtQuick 2.12 0012 import QtQuick.Particles 2.12 0013 import Box2D 2.0 0014 import QtGraphicalEffects 1.0 0015 import GCompris 1.0 0016 0017 Image { 0018 id: whale 0019 source: isHit ? url + "whale-hit.svg" : url + "whale.svg" 0020 0021 width: submarineImage.width * 1.2 0022 sourceSize.width: whale.width 0023 fillMode: Image.PreserveAspectFit 0024 0025 property bool isHit: false 0026 0027 function hit() { 0028 isHit = true 0029 } 0030 0031 function reset() { 0032 isHit = false 0033 x = rightLimit 0034 } 0035 0036 property bool movingLeft: true 0037 property real leftLimit 0038 property real rightLimit 0039 0040 transform: Rotation { 0041 id: rotate; 0042 origin.x: whale.width / 2; 0043 origin.y: 0; 0044 axis { x: 0; y: 1; z: 0 } angle: 0 0045 } 0046 0047 SequentialAnimation { 0048 id: rotateLeftAnimation 0049 loops: 1 0050 PropertyAnimation { 0051 target: rotate 0052 properties: "angle" 0053 from: 0 0054 to: 180 0055 duration: 500 0056 } 0057 } 0058 0059 SequentialAnimation { 0060 id: rotateRightAnimation 0061 loops: 1 0062 PropertyAnimation { 0063 target: rotate 0064 properties: "angle" 0065 from: 180 0066 to: 0 0067 duration: 500 0068 } 0069 } 0070 0071 onXChanged: { 0072 if (x <= leftLimit) { 0073 rotateLeftAnimation.start() 0074 whale.movingLeft = false 0075 } else if (x >= rightLimit) { 0076 rotateRightAnimation.start() 0077 whale.movingLeft = true 0078 } 0079 } 0080 0081 Loader { 0082 id: bubbleEffect 0083 anchors.fill: parent 0084 active: ApplicationInfo.hasShader 0085 sourceComponent: ParticleSystem { 0086 anchors.fill: parent 0087 Emitter { 0088 x: parent.x 0089 y: parent.y + parent.height / 2 0090 width: 1 0091 height: 1 0092 emitRate: 0.5 0093 lifeSpan: 1000 0094 lifeSpanVariation: 2500 0095 acceleration: PointDirection { 0096 x: -10 0097 xVariation: 10 0098 y: -20 0099 yVariation: 10 0100 } 0101 velocity: PointDirection { 0102 x: 20 0103 xVariation: 10 0104 y: -20 0105 yVariation: 10 0106 } 0107 size: 12 0108 sizeVariation: 8 0109 } 0110 0111 ImageParticle { 0112 source: "qrc:/gcompris/src/activities/clickgame/resource/bubble.svg" 0113 } 0114 } 0115 } 0116 0117 Body { 0118 target: whale 0119 bodyType: Body.Dynamic 0120 sleepingAllowed: true 0121 fixedRotation: true 0122 linearDamping: 0 0123 linearVelocity: isHit ? Qt.point(0,0) : Qt.point( (whale.movingLeft ? -1 : 1) , 0) 0124 0125 fixtures: Box { 0126 width: whale.width * 0.7 0127 height: whale.height * 0.8 0128 y: whale.height * 0.1 0129 categories: items.whaleCategory 0130 collidesWith: whale.visible ? items.submarineCategory : Fixture.None 0131 density: 1 0132 friction: 0 0133 restitution: 0 0134 } 0135 } 0136 }