Skip to content

kaylee

My feedback

1 result found

  1. 377 votes
    Vote

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
    You have left! (?) (thinking…)
    192 comments  ·  General » Other  ·  Admin →
    How important is this to you?

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
    An error occurred while saving the comment
    kaylee commented  · 

    Tennis Smash
    fill('tenniscourt2')

    // Add the player at the bottom of the court
    var bottomOfCourt = 900;
    var playerPosition = 650;
    var playerSize = 200;
    var player = stamp('hamster2', playerPosition, bottomOfCourt, playerSize);

    // Add the ball at the top of the court
    var topOfCourt = 510;
    var ballPosition = random(200, 500);
    var ballSize = 100;
    var ball = stamp('buttonpink', ballPosition, topOfCourt, ballSize);

    // Add the score at the top of the screen
    var score = 0;
    var sb = text(score, 100, 50, 'white');

    function touching() {

    // 'x' is the x-coordinate of your mouse pointer
    var xTapped = x;

    // Work out how long the player is going to take
    // to move to the mouse pointer
    var distance = Math.abs(player.x - x);
    var speed = 2;
    var time = (distance / speed);

    // Move the player to the mouse pointer
    player.move(xTapped, player.y, time);
    }

    // Repeat this over and over again...
    var scoreLocked = false;
    function loop() {

    // If the player is touching the ball:
    if (player.hits(ball)) {

    // Bounce the ball back to the top of the court
    ball.move(
    random(200, 450),
    topOfCourt,
    random(800, 2000)
    )

    // Increase the user's score
    if (!scoreLocked) {
    score = score + 1
    sb.change(score)
    }

    scoreLocked = true;
    setTimeout(function() {
    scoreLocked = false;
    }, 100);
    }

    // If the ball is at the top of the court...
    if (ball.y == topOfCourt) {

    // Bounce it back
    ball.move(random(80, 700), 980, 1200);
    }

    // If the ball gets past the player...
    if (ball.y > (bottomOfCourt + 10)) {

    // Explode the ball
    ball.explode();

    // Stop the main loop
    loop = null;

    // Change the background
    fill('zam', 0);
    }
    }

    kaylee supported this idea  · 
    An error occurred while saving the comment
    kaylee commented  · 

    5282

Feedback and Knowledge Base