-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRabbit.qml
More file actions
80 lines (64 loc) · 1.73 KB
/
Rabbit.qml
File metadata and controls
80 lines (64 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//rabbit by Oepi-Loepi for Toon
import QtQuick 2.1
Item {
id: rabbit
property bool destroyed: false
width: 125
height: 107
x: -60
y: parent.height - 107
Item {
id: sprite
anchors.centerIn: parent
height: parent.height
width: parent.height
clip: true
y: parent.height
property int framex: randomNumber(0, 9)
property int framey: randomNumber(0, 1)
ParallelAnimation {
id: walk
NumberAnimation { target: rabbit; property: "x"; to: (x+(5*speed)); duration: 100 }
}
Timer {
running: true
repeat: true
interval: 50
onTriggered: {
walk.restart();
sprite.framex++;
if (sprite.framex >= 12) {
sprite.framex = 0
sprite.framey++
}
if (sprite.framey === 1 && sprite.framex >= 11 ) {
sprite.framey= 0
sprite.framex = 0
}
}
}
Image {
id: spriteImage
source: "https://raw.githubusercontent.com/ToonSoftwareCollective/toonanimations/main/rabbit.png"
y:-107 *sprite.framey
x:-125*sprite.framex
}
}
function randomNumber(from, to) {
return Math.floor(Math.random() * (to - from + 1) + from);
}
property int speed: randomNumber(3, 6)
Timer {
interval: 400
running: true
repeat: true
onTriggered: {
if (!isNxt && (rabbit.x - rabbit.width > 800)) {
rabbit.destroy();
}
if (isNxt && (rabbit.x - rabbit.width > 1024)) {
rabbit.destroy();
}
}
}
}