Warning, /education/gcompris/src/activities/gnumch-equality/Monster.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - Monster.qml
0002 *
0003 * SPDX-FileCopyrightText: 2014 Manuel Tondeur <manueltondeur@gmail.com>
0004 *
0005 * Authors:
0006 * Joe Neeman (spuzzzzzzz@gmail.com) (GTK+ version)
0007 * Manuel Tondeur <manueltondeur@gmail.com> (Qt Quick port)
0008 *
0009 * SPDX-License-Identifier: GPL-3.0-or-later
0010 */
0011 import QtQuick 2.12
0012
0013 import "gnumch-equality.js" as Activity
0014
0015 Creature {
0016 id: monster
0017
0018 property int direction
0019 property var player
0020
0021 signal stop
0022
0023 Component.onCompleted: {
0024 activity.stop.connect(stop);
0025 }
0026
0027 onStop: {
0028 timerMove.stop();
0029 }
0030
0031 function checkCell() {
0032 if (index === player.index && player.movable) {
0033 player.getCaught(-1)
0034 eating = true
0035 }
0036
0037 if (monsters.checkOtherMonster(index)) {
0038 eating = true
0039 }
0040 }
0041
0042 opacity: 0
0043
0044 onMovingOnChanged: {
0045 if (movingOn == false) {
0046 checkCell()
0047 }
0048 }
0049
0050 onOpacityChanged: {
0051 if (opacity == 1) {
0052 checkCell()
0053 }
0054 }
0055
0056 Timer {
0057 id: timerMove
0058 interval: 2000
0059 running: true
0060 repeat: true
0061
0062 onTriggered: {
0063 if (!moveTo(direction)) {
0064 var vertical = Math.floor(direction/2)
0065 var sign = Math.pow(-1,(direction))
0066 y = y + sign * grid.cellHeight * vertical
0067 x = x - sign * grid.cellWidth * (vertical - 1)
0068 opacity = 0
0069 }
0070
0071 }
0072 }
0073
0074 Behavior on opacity {
0075 NumberAnimation {
0076 id: animationEnd
0077 duration: 500
0078
0079 onRunningChanged: {
0080 if (!animationEnd.running && monster.opacity == 0) {
0081 monster.destroy()
0082 }
0083 }
0084 }
0085 }
0086 }