Laitofai

Untitled

Jul 24th, 2022
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. let dino, cactus;
  2. let dinoSize, cactusSize;
  3. let groundY;
  4. let cactusSpeed;
  5. let jump;
  6. let inAir;
  7. let i;
  8.  
  9. function setup() {
  10. createCanvas(400, 400);
  11. frameRate(60);
  12. jump = 0;
  13. inAir = 0;
  14. i = 20;
  15. groundY = height * 0.8;
  16.  
  17. dinoSize = createVector(50, 100);
  18. dino = createVector(width * 0.15, groundY-dinoSize.y)
  19.  
  20. strokeWeight(0);
  21.  
  22. cactusSize = createVector(40, 50)
  23. cactus = createVector(width + cactusSize.x, groundY-cactusSize.y)
  24. cactusSpeed = 5;
  25. }
  26.  
  27. function draw() {
  28. background(220);
  29. colidingCactus();
  30.  
  31. fill(45, 125, 62) // рисуем землю
  32. rect(0, groundY, width, height - groundY)
  33.  
  34. fill(80, 150, 80) // рисуем дино
  35. rect(dino.x, dino.y, dinoSize.x, dinoSize.y)
  36.  
  37. fill(156, 59, 64) // рисуем кактус
  38. rect(cactus.x, cactus.y, cactusSize.x, cactusSize.y)
  39. cactus.x -= cactusSpeed;
  40. if(cactus.x < -cactusSize.x){
  41. cactus.x = width + cactusSize.x;
  42. }
  43. Jump();
  44. }
  45.  
  46. function colidingCactus() {
  47. let dinoRDAx = dino.x + dinoSize.x;
  48. let dinoDAy = dino.y + dinoSize.y;
  49. let cactusRUAx = cactus.x + cactusSize.x;
  50.  
  51. if (dinoRDAx > cactus.x && dinoDAy > cactus.y && dino.x < cactusRUAx && dinoDAy > cactus.y) {
  52. noLoop();
  53. }
  54. }
  55.  
  56. function Jump() {
  57. if(keyIsDown(UP_ARROW) && inAir == 0){
  58. jump = 1;
  59. inAir = 1;
  60. }
  61. if(jump > 0){
  62. dino.y -= i;
  63. i--;
  64. if(i == 0){
  65. jump = -1;
  66. }
  67. }
  68. if(jump < 0){
  69. i++;
  70. dino.y += i;
  71. if(i == 20){
  72. jump = 0;
  73. inAir = 0;
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment