Warning, /education/gcompris/src/activities/gnumch-equality/Fraidy.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - Fraidy.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 // Fraidy is an afraid monster. He won't go in the center but he'll
0014 // stay close to the border.
0015 Monster {
0016     id: fraidy
0017 
0018     property int firstDirection
0019 
0020     function setFirstDirection() {
0021         var firstDir = direction
0022         firstDirection = firstDir
0023     }
0024 
0025     monsterType: "fraidy"
0026     frames: 3
0027 
0028     onMovingOnChanged: {
0029         // He will either follow the border or go outside.
0030         if (movingOn == false) {
0031             if (Math.random() > 0.5) {
0032                 // He will go outside in this case.
0033                 if (firstDirection % 2 == 0) {
0034                     direction = firstDirection + 1
0035                 } else {
0036                     direction = firstDirection - 1
0037                 }
0038             }
0039         }
0040     }
0041 
0042     onOpacityChanged: {
0043         // When fraidy appear, he will not go straight but follow the border or go outside.
0044         if (opacity == 1) {
0045             direction = (direction + Math.pow(-1, Math.floor(Math.random()*2))) % 4
0046             if (direction < 0)
0047                 direction = 3
0048         }
0049     }
0050 
0051     Component.onCompleted: setFirstDirection()
0052 }