example.dd 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # main world
  2. struct world_main : dd_world {
  3. # test sprite
  4. struct dd_sprite my_sprite;
  5. # speed and direction
  6. int direction;
  7. int speed;
  8. # init sprite
  9. void init() {
  10. # first sprite is at the top
  11. this.my_sprite.name = "dd_logo.png";
  12. this.my_sprite.x = 100;
  13. this.my_sprite.y = 100;
  14. this.my_sprite.load();
  15. # speed and direction
  16. this.direction = 0;
  17. this.speed = 10;
  18. };
  19. # update sprite's position
  20. override void update() {
  21. # direction 0 moves to the right
  22. if (this.direction == 0) {
  23. this.my_sprite.x = this.my_sprite.x +this.speed;
  24. if (this.my_sprite.x +this.my_sprite.w > DD_WIDTH) {
  25. this.my_sprite.x = DD_WIDTH -this.my_sprite.w;
  26. this.direction = 1;
  27. }
  28. }
  29. # direction 1 moves downwards
  30. if (this.direction == 1) {
  31. this.my_sprite.y = this.my_sprite.y +this.speed;
  32. if (this.my_sprite.y +this.my_sprite.h > DD_HEIGHT) {
  33. this.my_sprite.y = DD_HEIGHT -this.my_sprite.h;
  34. this.direction = 2;
  35. }
  36. }
  37. # direction 2 moves leftwards
  38. if (this.direction == 2) {
  39. this.my_sprite.x = this.my_sprite.x -this.speed;
  40. if (this.my_sprite.x < 0) {
  41. this.my_sprite.x = 0;
  42. this.direction = 3;
  43. }
  44. }
  45. # direction 3 moves upwards
  46. if (this.direction == 3) {
  47. this.my_sprite.y = this.my_sprite.y -this.speed;
  48. if (this.my_sprite.y < 0) {
  49. this.my_sprite.y = 0;
  50. this.direction = 0;
  51. }
  52. }
  53. }; # update
  54. # draw sprite
  55. override void draw() {
  56. this.my_sprite.draw();
  57. };
  58. override void click() {
  59. this.direction = this.direction +1;
  60. if (this.direction > 3) {
  61. this.direction = 0;
  62. }
  63. };
  64. }; # world_main