Session 5: Add lives and punctuation to the pong

Work plan

  • Control the variable “lifes”
  • Point counter

We better control your lives

In the previous session we have seen what happened to us when we lost. We created a variable called “lives” that was decreasing every time we achieved it by adding -1 to this variable every time the ball did not touch the racket. But we have a problem, the game does not stop and lives start to dial negative numbers.

Icon tasksLet’s do it step by step

  • We enter our Scratch account and make a copy of our project m2 challenge41  and we change the name to m2repte51
  • In our project we have done that the game is repeated and that the lives decrease when the ball does not touch the racket. This repetition can be controlled in different ways but to prevent the game from continuing despite the end of the lives, we will have to use
    Repeat
  • Note that this repetition allows us to add control over the “ends” to an empty space. Within this empty space we will add a new element that belongs to the Operators block . From this blog we have already used in previous sessions the creation of random numbers
    Operators
  • Since we want the repetition to occur until the lives end, we will indicate this way:
    Control vines

Icon challenge Challenge 1:

We still have problems with the control of lives since if we do not control the position of the ball when it has not bounced on the racket, besides subtracting a life, it will continue to do so. Modify the m2repte51 project that we have open so that the ball returns to the initial position after subtracting a life and that it stops for a few seconds before moving back.

Icon track Track: We used the “waiting” block in module 1 in session 2 when we established dialogues between characters.


And now … we earn points

In addition to controlling how many lives we have left in the game, it is interesting to know how many times we can get the ball bouncing on the racket in the same life. To achieve this, we will add a point control.

Icon tasksLet’s do it step by step

  • We continue working on our m2repte51 project
  • We have to create a new variable that we will call “points” where we will accumulate the number of rebounds achieved before losing a life. We must not forget to mark this variable when we finish creating it so that it can be viewed on the screen
  • This variable “points” must start with a value of zero and must increase 1 each time the ball touches the racket:
    Control points

Icon challenge Challenge 2:

We continue working on our m2repte51 project   and add control points.

Icon trackTrack: every time the game begins, we have to put the point counter to 0. We have to combine the points with the lives. How do we organize the blogs?


Icon project Our project grows …

First of all, let’s take a look at these Scratch Cards to see if our pong evolves well. It is time to refer what has not just worked.

In the previous session we have already decided how many lives we want to give the players in our pinball project . Now that we know how to count the points, we should think what we want the game to do when the player reaches a certain number of points and add it to the description.


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

  • Operators: a block that contains the actions that allow us to perform operations, approximations, unions, exclusions, random numbers …