Advertisement
Guest User

Untitled

a guest
Jul 1st, 2018
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None
  1. // initialize variables
  2. // We can do this in the main code as well but since these (global)
  3. // variables are only used in this state I've placed it here.
  4.  
  5. int distance;
  6. int dotX;
  7. int dotY;
  8. int stepSize = 5;
  9.  
  10. float xpos;
  11. float ypos;
  12. float drag = 30.0;
  13.  
  14. void beginState3() {
  15. // set dot coordinates in the middle of the screen
  16. dotX = width/2;
  17. dotY = height/2;
  18. movie2.play();
  19. }
  20.  
  21. void updateState3(){
  22.  
  23. // --------------------------------------------
  24. // Do something with input
  25. // --------------------------------------------
  26.  
  27. if (keyPressed){
  28. if (key == '1') {currentState = 1;}
  29. if (key == '2') {currentState = 2;}
  30.  
  31.  
  32. if (key == CODED) {
  33. if(keyCode == UP) {dotY = dotY - stepSize;}
  34. if(keyCode == DOWN) {dotY = dotY + stepSize;}
  35. if(keyCode == LEFT) {dotX = dotX - stepSize;}
  36. if(keyCode == RIGHT) {dotX = dotX + stepSize;}
  37. }
  38. }
  39.  
  40. // keep dotX and dotY within screen
  41. if(dotX < 0) {dotX = width;}
  42. if(dotX > width) {dotX = 0;}
  43. if(dotY < 0) {dotY = height;}
  44. if(dotY > height) {dotY = 0;}
  45.  
  46. // --------------------------------------------
  47. // Do something with output
  48. // --------------------------------------------
  49.  
  50. distance = dotY - 500;
  51. println (distance);
  52.  
  53. background(0,0,255);
  54. textSize(32);
  55. text("State: " + currentState + " Active!", 10, 30);
  56. text("Press 1,2 to switch to other state", 10, 70);
  57. text("Press up,down,left,right arrow keys ", 10, 110);
  58.  
  59. noStroke();
  60. fill(255,255,0);
  61. ellipse(dotX, dotY, 20, 20);
  62. ellipse(400, 500, 60, 60);
  63. }
  64.  
  65. void movieEvent(Movie m) {
  66. m.read();
  67. }
  68.  
  69. void endState3() {
  70. movie2.stop();
  71. }
Advertisement
RAW Paste Data Copied
Advertisement