Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. final int GO_RIGHT = 0;
  2. final int GO_DOWN = 1;
  3. final int GO_LEFT = 2;
  4. final int GO_UP = 3;
  5.  
  6. float x, y;
  7. float w, h;
  8. float speed = 5;
  9.  
  10. int state = GO_RIGHT;
  11.  
  12. void setup() {
  13. size(500, 500);
  14. w = 50;
  15. h = 30;
  16. x = w/2;
  17. y = h/2;
  18. }
  19.  
  20. void draw() {
  21.  
  22. // If the state is 0, move to the right.
  23. switch (state){
  24. case GO_RIGHT:
  25. x += speed;
  26. // If, while the state is 0, it reaches the right side of the window, change the state to 1
  27. if (x > width-w/2) {
  28. x = width-w/2;
  29. state = 1;
  30. }
  31. break;
  32.  
  33. case GO_DOWN:
  34. y += speed;
  35. if (y > height-h/2) {
  36. y = height-h/2;
  37. state = 2;
  38. }
  39. break;
  40.  
  41. case GO_LEFT:
  42. x -= speed;
  43. if (x < w/2) {
  44. x = w/2;
  45. state = 3;
  46. }
  47. break;
  48.  
  49. case GO_UP:
  50. y -= speed;
  51. if (y < h/2) {
  52. y = h/2;
  53. state=0;
  54. }
  55. break;
  56. }
  57.  
  58. background(0);
  59. // UFO
  60. fill(151,37,210);
  61. ellipse(x, y, w, h/2);
  62. fill(186,0,255);
  63. stroke(255);
  64. arc(x, y, h*4/5, h*4/5, PI, TWO_PI);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement