pickup.dd 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # create pickups
  2. (class Pickup (group
  3. (def dd_sprite sprite)
  4. (def int counter 0)
  5. (def dd_sprite player)
  6. (def int paddingX 0)
  7. (def int paddingY 0)
  8. # create pick-up
  9. (function init (group) (group
  10. (= this.sprite (new dd_sprite "images/dd_logo.png"))
  11. (this.sprite.setWidth 50)
  12. (this.sprite.setHeight 50)
  13. (this.sprite.setX (/ eng.width 2))
  14. (this.sprite.setY 50)
  15. (this.sprite.setVisible 0)
  16. ))
  17. (function update (group) (group
  18. # counter to reveal pickup
  19. (if (== (this.sprite.getVisible) 0)
  20. (group
  21. (= this.counter (+ this.counter 1))
  22. (if (>= this.counter 100)
  23. (group
  24. (this.sprite.setX
  25. (-
  26. (+ this.paddingX (dd_math.rand (- eng.width (* this.paddingX 2))))
  27. (/ (this.sprite.getWidth) 2)
  28. )
  29. )
  30. (this.sprite.setY
  31. (-
  32. (+ this.paddingY (dd_math.rand (- eng.height (* this.paddingY 2))))
  33. (/ (this.sprite.getHeight 2))
  34. )
  35. )
  36. (this.sprite.setVisible 1)
  37. (= this.counter 0)
  38. )
  39. )
  40. )
  41. )
  42. # calculate collision with player
  43. (if (&& (this.sprite.getVisible) (this.sprite.collidesWith this.player))
  44. (group
  45. (this.sprite.setVisible 0)
  46. (= this.counter 0)
  47. )
  48. )
  49. ))
  50. ))