BoomBlock.qml 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import Qt 4.7
  5. import Qt.labs.particles 1.0
  6. Item {
  7. id: block
  8. property bool dying: false
  9. property bool spawned: false
  10. property int type: 0
  11. Behavior on x {
  12. enabled: spawned;
  13. SpringAnimation { spring: 2; damping: 0.2 }
  14. }
  15. Behavior on y {
  16. SpringAnimation { spring: 2; damping: 0.2 }
  17. }
  18. Image {
  19. id: img
  20. source: {
  21. if(type == 0){
  22. "pics/redStone.png";
  23. } else if(type == 1) {
  24. "pics/blueStone.png";
  25. } else {
  26. "pics/greenStone.png";
  27. }
  28. }
  29. opacity: 0
  30. Behavior on opacity { NumberAnimation { duration: 200 } }
  31. anchors.fill: parent
  32. }
  33. Particles {
  34. id: particles
  35. width: 1; height: 1
  36. anchors.centerIn: parent
  37. emissionRate: 0
  38. lifeSpan: 700; lifeSpanDeviation: 600
  39. angle: 0; angleDeviation: 360;
  40. velocity: 100; velocityDeviation: 30
  41. source: {
  42. if(type == 0){
  43. "pics/redStar.png";
  44. } else if (type == 1) {
  45. "pics/blueStar.png";
  46. } else {
  47. "pics/greenStar.png";
  48. }
  49. }
  50. }
  51. states: [
  52. State {
  53. name: "AliveState"; when: spawned == true && dying == false
  54. PropertyChanges { target: img; opacity: 1 }
  55. },
  56. State {
  57. name: "DeathState"; when: dying == true
  58. StateChangeScript { script: particles.burst(50); }
  59. PropertyChanges { target: img; opacity: 0 }
  60. StateChangeScript { script: block.destroy(1000); }
  61. }
  62. ]
  63. }