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

0001 /* GCompris - Smarty.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 // Smarty is smart enough to follow the muncher. So he will go after him.
0014 Monster {
0015     id: smarty
0016 
0017     frames: 3
0018 
0019     function goAfterMuncher() {
0020         // Number of cells between muncher and smarty.
0021         var horizontalCells = muncher.index % 6 - index % 6
0022         var verticalCells = ((muncher.index - muncher.index % 6) / 6) - ((index - index % 6) / 6)
0023 
0024         if (horizontalCells == 0 && verticalCells == 0)
0025             return
0026 
0027         if ( Math.abs(horizontalCells) >= Math.abs(verticalCells)) {
0028             direction = 0.5 - (horizontalCells / Math.abs(horizontalCells))/2
0029         } else {
0030             direction = 2.5 - (verticalCells / Math.abs(verticalCells))/2
0031         }
0032     }
0033 
0034     monsterType: "smarty"
0035 
0036     onMovingOnChanged: {
0037         if (movingOn == false) {
0038             goAfterMuncher()
0039         }
0040     }
0041 }