123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- import QtQuick 1.0
- Rectangle {
- id: mainwindow
- width: 500
- height: 500
- Rectangle {
- id: table
- anchors.fill: parent
- gradient: Gradient {
- GradientStop {
- position: 0.0; color: "green"
- }
- GradientStop {
- position: 0.5; color: "yellow"
- }
- GradientStop {
- position: 1.0; color: "blue"
- }
- }
- opacity: 0.8
- Rectangle {
- id: bottomline
- width: 500
- height: 20
- anchors.baseline: parent.bottom
- anchors.baselineOffset: -20
- color: "red"
- }
- Rectangle {
- id: nextline
- width: bottomline.width/2
- height: 20
- anchors.baseline: bottomline.top
- anchors.baselineOffset: -200
- color: "red"
- }
- Rectangle {
- id: player;
- width: 20; height: 20; radius:10
- anchors.baseline: bottomline.top
- anchors.baselineOffset: -height
- property int startx
- property int starty
- onXChanged: {
- if (jump.running==false)
- {
- if ( (player.anchors.baselineOffset==-200)
- || (player.anchors.baselineOffset==0) )
- {
- fall.stop();
- }
- else
- {
- fall.start();
- }
- }
- }
- onYChanged:
- {
- if (jump.running==false)
- {
- if ( (player.anchors.baselineOffset==-200)
- || (player.anchors.baselineOffset==0) )
- {
- fall.stop();
- }
- else
- {
- fall.start();
- }
- }
- }
- }
- PropertyAnimation{
- from: -200; to: 0
- duration: 10000
- target: bottomline
- properties: "anchors.baselineOffset"
- running: false
- loops: Animation.Infinite
- }
- }
- PropertyAnimation{
- id: jump
- from: player.starty; to: player.starty-200
- duration: 400
- target: player
- properties: "anchors.baselineOffset"
- easing.type: Easing.OutQuad
- }
- PropertyAnimation{
- id: fall
- from: player.anchors.baselineOffset; to: 0
- duration: 400
- target: player
- properties: "anchors.baselineOffset"
- easing.type: Easing.InQuad
- }
- PropertyAnimation{
- id: goright;
- target: player;
- properties: "x";
- from: player.x; to:table.width-player.width;
- duration: 2000*(1-(player.startx/table.width));
- }
- PropertyAnimation{
- id: goleft;
- target: player;
- properties: "x";
- from: player.x; to:0;
- duration: 2000*(player.startx/table.width);
- }
- focus: true
- Keys.onPressed:{
- if (event.key == Qt.Key_Left) {
- if (goleft.running==false)
- {
- goright.stop();
- player.startx=player.x;
- goleft.start();
- }
- }
- if (event.key == Qt.Key_Right) {
- if (goright.running==false)
- {
- goleft.stop();
- player.startx=player.x
- goright.start();
- }
- }
- if (event.key == Qt.Key_Space)
- {
- player.starty=player.anchors.baselineOffset
- jump.start();
- }
- }
- Keys.onReleased:{
- goright.stop();
- goleft.stop();
- }
- }
|