Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. var state = 0;
  2. var img;
  3. var player_img;
  4. var font;
  5. var player;
  6. var fish1;
  7. var fish2;
  8. var fish1_img;
  9. var fish2_img;
  10. var cat1;
  11. // 0 = START
  12. // 1 = MAIN
  13. // 2 = STOP
  14. var _startText;
  15. var background1;
  16. var blowfish;
  17. var blowfish_img
  18. var shark;
  19. var shark_img;
  20.  
  21. var score = 0;
  22.  
  23. function start() {
  24. background(47,47,47)
  25. image(img, 32, height/5, img.width/5, img.height/5);
  26.  
  27. textFont(font, 16)
  28. fill(255);
  29. text('Press SPACE to play', 50, height/2 +100)
  30. }
  31.  
  32. function main() {
  33. background(background1)
  34. if (keyIsDown(39) && player.position.x < width - 33 ) {
  35. player.setSpeed(5, 0);
  36. }
  37. else {
  38. player.setSpeed(0, 0);
  39. }
  40. if (keyIsDown(37) && player.position.x > + 33) {
  41. player.setSpeed(5, 180);
  42. }
  43. if (keyCode == 32) {
  44. player.setSpeed(0, 0);
  45. }
  46. drawSprites();
  47.  
  48. // move first fish across canvas
  49. fish1.position.y +=4
  50. if (fish1.position.y > height + 33){
  51. fish1.position.y =-33
  52. fish1.position.x = random(30, 300)
  53. }
  54.  
  55. if(player.overlap(fish1)){
  56. fish1.position.x = random(30, 300)
  57. fish1.position.y =-33
  58. score +=1
  59.  
  60. }
  61.  
  62. // move tropical fish across canvas
  63. fish2.position.y +=8
  64. if (fish2.position.y > height + 33){
  65. fish2.position.y =-33
  66. fish2.position.x = random(30, 300)
  67. }
  68.  
  69. if(player.overlap(fish2)){
  70. fish2.position.x = random(30, 300)
  71. fish2.position.y =-33
  72. score +=2
  73. }
  74.  
  75. // move blowfish across canvas
  76. blowfish.position.y +=4
  77. if (blowfish.position.y > height + 33){
  78. blowfish.position.y =-33
  79. blowfish.position.x = random(30, 300)
  80. }
  81.  
  82. if(player.overlap(blowfish)){
  83. blowfish.position.x = random(30, 300)
  84. blowfish.position.y =-33
  85. score +=1
  86.  
  87. }
  88.  
  89. // move shark across canvas
  90. fish1.position.y +=4
  91. if (fish1.position.y > height + 33){
  92. fish1.position.y =-33
  93. fish1.position.x = random(30, 300)
  94. }
  95.  
  96. if(player.overlap(fish1)){
  97. fish1.position.x = random(30, 300)
  98. fish1.position.y =-33
  99. score +=1
  100.  
  101. }
  102.  
  103. fill(255, 255, 255)
  104. textFont(font) && textSize(16) && textStyle(BOLD) && textAlign(RIGHT);
  105. text('Score :' + score, width/1.125, height/9);
  106. // textFont(font, 16)
  107. // fill(255);
  108. // text('Score: ', + score, 50, height/2 +100);
  109.  
  110.  
  111.  
  112. }
  113.  
  114. function stop() {
  115.  
  116. }
  117.  
  118. function fishMovement() {
  119.  
  120. }
  121.  
  122. function keyPressed() {
  123. if (state === 0 && keyCode === 32) {
  124. state = 1
  125. }
  126. }
  127.  
  128. function preload() {
  129. font = loadFont("prstart.ttf")
  130. img = loadImage("assets/cat catch logo.png");
  131. player_img = loadImage("assets/cat1.png");
  132. // create a sprite
  133. player = createSprite(200, 564);
  134. player.addImage(player_img);
  135. player.scale = 0.28;
  136.  
  137. fish1_img = loadImage('assets/fish.png')
  138. fish2_img = loadImage('assets/tropical fish.png')
  139. //create fish sprites
  140. fish1 = createSprite(200, 204);
  141. fish1.addImage(fish1_img);
  142. fish1.scale = 0.4;
  143. fish1.rotation = 270
  144. //create 2nd fish
  145. fish2 = createSprite(200, 204);
  146. fish2.addImage(fish2_img);
  147. fish2.scale = 0.4;
  148. fish2.rotation = 270
  149. background1 = loadImage('assets/background.PNG')
  150. blowfish = createSprite(200, 204);
  151. blowfish = loadImage('assets/blowfish.png')
  152. blowfish.addImage(blowfish_img)
  153. blowfish.scale = 0.4
  154. }
  155.  
  156. function setup() {
  157. createCanvas(400, 600)
  158.  
  159. }
  160.  
  161. function draw() {
  162. if (state === 0) {
  163. start()
  164. }
  165. else if (state === 1) {
  166. main()
  167. }
  168. else if (state === 2) {
  169. stop()
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement