Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var bunny = createSprite(200, 345);
- bunny.setAnimation("bunny");
- var carrot = createSprite(450, randomNumber(50, 350));
- carrot.setAnimation("carrot");
- carrot.velocityX = -5;
- var score = 0;
- function draw() {
- background("lightblue");
- stroke("black");
- fill("green");
- rect(0, 390, 400, 10);
- // draw score
- fill("black");
- textSize(20);
- text("Score:", 5, 5, 20, 20);
- text(score , 70, 5, 20, 20);
- // loop carrot back to right side of screen
- if (carrot.x < -25) {
- carrot.x = 450;
- carrot.y = randomNumber(10, 390);
- }
- // make bunny jump when up arrow is pressed
- if (bunny.y > 344) {
- if (keyWentDown("up")) {
- bunny.velocityY = -8;
- } else {
- bunny.velocityY = 0;
- }
- }
- if (bunny.y < 80) {
- bunny.velocityY = 8;
- }
- // when bunny touches carrot
- // add 1 to score and put carrot back off screen
- if (bunny.isTouching(carrot)) {
- score = score + 1;
- bunny.x = 450;
- bunny.y = randomNumber(10, 390);
- }
- drawSprites();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement