diff options
author | Juha Vuolle <juha.vuolle@qt.io> | 2023-02-17 12:11:02 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-02-22 06:53:36 +0000 |
commit | 1020acd025110385807b7e77f21e9a636b3a5e41 (patch) | |
tree | 8a731bc8385bb5106464a104ef91313d253ffb9e | |
parent | cfa3af090e9f48526a387bd00df2dc69019a4de3 (diff) | |
download | qtsensors-1020acd025110385807b7e77f21e9a636b3a5e41.tar.gz |
Remove sensors maze example
The Maze (QML) example is a nice game implementation, but doesn't add
much demonstration value in comparison to sensorsshowcase example.
The one unique thing it does demonstrate is tilt sensor. Tiltsensor can
be added to the sensorsshowcase too; but OTOH tilt is in some sense
just 'a' sensor among the sensors, and there is probably no need to use
all of them in the examples.
Task-number: QTBUG-110939
Change-Id: I2fd997750b05b3962428955a2929e149af6b72bd
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
(cherry picked from commit c908718f86dd409f0f2d3757057d797b2f5ff83a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
26 files changed, 0 insertions, 923 deletions
diff --git a/examples/sensors/CMakeLists.txt b/examples/sensors/CMakeLists.txt index 69582c3..9bc7056 100644 --- a/examples/sensors/CMakeLists.txt +++ b/examples/sensors/CMakeLists.txt @@ -3,7 +3,6 @@ if(TARGET Qt::Quick) qt_internal_add_example(grue) - qt_internal_add_example(maze) qt_internal_add_example(qmlqtsensors) qt_internal_add_example(sensor_explorer) if(TARGET Qt::Svg) diff --git a/examples/sensors/maze/CMakeLists.txt b/examples/sensors/maze/CMakeLists.txt deleted file mode 100644 index 258291c..0000000 --- a/examples/sensors/maze/CMakeLists.txt +++ /dev/null @@ -1,77 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(maze LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sensors/maze") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Sensors) - -qt_add_executable(maze - main.cpp -) - -set_target_properties(maze PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -if(ANDROID) - set_property(TARGET maze PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR - ${CMAKE_CURRENT_SOURCE_DIR}/android) - endif() -if(APPLE) - if(IOS) - set_property(TARGET maze PROPERTY - MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist" - ) - endif() -endif() - -target_link_libraries(maze PUBLIC - Qt::Core - Qt::Gui - Qt::Quick - Qt::Sensors -) - -# Resources: -set(maze_resource_files - "Congratulation.qml" - "LabyrinthSquare.qml" - "Mouse.qml" - "components/ApplicationWindow.qml" - "components/Button.qml" - "components/images/button_background_disabled.png" - "components/images/button_background_normal.png" - "components/images/button_background_pressed.png" - "content/00.png" - "content/01.png" - "content/cheese.png" - "content/cheeseeating.gif" - "content/congratulations.gif" - "content/mouse_down.gif" - "content/start.png" - "lib.js" - "maze.qml" -) - -qt6_add_resources(maze "maze" - PREFIX - "/" - FILES - ${maze_resource_files} -) - -install(TARGETS maze - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/sensors/maze/Congratulation.qml b/examples/sensors/maze/Congratulation.qml deleted file mode 100644 index a1e54ad..0000000 --- a/examples/sensors/maze/Congratulation.qml +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -//Import the declarative plugins -import QtQuick - -//Import the javascript functions for this game -import "lib.js" as Lib - -//Implementation of the Congratulation control -Item { - x: Lib.cellDimension - y: Lib.cellDimension - width: Lib.cellDimension * (Lib.dimension - 2) - height: Lib.cellDimension * (Lib.dimension - 2) - - //Containing a animated gif image - AnimatedImage { - id: img - anchors.fill: parent - visible: true - source: "content/congratulations.gif" - } -} diff --git a/examples/sensors/maze/Info.plist b/examples/sensors/maze/Info.plist deleted file mode 100644 index 2458247..0000000 --- a/examples/sensors/maze/Info.plist +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> -<plist version="1.0"> -<dict> - <key>CFBundleDisplayName</key> - <string>maze</string> - <key>CFBundleExecutable</key> - <string>maze</string> - <key>CFBundleGetInfoString</key> - <string>Created by Qt/QMake</string> - <key>CFBundleIdentifier</key> - <string>com.qt.sensorsmaze</string> - <key>CFBundleName</key> - <string>maze</string> - <key>CFBundlePackageType</key> - <string>APPL</string> - <key>CFBundleShortVersionString</key> - <string>1.0</string> - <key>CFBundleSignature</key> - <string>????</string> - <key>CFBundleVersion</key> - <string>1.0</string> - <key>LSRequiresIPhoneOS</key> - <true/> - <key>UILaunchStoryboardName</key> - <string>LaunchScreen</string> - <key>UISupportedInterfaceOrientations</key> - <array> - <string>UIInterfaceOrientationPortrait</string> - </array> -</dict> -</plist> diff --git a/examples/sensors/maze/LabyrinthSquare.qml b/examples/sensors/maze/LabyrinthSquare.qml deleted file mode 100644 index d9e72db..0000000 --- a/examples/sensors/maze/LabyrinthSquare.qml +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -//Import the declarative plugins -import QtQuick - -//Import the javascript functions for this game -import "lib.js" as Lib - -//Implementation of the Labyrinth square control. -Rectangle { - id: sq - x: 0 - y: 0 - width: Lib.cellDimension - height: Lib.cellDimension - color: "white" - property int val: 0 - property AnimatedImage picture: img - - //Dependent of its position and the labyrinth value a square can be the start, cheese, empty or a wall - AnimatedImage { - id: img - anchors.fill: parent - source: "" - } - - function updateImage() - { - if (sq.val == -1) - sq.picture.source = "content/start.png"; - else if (sq.val == 3) - sq.picture.source = "content/cheese.png"; - else if (sq.val == 4){ - sq.picture.source = "content/cheeseeating.gif"; - sq.picture.playing = true; - } - else if (sq.val == 1) - sq.picture.source = "content/01.png"; - else - sq.picture.source = "content/00.png"; - } -} diff --git a/examples/sensors/maze/Mouse.qml b/examples/sensors/maze/Mouse.qml deleted file mode 100644 index 155f0bd..0000000 --- a/examples/sensors/maze/Mouse.qml +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -//Import the declarative plugins -import QtQuick - -//Import the javascript functions for this game -import "lib.js" as Lib - -//Implementation of the Mouse control. -Item { - id: mouse - x: 0 - y: 0 - width: Lib.cellDimension - height: Lib.cellDimension - property int angle - readonly property double radians_to_degrees: 180 / Math.PI - - AnimatedImage { - id: img - source: "content/mouse_down.gif" - anchors.fill: parent - visible: true - } - - //Function for moving the mouse - function move(newx, newy) - { - if (mouse.x === newx && mouse.y === newy) - return - // somehow this actually works -//! [0] - var a = newy - mouse.y - var b = newx - mouse.x - angle = Math.atan2(-b, a) * mouse.radians_to_degrees - if (angle < 0) - angle = 360 + angle - - img.rotation = angle - mouse.x = newx; - mouse.y = newy; -//! [0] - } -} diff --git a/examples/sensors/maze/android/AndroidManifest.xml b/examples/sensors/maze/android/AndroidManifest.xml deleted file mode 100644 index 8efe1ed..0000000 --- a/examples/sensors/maze/android/AndroidManifest.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="org.qtproject.example.maze" - android:installLocation="auto" - android:versionCode="1" - android:versionName="1.0"> - <!-- The comment below will be replaced with dependencies permissions upon deployment. - Remove the comment if you do not require these default permissions. --> - <!-- %%INSERT_PERMISSIONS --> - - <!-- The comment below will be replaced with dependencies permissions upon deployment. - Remove the comment if you do not require these default features. --> - <!-- %%INSERT_FEATURES --> - - <supports-screens - android:anyDensity="true" - android:largeScreens="true" - android:normalScreens="true" - android:smallScreens="true" /> - <application - android:name="org.qtproject.qt.android.bindings.QtApplication" - android:extractNativeLibs="true" - android:hardwareAccelerated="true" - android:label="-- %%INSERT_APP_NAME%% --" - android:requestLegacyExternalStorage="true"> - <activity - android:name="org.qtproject.qt.android.bindings.QtActivity" - android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" - android:label="-- %%INSERT_APP_NAME%% --" - android:launchMode="singleTop" - android:screenOrientation="portrait"> - <intent-filter> - <action android:name="android.intent.action.MAIN"/> - <category android:name="android.intent.category.LAUNCHER"/> - </intent-filter> - <meta-data - android:name="android.app.lib_name" - android:value="-- %%INSERT_APP_LIB_NAME%% --" /> - <meta-data - android:name="android.app.background_running" - android:value="false" /> - <meta-data - android:name="android.app.extract_android_style" - android:value="minimal" /> - </activity> - </application> -</manifest> diff --git a/examples/sensors/maze/components/ApplicationWindow.qml b/examples/sensors/maze/components/ApplicationWindow.qml deleted file mode 100644 index 3f87d72..0000000 --- a/examples/sensors/maze/components/ApplicationWindow.qml +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -//Import the declarative plugins -import QtQuick - -Rectangle { - id: appWnd - x: 0 - y: 0 - width: 320 - height: 480 - color: "#ececec" -} diff --git a/examples/sensors/maze/components/Button.qml b/examples/sensors/maze/components/Button.qml deleted file mode 100644 index 953424a..0000000 --- a/examples/sensors/maze/components/Button.qml +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -//Import the declarative plugins -import QtQuick - -//Implementation of the Button control. -Item { - id: button - width: 30 - height: 100 - property alias text: innerText.text - signal clicked - - Image { - id: backgroundImage - anchors.fill: parent - source: (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") - } - - Text { - id: innerText - anchors.centerIn: parent - color: "white" - font.bold: true - } - - //Mouse area to react on click events - MouseArea { - anchors.fill: button - onClicked: { button.clicked();} - onPressed: { - backgroundImage.source = "images/button_background_pressed.png" } - onReleased: { - backgroundImage.source = (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") - } - } -} diff --git a/examples/sensors/maze/components/images/button_background_disabled.png b/examples/sensors/maze/components/images/button_background_disabled.png Binary files differdeleted file mode 100644 index 62a00b9..0000000 --- a/examples/sensors/maze/components/images/button_background_disabled.png +++ /dev/null diff --git a/examples/sensors/maze/components/images/button_background_normal.png b/examples/sensors/maze/components/images/button_background_normal.png Binary files differdeleted file mode 100644 index 1fecad5..0000000 --- a/examples/sensors/maze/components/images/button_background_normal.png +++ /dev/null diff --git a/examples/sensors/maze/components/images/button_background_pressed.png b/examples/sensors/maze/components/images/button_background_pressed.png Binary files differdeleted file mode 100644 index e0ba0e7..0000000 --- a/examples/sensors/maze/components/images/button_background_pressed.png +++ /dev/null diff --git a/examples/sensors/maze/content/00.png b/examples/sensors/maze/content/00.png Binary files differdeleted file mode 100644 index 2522be5..0000000 --- a/examples/sensors/maze/content/00.png +++ /dev/null diff --git a/examples/sensors/maze/content/01.png b/examples/sensors/maze/content/01.png Binary files differdeleted file mode 100644 index 6146b20..0000000 --- a/examples/sensors/maze/content/01.png +++ /dev/null diff --git a/examples/sensors/maze/content/cheese.png b/examples/sensors/maze/content/cheese.png Binary files differdeleted file mode 100644 index c737b9d..0000000 --- a/examples/sensors/maze/content/cheese.png +++ /dev/null diff --git a/examples/sensors/maze/content/cheeseeating.gif b/examples/sensors/maze/content/cheeseeating.gif Binary files differdeleted file mode 100644 index 6b2cb47..0000000 --- a/examples/sensors/maze/content/cheeseeating.gif +++ /dev/null diff --git a/examples/sensors/maze/content/congratulations.gif b/examples/sensors/maze/content/congratulations.gif Binary files differdeleted file mode 100644 index 7020417..0000000 --- a/examples/sensors/maze/content/congratulations.gif +++ /dev/null diff --git a/examples/sensors/maze/content/mouse_down.gif b/examples/sensors/maze/content/mouse_down.gif Binary files differdeleted file mode 100644 index 5491c18..0000000 --- a/examples/sensors/maze/content/mouse_down.gif +++ /dev/null diff --git a/examples/sensors/maze/content/start.png b/examples/sensors/maze/content/start.png Binary files differdeleted file mode 100644 index 581b8c9..0000000 --- a/examples/sensors/maze/content/start.png +++ /dev/null diff --git a/examples/sensors/maze/doc/src/maze.qdoc b/examples/sensors/maze/doc/src/maze.qdoc deleted file mode 100644 index a6f132f..0000000 --- a/examples/sensors/maze/doc/src/maze.qdoc +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example maze - \title Qt Sensors - Maze QML Example - \ingroup qtsensors-examples - \image maze.png - - \section2 Maze in QML - \brief The Maze example demonstrates the TiltSensor QML type. - - - To write a QML application that will use the TiltSensor QML sensors type - you need to do the following steps: - - To import the Qt Sensors QML types into your application, use the following - import statement in your .qml file: - - \snippet maze/maze.qml 0 - - Then, add the Sensor QML types into your qml file. - - In this example we use the TiltSensor: - - \snippet maze/maze.qml 1 - - The mouse should move by a factor of the tilt value: - - \snippet maze/maze.qml 2 - - The walk direction of the mouse takes into account some collision detection: - - \snippet maze/maze.qml 3 - - The rotation of the mouse image is determined according to the angle that the mouse is moving. - - \snippet maze/Mouse.qml 0 - -*/ - diff --git a/examples/sensors/maze/lib.js b/examples/sensors/maze/lib.js deleted file mode 100644 index 3bae6a8..0000000 --- a/examples/sensors/maze/lib.js +++ /dev/null @@ -1,264 +0,0 @@ -//global variables -var labyrinth = null; -var dimension = 24; -var cellDimension = 13; -var won; -var objectArray = null; -var sec = 0.0 - -//Allocate labyrinth arrays and create labyrinth and way reflected in the labyrinth array -function createLabyrinth() -{ - won = false; - //create the labyrinth matrix - labyrinth = null; - labyrinth = new Array(dimension); - for (var x = 0; x < dimension; x++ ){ - labyrinth[x] = new Array(dimension); - for (var y = 0; y < dimension; y++ ){ - labyrinth[x][y] = 0; - } - } - createWay(); - createLab(); -} - -//Create a way where the mouse can reach the cheese -function createWay() -{ - //Create rnd way to have at least one solution - //A way square is marked as a 2 in the labyrinth array - var x = 0; - var y = 0; - var ox = x; - var oy = y; - labyrinth[0][0] = 2; - while (x < dimension && y < dimension){ - var rnd = Math.floor(Math.random()*5); - if (Math.floor(Math.random()*2) == 1){ - if (rnd == 0) x--; - if (rnd >= 1) x++; - if (x < 0) x++; - if (x >= dimension){ - x = ox; - break; - } - } - else { - if (rnd == 0) y--; - if (rnd >= 1) y++; - if (y < 0) y++; - if (y >= dimension){ - y = oy; - break; - } - } - - /*avoid to have [2]2| - |2|2|*/ - if (x < (dimension - 1) && y < (dimension - 1)){ - if (labyrinth[x + 1][y] == 2 - && labyrinth[x][y + 1] == 2 - && labyrinth[x + 1][y + 1] == 2){ - y = oy; - x = ox; - continue; - } - } - /*avoid to have |2[2] - |2|2|*/ - if (x > 0 && y < (dimension - 1)){ - if (labyrinth[x - 1][y] == 2 - && labyrinth[x][y + 1] == 2 - && labyrinth[x - 1][y + 1] == 2){ - y = oy; - x = ox; - continue; - } - } - /*avoid to have |2|2| - [2]2|*/ - if (x < (dimension - 1) && y > 0){ - if (labyrinth[x + 1][y] == 2 - && labyrinth[x][y - 1] == 2 - && labyrinth[x + 1][y - 1] == 2){ - y = oy; - x = ox; - continue; - } - } - /*avoid to have |2|2| - |2[2]*/ - if (x > 0 && y > 0){ - if (labyrinth[x - 1][y] == 2 - && labyrinth[x][y - 1] == 2 - && labyrinth[x - 1][y - 1] == 2){ - y = oy; - x = ox; - continue; - } - } - - labyrinth[x][y] = 2; - ox = x; - oy = y; - } - //finish way - while (x < (dimension - 1)){ - labyrinth[x][y] = 2; - x++; - } - while (y < (dimension - 1)){ - labyrinth[x][y] = 2; - y++; - } -} - -//Create the labyrinth with rnd values -function createLab() -{ - //A wall square is marked as a 1 in the labyrinth array - //Not a wall square is marked as a 0 in the labyrinth array - //The Cheese square is marked as a 3 in the labyrinth array - //The start is marked as a -1 in the labyrinth array - for (var x = 0; x < dimension; x++ ){ - var rnd = 0; - for (var y = 0; y < dimension; y++){ - //But don't overwrite the way - if (labyrinth[x][y] != 2){ - var rnd = Math.floor(Math.random()*2); - var xy = 0; - var xxy = 0; - var xyy = 0; - var xxyy = 0; - - if (x > 0 && y > 0){ - xy = labyrinth[x - 1][y - 1]; - if (xy == 2) - xy = 0; - - xyy = labyrinth[x - 1][y]; - if (xyy == 2) - xyy = 0; - - xxy = labyrinth[x][y - 1]; - if (xxy == 2) - xxy = 0; - - xxyy = rnd; - if (xxyy == 2) - xxyy = 0; - - //avoid to have to many |0|1| or |1|0| [xy ][xxy ] - // |1[0] |0[1] [xyy ][xxyy] - if (xyy == xxy && xy == xxyy && xy != xxy){ - if (rnd == 1) - rnd = 0; - else rnd = 1; - } - - //avoid to have to many |1|1| or |0|0| - // |1[1] |0[0] - if (xy == xxy && xxy == xxyy && xxyy == xyy){ - if (rnd == 1) - rnd = 0; - else rnd = 1; - } - } - else if (x == 0 && y > 0){ - xy = labyrinth[x][y - 1]; - if (xy == 2) - xy = 0; - - xyy = rnd; - if (xyy == 2) - xyy = 0; - - xxy = labyrinth[x + 1][y - 1]; - if (xxy == 2) - xxy = 0; - - xxyy = labyrinth[x + 1][y]; - if (xxyy == 2) - xxyy = 0; - - //avoid to have to many |1|1| or |0|0| - // |1[1] |0[0] - if (xy == xxy && xxy == xxyy && xxyy == xyy){ - if (rnd == 1) - rnd = 0; - else rnd = 1; - } - - //avoid to have to many |0|1| or |1|0| [xy ][xxy ] - // |1[0] |0[1] [xyy ][xxyy] - if (xyy == xxy && xy == xxyy && xy != xxy){ - if (rnd == 1) - rnd = 0; - else rnd = 1; - } - } - labyrinth[x][y] = rnd; - } - - } - } - //set start and end - labyrinth[0][0] = -1; - labyrinth[0][1] = 0; - labyrinth[1][0] = 0; - labyrinth[1][1] = 0; - - labyrinth[dimension - 2][dimension - 2] = 0; - labyrinth[dimension - 2][dimension - 1] = 0; - labyrinth[dimension - 1][dimension - 2] = 0; - labyrinth[dimension - 1][dimension - 1] = 3; -} - -//Function that checks if the mouse can be moved in x and y -function canMove(x, y) -{ - //Check if movement is allowed - var xcenter = x + (cellDimension / 2); - var ycenter = y + (cellDimension / 2); - //try to get the index - var idx = Math.floor(xcenter / cellDimension); - var idy = Math.floor(ycenter / cellDimension); - var dx = xcenter - (idx * cellDimension + ( cellDimension / 2 )); - var dy = ycenter - (idy * cellDimension + ( cellDimension / 2 )); - - if (dx > 0){ - if (labyrinth[idx][idy] == 1) - return false; - } - if (dx < 0){ - if (labyrinth[idx][idy] == 1) - return false; - } - if (dy > 0){ - if (labyrinth[idx][idy] == 1) - return false; - } - if (dy < 0){ - if (labyrinth[idx][idy] == 1) - return false; - } - //check if won - if (idx == (dimension - 1) && idy == (dimension - 1)) - won = true; - return true; -} - -//Function that prints out the labyrith array values in the console -function printLab() -{ - //for debug purposes print out lab n console - var iy = 0; - for (var y = 0; y < dimension; y++ ){ - var line = ""; - for (var x = 0; x < dimension; x++ ){ - line += labyrinth[x][y]; - } - console.log(line); - } -} diff --git a/examples/sensors/maze/main.cpp b/examples/sensors/maze/main.cpp deleted file mode 100644 index 2dbf1aa..0000000 --- a/examples/sensors/maze/main.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "../stub.h" -SENSORS_EXAMPLE_MAIN(maze) diff --git a/examples/sensors/maze/maze.pro b/examples/sensors/maze/maze.pro deleted file mode 100644 index f15fa57..0000000 --- a/examples/sensors/maze/maze.pro +++ /dev/null @@ -1,19 +0,0 @@ -TEMPLATE = app -TARGET = maze -QT += quick sensors -SOURCES = main.cpp - -OTHER_FILES = \ - components \ - $$files(*.qml) \ - $$files(*.js) \ - content \ - android/AndroidManifest.xml - -target.path = $$[QT_INSTALL_EXAMPLES]/sensors/maze -INSTALLS += target - -RESOURCES += \ - maze.qrc - -ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android diff --git a/examples/sensors/maze/maze.qml b/examples/sensors/maze/maze.qml deleted file mode 100644 index c28e970..0000000 --- a/examples/sensors/maze/maze.qml +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -/* Layout - mainWnd - / -------------------------------/ gameRect -| / -|-----------------------------/ -||---------------------------| -||||M| || -||| \ || -||| mouseCtrl || -||| || -||| || -||| Labyrinth || -||| || -||| || -||| cheeseSquare || -||| \ || -||| |C||| -||---------------------------| -|----------------------------- -| -|----------------------------- -|| || | -|----------------------------- -| \ \ -| \ timePlayingLabel -| newGameButton ------------------------------- - -*/ -//Import the declarative plugins -import QtQuick -import "components" - -//! [0] -import QtSensors -//! [0] - -//Import the javascript functions for this game -import "lib.js" as Lib - -ApplicationWindow { - id: mainWnd - property bool gameRunning: false - - Component.onCompleted: { - initializeMaze() - newGame() - } - - function initializeMaze() { - Lib.objectArray = new Array(Lib.dimension * Lib.dimension); - Lib.createLabyrinth(); - var idx = 0; - var component = Qt.createComponent("LabyrinthSquare.qml"); - for (var y = 0; y < Lib.dimension; y++ ) { - for (var x = 0; x < Lib.dimension; x++ ) { - var square = component.createObject(gameRect); - if (!square) { - console.log("error loading labyrinth square: " + component.errorString()) - return - } - square.x = x * square.width; - square.y = y * square.height; - square.val = Lib.labyrinth[x][y]; - Lib.objectArray[idx] = square; - idx++; - } - } - } - - function newGame() { - congratulation.visible = false; - - // Reset game time - timePlayingLabel.text = "--"; - Lib.sec = 0.0; - - // Create new labyrinth - Lib.createLabyrinth(); - // Update maze tiles to match the new labyrinth - var idx = 0; - for (var y = 0; y < Lib.dimension; y++ ) { - for (var x = 0; x < Lib.dimension; x++ ) { - Lib.objectArray[idx].val = Lib.labyrinth[x][y]; - Lib.objectArray[idx].updateImage(); - idx++; - } - } - // Reset mouse position and start the game - mouseCtrl.x = 0; - mouseCtrl.y = 0; - mainWnd.gameRunning = true; - } - - function gameWon() { - // Update the cheese square at the bottom right (win animation) - Lib.objectArray[Lib.dimension * Lib.dimension - 1].val = 4 - Lib.objectArray[Lib.dimension * Lib.dimension - 1].updateImage() - congratulation.visible = true; - mainWnd.gameRunning = false; - } - - Rectangle { - id: gameRect - x: (mainWnd.width - width) / 2 - y: 5 - width: Lib.dimension * Lib.cellDimension - height: Lib.dimension * Lib.cellDimension - color: "transparent" - border.width: 2 - } - - Mouse { - id: mouseCtrl - } - - Congratulation { - id: congratulation - visible: false - } - -//! [1] - TiltSensor { - id: tiltSensor - active: true - } -//! [1] - - //Timer to read out the x and y rotation of the TiltSensor - Timer { - id: tiltTimer - interval: 50 - repeat: true - running: tiltSensor.active && mainWnd.gameRunning - - onTriggered: { - // Update the maze unless game is already won - if (Lib.won === true) { - gameWon() - return - } - Lib.sec += 0.05; - timePlayingLabel.text = Math.floor(Lib.sec) + " seconds"; - - //check if we can move the mouse - var xval = -1; - var yval = -1; - -//! [2] - var xstep = 0; - xstep = tiltSensor.reading.yRotation * 0.1 //acceleration - - var ystep = 0; - ystep = tiltSensor.reading.xRotation * 0.1 //acceleration -//! [2] -//! [3] - if (xstep < 1 && xstep > 0) - xstep = 0 - else if (xstep > -1 && xstep < 0) - xstep = 0 - - if (ystep < 1 && ystep > 0) - ystep = 0; - else if (ystep > -1 && ystep < 0) - ystep = 0; - - if ((xstep < 0 && mouseCtrl.x > 0 - && Lib.canMove(mouseCtrl.x + xstep,mouseCtrl.y))) { - xval = mouseCtrl.x + xstep; - - } else if (xstep > 0 && mouseCtrl.x < (Lib.cellDimension * (Lib.dimension - 1)) - && Lib.canMove(mouseCtrl.x + xstep,mouseCtrl.y)) { - xval = mouseCtrl.x + xstep; - } else - xval = mouseCtrl.x; - - if (ystep < 0 && mouseCtrl.y > 0 - && Lib.canMove(mouseCtrl.x, mouseCtrl.y + ystep)) { - yval = mouseCtrl.y + ystep; - } else if (ystep > 0 && (mouseCtrl.y < (Lib.cellDimension * (Lib.dimension - 1))) - && Lib.canMove(mouseCtrl.x, mouseCtrl.y + ystep)) { - yval = mouseCtrl.y + ystep; - } else - yval = mouseCtrl.y - mouseCtrl.move(xval, yval); -//! [3] - } - } - - //Button to start a new Game - Button{ - id: newGameButton - anchors.left: gameRect.left - anchors.top: gameRect.bottom - anchors.topMargin: 5 - height: 30 - width: 100 - text: qsTr("New game") - onClicked: newGame() - } - Button{ - id: calibrateButton - anchors.left: gameRect.left - anchors.top: newGameButton.bottom - anchors.topMargin: 5 - height: 30 - width: 100 - text: qsTr("Calibrate") - onClicked: tiltSensor.calibrate(); - } - - Text { - id: tiltSensorInfo - visible: tiltSensor.active - anchors.left: gameRect.left - anchors.top: calibrateButton.bottom - anchors.topMargin: 5 - text: qsTr("Tilt sensor ID: ") + tiltSensor.identifier - } - - //Label to print out the game time - Text{ - id: timePlayingLabel - anchors.right: gameRect.right - anchors.top: gameRect.bottom - anchors.topMargin: 5 - } - - Rectangle { - id: tiltSensorMissing - visible: !tiltSensor.active - anchors.fill: parent - color: "#AACCCCCC" // slightly transparent - Text { - anchors.centerIn: parent - text: qsTr("Tilt sensor\nnot found") - font.pixelSize: 24 - font.bold: true - color: "black" - } - MouseArea { - // prevent interaction with the game - anchors.fill: parent - } - } -} - diff --git a/examples/sensors/maze/maze.qrc b/examples/sensors/maze/maze.qrc deleted file mode 100644 index 1091619..0000000 --- a/examples/sensors/maze/maze.qrc +++ /dev/null @@ -1,21 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>Congratulation.qml</file> - <file>LabyrinthSquare.qml</file> - <file>lib.js</file> - <file>maze.qml</file> - <file>Mouse.qml</file> - <file>components/ApplicationWindow.qml</file> - <file>components/Button.qml</file> - <file>components/images/button_background_disabled.png</file> - <file>components/images/button_background_pressed.png</file> - <file>components/images/button_background_normal.png</file> - <file>content/00.png</file> - <file>content/start.png</file> - <file>content/mouse_down.gif</file> - <file>content/congratulations.gif</file> - <file>content/cheeseeating.gif</file> - <file>content/cheese.png</file> - <file>content/01.png</file> - </qresource> -</RCC> diff --git a/examples/sensors/sensors.pro b/examples/sensors/sensors.pro index 77a9529..86d029b 100644 --- a/examples/sensors/sensors.pro +++ b/examples/sensors/sensors.pro @@ -4,7 +4,6 @@ SUBDIRS += grue qtHaveModule(quick) { SUBDIRS += \ - maze \ qmlqtsensors \ sensor_explorer } |