Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. fill = ('white')
  2. var score = 0
  3.  
  4. var health = 20
  5.  
  6. var yoda = {
  7. x: 50,
  8. y: 150,
  9. vel: 0.5,
  10. gravity: 0.6
  11. }
  12. random = (0, 400)
  13.  
  14. var seaguls = [
  15. {x: -200,y: 100},
  16. {x: -400,y: 200},
  17. {x: -600,y: 300},
  18. {x: -800,y: 250},
  19. {x: -1100,y: 200},
  20. ]
  21.  
  22. var platforms = [
  23. {x: 100, y:300},
  24. {x: 200,y: 200},
  25. {x: 300,y: 380},
  26. {x: 440, y:200},
  27. {x: 500,y: 350},
  28. {x: 600, y: 180},
  29. {x: 700,y: 100},
  30.  
  31.  
  32. ]
  33.  
  34. function setup() {
  35. createCanvas(400, 400);
  36. }
  37.  
  38.  
  39. //yoda jump
  40. function keyPressed() {
  41. if (keyCode == (UP_ARROW)) {
  42.  
  43. yoda.vel = -10;
  44.  
  45.  
  46. }}
  47.  
  48.  
  49.  
  50. function draw() {
  51. background(100, 100, 255)
  52.  
  53.  
  54. //yoda image
  55. //rotate( 1),
  56. fill('brown')
  57. rect(yoda.x, yoda.y, 30, 30, 5)
  58. line(yoda.x + 40, yoda.y + 40, yoda.x - 25, yoda.y);
  59. fill('lightgreen')
  60. ellipse(yoda.x + 20, yoda.y - 10, 50, 50);
  61. arc(yoda.x, yoda.y - 10, 25, 15, 60, HALF_PI);
  62. fill('black');
  63. ellipse(yoda.x + 32, yoda.y - 10, 10, 10);
  64. fill('lightgreen');;
  65. resetMatrix();
  66.  
  67. //yoda movement
  68. if (keyIsDown(DOWN_ARROW)) {
  69. yoda.y += 5;
  70. }
  71. if (keyIsDown(LEFT_ARROW)) {
  72. yoda.x -= 5;
  73. //platforms.x += 5;
  74. }
  75. if (keyIsDown(RIGHT_ARROW)) {
  76. yoda.x += 5;
  77. for (var platform of platforms) {
  78. platform.x -= 5;
  79. }
  80. }
  81. for (var seagul of seaguls)
  82. {
  83. drawSeagul(seagul.x, seagul.y)
  84. seagul.x += 2;
  85. if (seagul.x > 900 ) {seagul.x= seagul.x-random(1200, 4000)}
  86.  
  87. if (score > 200) {
  88. seagul.x +=4
  89. }
  90. if (score > 300) {
  91. seagul.x +=5
  92. }
  93. if (score > 600) {
  94. seagul.x +=8
  95. }
  96. }
  97.  
  98.  
  99.  
  100.  
  101. yoda.vel += yoda.gravity;
  102. for (var platform of platforms) {
  103. platform.x -= 1
  104. drawPlatform(platform.x, platform.y)
  105. if (platform.x < -100 ) {platform.x= platform.x+700}
  106.  
  107. if (score > 200) {
  108. platform.x -=2
  109. }
  110. if (score > 300) {
  111. platform.x -=3
  112. }
  113. if (score > 400) {
  114. platform.x -=5
  115. }
  116. }
  117. yoda.y += yoda.vel;
  118.  
  119. //score
  120. score += 0.5;
  121. text('score ' + score, 300, 20)
  122. text('health ' + health, 200, 20)
  123. }
  124. //seagul
  125.  
  126. function drawSeagul(x, y) {
  127. fill('white')
  128. scale(1, 1);
  129. ellipse(x -20, y + 20, 80, 20);
  130. ellipse(x - 20, y+20, 50, 50);
  131. ellipse(x, y, 50, 50);
  132. fill('black')
  133. ellipse(x -10, y, 10, 10);
  134. fill('yellow')
  135. rect(x + 5, y, 20, 12, 10);
  136. resetMatrix();
  137.  
  138. //yoda hits seagul or falls of platform - health low
  139. if (dist(yoda.x, yoda.y , x , y) < 50)
  140. {
  141. score = 0 ,
  142. health -=1 ,
  143. fill('red')
  144. rect( 0, 0 , 400, 400);
  145. }
  146.  
  147. if (yoda.y >400 )
  148. {
  149. score = 0 ,
  150. health -=1 ,
  151. fill('red')
  152. rect( 0, 0 , 400, 400);
  153. }
  154.  
  155. if
  156. (health < 0) {
  157. fill('red')
  158. rect( 0, 0 , 400, 400);
  159.  
  160. }
  161.  
  162.  
  163.  
  164.  
  165. //platform draw and logic
  166. }
  167. function drawPlatform(x, y) {
  168. fill('lightgreen')
  169. if (yoda.y > y - 30 && yoda.y < y) {
  170. if (yoda.x > x - 30 && yoda.x < x + 50)
  171. {
  172. fill('yellow'); yoda.vel = 0;
  173. if (keyIsDown(DOWN_ARROW)) {
  174. yoda.y -= 5;
  175. }
  176. if (keyIsDown(UP_ARROW)) {
  177. yoda.y -=120;
  178. yoda.vel =-5
  179.  
  180.  
  181. }
  182. }
  183. }
  184. rect(x, y, 50, 25, 20)
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement