Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1.  
  2. float rot = 0;
  3. boolean upp, ner;
  4. int antal = 30;
  5.  
  6. int[] posX = new int[antal];
  7. int[] posY = new int[antal];
  8.  
  9. void hinder(){
  10. background( 0 );
  11. fill(255, 0, 0);
  12. for(int i = 0; i < antal; i++){
  13. ellipse(posX[i], posY[i], 40, 40);
  14. }
  15. }
  16.  
  17. void theWhale(int direction){
  18. if(go){
  19. int d = direction;
  20. setVelocity(d);
  21.  
  22. //Ska ej rotera när den står still
  23. if( velocity.x > 0.05) rot = velocity.heading2D();
  24. fill( 200, 200, 0 );
  25. noStroke();
  26.  
  27. pushMatrix();
  28. translate( whale.x, whale.y );
  29. rotate(rot);
  30. ellipse( 0, 0, 40, 20 );
  31. popMatrix();
  32. }
  33. }
  34.  
  35. //Sätt hastigheten
  36. void setVelocity(int direction){
  37. int d = direction;
  38. switch(d){
  39. case -1:
  40. acceleration.set(0.13, 0.05, 0);
  41. break;
  42. case 1:
  43. acceleration.set(0.13, -0.05, 0);
  44. break;
  45. case 0:
  46. acceleration.x = 0.13;
  47. break;
  48. case 3:
  49. acceleration.x = -0.015;
  50. //Jag msåte veta när den går upp och när den går ner när den ska stanna
  51. //så att den inte går åt motsatt håll
  52. if(acceleration.y > 0){
  53. acceleration.y = -(acceleration.y+0.02);
  54. upp = true;
  55. ner = false;
  56. }
  57. else if(acceleration.y < 0){
  58. acceleration.y = -(acceleration.y-0.02);
  59. upp = false;
  60. ner = true;
  61. }
  62. else{
  63. upp = false;
  64. ner = false;
  65. }
  66. break;
  67. }
  68.  
  69.  
  70.  
  71. //Ska ej röra på sig när den står still
  72. if(velocity.x<0){
  73. acceleration.set(0, 0, 0);
  74. velocity.set(0, 0, 0);
  75. }
  76. else if(velocity.x > 2) velocity.x = 2;
  77.  
  78. if(upp && velocity.y<0){
  79. velocity.y = 0;
  80. acceleration.y = 0;
  81. }
  82. else if(ner && velocity.y>0){
  83. velocity.y = 0;
  84. acceleration.y = 0;
  85. }
  86. //if(velocity.y > 2) velocity.y = 2;
  87. velocity.add(acceleration);
  88. //println(velocity.y);
  89. //println("Upp: " + upp + " Ner: " + ner);
  90. whale.add(velocity);
  91. if(whale.x > width) whale.x = 0;
  92. if(whale.y > height) whale.y = 0;
  93. else if(whale.y <0) whale.y = height;
  94. //println(velocity.x);
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement