1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- # main world
- struct world_main : dd_world {
- # test sprite
- struct dd_sprite my_sprite;
- # speed and direction
- int direction;
- int speed;
- # init sprite
- void init() {
- # first sprite is at the top
- this.my_sprite.name = "dd_logo.png";
- this.my_sprite.x = 100;
- this.my_sprite.y = 100;
- this.my_sprite.load();
- # speed and direction
- this.direction = 0;
- this.speed = 10;
- };
- # update sprite's position
- override void update() {
- # direction 0 moves to the right
- if (this.direction == 0) {
- this.my_sprite.x = this.my_sprite.x +this.speed;
- if (this.my_sprite.x +this.my_sprite.w > DD_WIDTH) {
- this.my_sprite.x = DD_WIDTH -this.my_sprite.w;
- this.direction = 1;
- }
- }
- # direction 1 moves downwards
- if (this.direction == 1) {
- this.my_sprite.y = this.my_sprite.y +this.speed;
- if (this.my_sprite.y +this.my_sprite.h > DD_HEIGHT) {
- this.my_sprite.y = DD_HEIGHT -this.my_sprite.h;
- this.direction = 2;
- }
- }
- # direction 2 moves leftwards
- if (this.direction == 2) {
- this.my_sprite.x = this.my_sprite.x -this.speed;
- if (this.my_sprite.x < 0) {
- this.my_sprite.x = 0;
- this.direction = 3;
- }
- }
- # direction 3 moves upwards
- if (this.direction == 3) {
- this.my_sprite.y = this.my_sprite.y -this.speed;
- if (this.my_sprite.y < 0) {
- this.my_sprite.y = 0;
- this.direction = 0;
- }
- }
- }; # update
- # draw sprite
- override void draw() {
- this.my_sprite.draw();
- };
- override void click() {
- this.direction = this.direction +1;
- if (this.direction > 3) {
- this.direction = 0;
- }
- };
- }; # world_main
|