Advertisement
Guest User

bunny

a guest
May 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. var bunny = createSprite(200, 345);
  2. bunny.setAnimation("bunny");
  3.  
  4. var carrot = createSprite(450, randomNumber(50, 350));
  5. carrot.setAnimation("carrot");
  6. carrot.velocityX = -5;
  7.  
  8. var score = 0;
  9.  
  10. function draw() {
  11. background("lightblue");
  12. stroke("black");
  13. fill("green");
  14. rect(0, 390, 400, 10);
  15.  
  16. // draw score
  17. fill("black");
  18. textSize(20);
  19. text("Score:", 5, 5, 20, 20);
  20. text(score , 70, 5, 20, 20);
  21.  
  22. // loop carrot back to right side of screen
  23. if (carrot.x < -25) {
  24. carrot.x = 450;
  25. carrot.y = randomNumber(10, 390);
  26. }
  27.  
  28. // make bunny jump when up arrow is pressed
  29. if (bunny.y > 344) {
  30. if (keyWentDown("up")) {
  31. bunny.velocityY = -8;
  32. } else {
  33. bunny.velocityY = 0;
  34. }
  35. }
  36. if (bunny.y < 80) {
  37. bunny.velocityY = 8;
  38. }
  39.  
  40. // when bunny touches carrot
  41. // add 1 to score and put carrot back off screen
  42. if (bunny.isTouching(carrot)) {
  43. score = score + 1;
  44. bunny.x = 450;
  45. bunny.y = randomNumber(10, 390);
  46. }
  47.  
  48. drawSprites();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement