mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-06 02:30:38 -08:00
add example 'sokoban'
This commit is contained in:
parent
a5b827bc96
commit
b897d60539
33 changed files with 5368 additions and 1 deletions
15
examples/sokoban/qml/ext/ArrowButton.qml
Normal file
15
examples/sokoban/qml/ext/ArrowButton.qml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
|
||||
Button {
|
||||
width: main.small ? 37 : 50
|
||||
height: width
|
||||
flat: true
|
||||
focusPolicy: Qt.NoFocus
|
||||
font.family: fontAwesome.name
|
||||
font.pixelSize: 1.2 * width
|
||||
opacity: 0.2
|
||||
scale: 1.2
|
||||
|
||||
onPressed: Lisp.call(this, "qsoko:button-pressed")
|
||||
}
|
||||
12
examples/sokoban/qml/ext/Button.qml
Normal file
12
examples/sokoban/qml/ext/Button.qml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
|
||||
Button {
|
||||
width: main.small ? 32 : 50
|
||||
height: width
|
||||
font.family: fontAwesome.name
|
||||
font.pixelSize: width - 6
|
||||
opacity: 0.8
|
||||
|
||||
onPressed: Lisp.call(this, "qsoko:button-pressed")
|
||||
}
|
||||
21
examples/sokoban/qml/ext/Dynamic.qml
Normal file
21
examples/sokoban/qml/ext/Dynamic.qml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import QtQuick 2.15
|
||||
|
||||
Item {
|
||||
objectName: "dynamic"
|
||||
|
||||
property Component box: Qt.createComponent("dynamic/Box.qml")
|
||||
property Component box2: Qt.createComponent("dynamic/Box2.qml")
|
||||
property Component player: Qt.createComponent("dynamic/Player.qml")
|
||||
property Component fixed: Qt.createComponent("dynamic/Fixed.qml")
|
||||
|
||||
function makeItem(name) {
|
||||
switch (name) {
|
||||
case "object": return box.createObject()
|
||||
case "object2": return box2.createObject()
|
||||
case "player":
|
||||
case "player2": return player.createObject()
|
||||
case "wall":
|
||||
case "goal": return fixed.createObject()
|
||||
}
|
||||
}
|
||||
}
|
||||
6
examples/sokoban/qml/ext/NumberAnimation.qml
Normal file
6
examples/sokoban/qml/ext/NumberAnimation.qml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import QtQuick 2.15
|
||||
|
||||
NumberAnimation {
|
||||
onRunningChanged: Lisp.call("qsoko:animation-change", running)
|
||||
}
|
||||
|
||||
6
examples/sokoban/qml/ext/RotationAnimation.qml
Normal file
6
examples/sokoban/qml/ext/RotationAnimation.qml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import QtQuick 2.15
|
||||
|
||||
RotationAnimation {
|
||||
onRunningChanged: Lisp.call("qsoko:animation-change", running)
|
||||
}
|
||||
|
||||
5
examples/sokoban/qml/ext/ScaleAnimator.qml
Normal file
5
examples/sokoban/qml/ext/ScaleAnimator.qml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import QtQuick 2.15
|
||||
|
||||
ScaleAnimator {
|
||||
onRunningChanged: Lisp.call("qsoko:animation-change", running)
|
||||
}
|
||||
6
examples/sokoban/qml/ext/SequentialAnimation.qml
Normal file
6
examples/sokoban/qml/ext/SequentialAnimation.qml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import QtQuick 2.15
|
||||
|
||||
SequentialAnimation {
|
||||
onRunningChanged: Lisp.call("qsoko:animation-change", running)
|
||||
}
|
||||
|
||||
18
examples/sokoban/qml/ext/dynamic/Box.qml
Normal file
18
examples/sokoban/qml/ext/dynamic/Box.qml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import QtQuick 2.15
|
||||
import "../" as Ext
|
||||
|
||||
Image {
|
||||
Behavior on x {
|
||||
Ext.NumberAnimation {
|
||||
duration: 150
|
||||
easing.type: Easing.InQuart
|
||||
}
|
||||
}
|
||||
|
||||
Behavior on y {
|
||||
Ext.NumberAnimation {
|
||||
duration: 150
|
||||
easing.type: Easing.InQuart
|
||||
}
|
||||
}
|
||||
}
|
||||
48
examples/sokoban/qml/ext/dynamic/Box2.qml
Normal file
48
examples/sokoban/qml/ext/dynamic/Box2.qml
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import QtQuick 2.15
|
||||
import "../" as Ext
|
||||
|
||||
Image {
|
||||
id: box2
|
||||
|
||||
Behavior on x {
|
||||
Ext.NumberAnimation {
|
||||
duration: 150
|
||||
easing.type: Easing.InQuart
|
||||
}
|
||||
}
|
||||
|
||||
Behavior on y {
|
||||
Ext.NumberAnimation {
|
||||
duration: 150
|
||||
easing.type: Easing.InQuart
|
||||
}
|
||||
}
|
||||
|
||||
// final animation
|
||||
|
||||
Ext.SequentialAnimation {
|
||||
objectName: "wiggle_box"
|
||||
loops: 3
|
||||
|
||||
RotationAnimation {
|
||||
target: box2
|
||||
property: "rotation"
|
||||
from: 0; to: 30
|
||||
duration: 150
|
||||
}
|
||||
|
||||
RotationAnimation {
|
||||
target: box2
|
||||
property: "rotation"
|
||||
from: 30; to: -30
|
||||
duration: 300
|
||||
}
|
||||
|
||||
RotationAnimation {
|
||||
target: box2
|
||||
property: "rotation"
|
||||
from: -30; to: 0
|
||||
duration: 150
|
||||
}
|
||||
}
|
||||
}
|
||||
4
examples/sokoban/qml/ext/dynamic/Fixed.qml
Normal file
4
examples/sokoban/qml/ext/dynamic/Fixed.qml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import QtQuick 2.15
|
||||
|
||||
Image {
|
||||
}
|
||||
30
examples/sokoban/qml/ext/dynamic/Player.qml
Normal file
30
examples/sokoban/qml/ext/dynamic/Player.qml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import QtQuick 2.15
|
||||
import "../" as Ext
|
||||
|
||||
Image {
|
||||
id: player
|
||||
|
||||
Behavior on x {
|
||||
Ext.NumberAnimation {
|
||||
duration: 120
|
||||
easing.type: Easing.InOutSine
|
||||
}
|
||||
}
|
||||
|
||||
Behavior on y {
|
||||
Ext.NumberAnimation {
|
||||
duration: 120
|
||||
easing.type: Easing.InOutSine
|
||||
}
|
||||
}
|
||||
|
||||
// final animation
|
||||
|
||||
Ext.RotationAnimation {
|
||||
objectName: "rotate_player"
|
||||
target: player
|
||||
property: "rotation"
|
||||
from: 0; to: 360
|
||||
duration: 600
|
||||
}
|
||||
}
|
||||
BIN
examples/sokoban/qml/fonts/fontawesome-webfont.ttf
Normal file
BIN
examples/sokoban/qml/fonts/fontawesome-webfont.ttf
Normal file
Binary file not shown.
BIN
examples/sokoban/qml/img/goal.png
Normal file
BIN
examples/sokoban/qml/img/goal.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 284 B |
BIN
examples/sokoban/qml/img/object.png
Normal file
BIN
examples/sokoban/qml/img/object.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 469 B |
BIN
examples/sokoban/qml/img/object2.png
Normal file
BIN
examples/sokoban/qml/img/object2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 478 B |
BIN
examples/sokoban/qml/img/player.png
Normal file
BIN
examples/sokoban/qml/img/player.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 841 B |
BIN
examples/sokoban/qml/img/player2.png
Normal file
BIN
examples/sokoban/qml/img/player2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 841 B |
BIN
examples/sokoban/qml/img/wall.png
Normal file
BIN
examples/sokoban/qml/img/wall.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 165 B |
155
examples/sokoban/qml/main.qml
Normal file
155
examples/sokoban/qml/main.qml
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Window 2.15
|
||||
import "ext/" as Ext
|
||||
|
||||
Rectangle {
|
||||
id: main
|
||||
width: Screen.desktopAvailableWidth
|
||||
height: Screen.desktopAvailableHeight
|
||||
|
||||
property bool small: (Math.max(width, height) < 1000)
|
||||
|
||||
function isLandscape() { return (Screen.primaryOrientation === Qt.LandscapeOrientation) }
|
||||
|
||||
Ext.Dynamic {}
|
||||
|
||||
Row {
|
||||
anchors.centerIn: parent
|
||||
// adapt 'level' and 'board' scale to screen size
|
||||
scale: isLandscape()
|
||||
? ((Screen.desktopAvailableHeight - 10) / board.height)
|
||||
: ((Screen.desktopAvailableWidth - 10) / (board.width + 2 * level.width))
|
||||
|
||||
Slider {
|
||||
id: level
|
||||
objectName: "level"
|
||||
height: board.height
|
||||
orientation: Qt.Vertical
|
||||
stepSize: 1.0
|
||||
|
||||
onValueChanged: Lisp.call("qsoko:set-maze")
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: board
|
||||
objectName: "board"
|
||||
width: 512; height: 512
|
||||
color: "lightsteelblue"
|
||||
}
|
||||
|
||||
// dummy to have it exactly centered
|
||||
Item {
|
||||
width: level.width
|
||||
height: level.height
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
id: buttons1
|
||||
objectName: "buttons1"
|
||||
spacing: main.small ? 10 : 15
|
||||
padding: 10
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
Ext.Button {
|
||||
objectName: "previous"
|
||||
text: "\uf100"
|
||||
}
|
||||
Ext.Button {
|
||||
objectName: "next"
|
||||
text: "\uf101"
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
id: buttons2
|
||||
objectName: "buttons2"
|
||||
spacing: main.small ? 10 : 15
|
||||
padding: 10
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
Ext.Button {
|
||||
objectName: "undo"
|
||||
text: "\uf112"
|
||||
}
|
||||
Ext.Button {
|
||||
objectName: "restart"
|
||||
text: "\uf0e2"
|
||||
}
|
||||
Ext.Button {
|
||||
objectName: "solve"
|
||||
text: "\uf17b"
|
||||
}
|
||||
}
|
||||
|
||||
// container for arrow buttons
|
||||
Item {
|
||||
id: arrows
|
||||
y: buttons1.y - height - (main.small ? 25 : 50)
|
||||
width: up.width * 3
|
||||
height: up.height * 3
|
||||
anchors.margins: 10
|
||||
anchors.horizontalCenter: buttons2.horizontalCenter
|
||||
|
||||
Ext.ArrowButton {
|
||||
id: up
|
||||
objectName: "up"
|
||||
text: "\uf139"
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
Ext.ArrowButton {
|
||||
objectName: "left"
|
||||
text: "\uf137"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
Ext.ArrowButton {
|
||||
objectName: "right"
|
||||
text: "\uf138"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.right: parent.right
|
||||
}
|
||||
|
||||
Ext.ArrowButton {
|
||||
objectName: "down"
|
||||
text: "\uf13a"
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom: parent.bottom
|
||||
}
|
||||
}
|
||||
|
||||
// level change animations
|
||||
|
||||
Ext.ScaleAnimator {
|
||||
objectName: "zoom_board_out"
|
||||
target: board
|
||||
from: 1.0
|
||||
to: 0.0
|
||||
duration: 250
|
||||
}
|
||||
|
||||
Ext.ScaleAnimator {
|
||||
objectName: "zoom_board_in"
|
||||
target: board
|
||||
from: 0.0
|
||||
to: 1.0
|
||||
duration: 250
|
||||
}
|
||||
|
||||
// etc
|
||||
|
||||
Keys.onPressed: {
|
||||
if(event.key === Qt.Key_Back) {
|
||||
event.accepted = true
|
||||
Lisp.call("qml:qquit")
|
||||
}
|
||||
}
|
||||
|
||||
FontLoader {
|
||||
id: fontAwesome
|
||||
source: "fonts/fontawesome-webfont.ttf"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue