Session 7: Add levels

Work plan

  • Conditions of change of level
  • Speed of the ball
  • Racket size
  • Countdown

Speed and size of the racket

We will add different levels of difficulty to the game, so it is becoming more complicated to move forward and not get bored.

Step by step Let’s do it step by step

  • Entering our Scratch account, we open the m2repte61 project and set it as m2repte71
  • Since we want the ball to go faster and faster, we have to create a variable called “speed”
  • We initialize the “speed” variable at the beginning of the program:
    We initialize the variable speed
  • Now that we have this variable, we change the block move 10 to move “speed” :
    Move your speed
  • Level management can be done in two ways, by time or by points. For example, we can make a change in level every 15 seconds or every 10 points
  • We do the management by points. Inside the loop where the logic of the program is, just after verifying that the ball touches the racket, we put these blocks:
    Increase speed by 3
  • Another element we can add to increase the difficulty is to reduce the size of the racket. However, since the program is in the ball and we want to act on another character, we will have to do it with the sending of a message, which we will have created previously, as we did in session 10 of module 1:
    Message Reduce racket
  • This message should be received by the racket, so we add this program to the racket. Let’s say that increasing -5 is the same as decreasing 5:
    Reduce racquet
  • We need to keep in mind that when we run the program again the size of the racket will be smaller. In order for this to happen, we must put this block just behind the green flag of the racket program:
    Set the size to 100%

Icon challenge Challenge 1:

We continue with the m2repte71 project and we have an increase in speed and a decrease in the size of the racket every 10 points (at 10 points, 20 points, 30 points …).

Icon trackTrack: Note that “every 10 points” is the same as saying when the number of points is multiple of 10. To detect if the points are multiple of 10, we can divide the points between 10 and check if the residue is 0. We can use this blog:
Waste


Icon challenge Challenge 2:

Let’s make a copy of the challenge that we have open m2repte71 with the name m2repte72 . In this challenge, the speed changes of the ball and the size of the racket must be managed based on the time that has elapsed taking advantage of the chronometer (instead of the points as in the previous challenge)


Time limit

In the previous session we worked with the stopwatch and we said that we could manage the time in a similar way but using a variable. The timer only allows us to increase the time automatically; With a time variable we can control it by increasing it (count on) or decrease (countdown).

Step by step Let’s do it step by step

  • We continue with the m2repte71 project
  • We create a variable called “time”
  • With this variable we can create a countdown, that we would do this way:
    Countdown
  • We insert this account back into our project so that each thing goes to its place. The initialization of the time at the beginning and what is inside the loop where the logic of the program is
  • This countdown should help us to finish the game when time reaches zero:
    Ends when time reaches 0

Icon challenge Challenge 3:

We continue with the m2repte71 project . As in terms of the score, we have increased the level (speed of the ball and size of the racket), we now increase the lives and the time available according to the points.


Icon project Our project grows …

The level control that we have worked on in our pong, that is, changing the speed of the ball, the size of the rackets, as well as changing lives and time depending on the points accumulated can also apply to our final challenge of pinball . We need to add to the description of our pinball as we want it to be the mechanics of the game in terms of scores, lives and levels. These are actually the instructions to play your pinball . At session 11 you will be asked that these instructions are clearly explained in the instructionssection of your project.


Glossary icon Because we are programmers and programmers we talk about …

  • Levels of play:  conditions that must be met to vary the complexity of the game. They are usually sequential and depend on defined variables.