example.dd 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # player
  2. # moves to 4 points, when it reaches one, it goes to the next
  3. (class playerClass (group
  4. # points
  5. (def dd_point p (new dd_point 0 0))
  6. (def dd_point p1 (new dd_point eng.width 0))
  7. (def dd_point p2 (new dd_point eng.width eng.height))
  8. (def dd_point p3 (new dd_point 0 eng.height))
  9. # sprite and target
  10. (def dd_sprite this.sprite)
  11. (def dd_point target p)
  12. # init
  13. (function init (group) (group
  14. (= this.sprite (new dd_sprite "images/dd_logo.png"))
  15. (= this.sprite.width 150)
  16. (= this.sprite.height 150)
  17. (this.sprite.anchor.set (/ 1 2))
  18. ))
  19. # move to next target
  20. (function nextTarget (group) (group
  21. (if (== target p ) (= target p1)
  22. (== target p1) (= target p2)
  23. (== target p2) (= target p3)
  24. (== target p3) (= target p )
  25. )
  26. ))
  27. # update
  28. (function update (group) (group
  29. (= this.sprite.x (+ this.sprite.x (/ (- target.x this.sprite.x) 50)) )
  30. (= this.sprite.y (+ this.sprite.y (/ (- target.y this.sprite.y) 50)) )
  31. (if (&&
  32. (< (dd_math.abs (- target.x this.sprite.x)) 5)
  33. (< (dd_math.abs (- target.y this.sprite.y)) 5)
  34. )
  35. (this.nextTarget)
  36. )
  37. ))
  38. ))
  39. # main class
  40. ( class world_main World (group
  41. # padding
  42. (def int padding 10)
  43. # player
  44. (def playerClass this.player)
  45. (function input (group) (this.player.nextTarget))
  46. (function update (group) (group
  47. (this.player.update)
  48. ))
  49. (function start (group) (group
  50. (= this.player (new playerClass))
  51. (this.player.init)
  52. (this.container.addChild this.player.sprite)
  53. # top left
  54. (def dd_sprite this.tpLeft (new dd_sprite "images/dd_logo.png"))
  55. (= this.tpLeft.width 50)
  56. (= this.tpLeft.height 50)
  57. (= this.tpLeft.interactive true)
  58. (this.container.addChild this.tpLeft)
  59. # bottom left
  60. (def dd_sprite this.btmLeft (new dd_sprite "images/dd_logo.png"))
  61. (= this.btmLeft.width 50)
  62. (= this.btmLeft.height 50)
  63. (this.container.addChild this.btmLeft)
  64. # top right
  65. (def sprite this.tpRight (new dd_sprite "images/dd_logo.png"))
  66. (= this.tpRight.width 50)
  67. (= this.tpRight.height 50)
  68. (this.container.addChild this.tpRight)
  69. # bottom right
  70. (def sprite this.btmRight (new dd_sprite "images/dd_logo.png"))
  71. (= this.btmRight.width 50)
  72. (= this.btmRight.height 50)
  73. (this.container.addChild this.btmRight)
  74. ))
  75. (function resize (group) (group
  76. (= this.tpLeft.x padding)
  77. (= this.tpLeft.y padding)
  78. (= this.btmLeft.x padding)
  79. (= this.btmLeft.y (- eng.height this.btmLeft.height padding))
  80. (= this.tpRight.x (- eng.width this.tpRight.width padding))
  81. (= this.tpRight.y padding)
  82. (= this.btmRight.x (- eng.width this.btmRight.width padding))
  83. (= this.btmRight.y (- eng.height this.btmRight.height padding))
  84. ))
  85. # assets
  86. (function assets(group) (group
  87. (return (array "images/dd_logo.png"))
  88. ))
  89. ))