Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let dino, cactus;
- let dinoSize, cactusSize;
- let groundY;
- let cactusSpeed;
- let jump;
- let inAir;
- let i;
- function setup() {
- createCanvas(400, 400);
- frameRate(60);
- jump = 0;
- inAir = 0;
- i = 20;
- groundY = height * 0.8;
- dinoSize = createVector(50, 100);
- dino = createVector(width * 0.15, groundY-dinoSize.y)
- strokeWeight(0);
- cactusSize = createVector(40, 50)
- cactus = createVector(width + cactusSize.x, groundY-cactusSize.y)
- cactusSpeed = 5;
- }
- function draw() {
- background(220);
- colidingCactus();
- fill(45, 125, 62) // рисуем землю
- rect(0, groundY, width, height - groundY)
- fill(80, 150, 80) // рисуем дино
- rect(dino.x, dino.y, dinoSize.x, dinoSize.y)
- fill(156, 59, 64) // рисуем кактус
- rect(cactus.x, cactus.y, cactusSize.x, cactusSize.y)
- cactus.x -= cactusSpeed;
- if(cactus.x < -cactusSize.x){
- cactus.x = width + cactusSize.x;
- }
- Jump();
- }
- function colidingCactus() {
- let dinoRDAx = dino.x + dinoSize.x;
- let dinoDAy = dino.y + dinoSize.y;
- let cactusRUAx = cactus.x + cactusSize.x;
- if (dinoRDAx > cactus.x && dinoDAy > cactus.y && dino.x < cactusRUAx && dinoDAy > cactus.y) {
- noLoop();
- }
- }
- function Jump() {
- if(keyIsDown(UP_ARROW) && inAir == 0){
- jump = 1;
- inAir = 1;
- }
- if(jump > 0){
- dino.y -= i;
- i--;
- if(i == 0){
- jump = -1;
- }
- }
- if(jump < 0){
- i++;
- dino.y += i;
- if(i == 20){
- jump = 0;
- inAir = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment