{"id":10154,"date":"2018-09-24T13:26:04","date_gmt":"2018-09-24T11:26:04","guid":{"rendered":"http:\/\/agora.xtec.cat\/esc-cancoll\/?page_id=10154"},"modified":"2018-12-05T14:57:00","modified_gmt":"2018-12-05T13:57:00","slug":"session-4","status":"publish","type":"page","link":"https:\/\/agora.xtec.cat\/esc-cancoll\/curs-scratch-primaria\/module-2-a-game-or-two\/session-4\/","title":{"rendered":"Session 4: When is the pong finished?"},"content":{"rendered":"<h2><span id=\"Pla_de_treball\">Work plan<\/span><\/h2>\n<div>\n<ul>\n<li>Control of the end of the game<\/li>\n<li>The variable concept<\/li>\n<li>The lives in the game<\/li>\n<\/ul>\n<h2><span id=\"No_sempre_encertem_amb_la_raqueta\"><strong>We do not always agree with the racket<\/strong><\/span><\/h2>\n<p>When we play in the pong and we move the racket, we may not be right to play the ball.\u00a0We have to get control when this happens to know that the game is over and, as we will see later, decide whether we can continue or not.<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-icona_tasques.png\" alt=\"Icon tasks\" width=\"32\" \/><strong>Let&#8217;s do it step by step<\/strong><\/p>\n<div>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li>We enter our Scratch account and make a copy of our project\u00a0<strong>m2\u00a0<\/strong><strong>challenge31<\/strong>\u00a0\u00a0and we change the name to\u00a0<strong>m2repte41<\/strong><\/li>\n<li>In this project we surely have two rackets, one vertical and one horizontal.\u00a0We eliminate the vertical and we stand only with the horizontal racket<\/li>\n<li>We will add the &#8220;line of death&#8221; to the bottom of the screen.\u00a0When the ball touches this line the game will end<\/li>\n<li>We will use the\u00a0<strong>Sensors<\/strong>\u00a0to detect when there is this interaction between the ball and the &#8220;line of death.&#8221;\u00a0To do so, first of all we have to create a new character that will be precisely this line and that it must be of the same length as the width of the screen and the thickness and color that we like the most.\u00a0We need to achieve this result<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong18.png\" alt=\"Line of death\" width=\"403\" height=\"247\" \/><\/p>\n<ul>\n<li>Now only the interaction between the ball and the line of death is necessary.\u00a0We can do it in different ways, using conditionals or with an iterative structure (the two possibilities we saw in module 1 in session 9).\u00a0Whether we use a possibility like the other, we will have to add the sensors that control the interaction of the ball with the &#8220;line of death&#8221;, considering it as a character or taking into account its color<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong19.png\" alt=\"Conditional\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong20.png\" alt=\"Iteration\" \/><\/li>\n<\/ul>\n<\/div>\n<hr \/>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-icona_repte.png\" alt=\"Icon challenge\" width=\"32\" \/>\u00a0<strong>Challenge 1:<\/strong><\/p>\n<p>The game also ends when the ball is at a height lower than the racket, although it does not reach the &#8220;line of death&#8221;, since there is no possibility of reacting and recovering.\u00a0Modify the\u00a0<strong>m2repte41<\/strong>\u00a0project\u00a0that we have open so that the game ends when the ball is lower than the racket.<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-icona_pista.png\" alt=\"Icon track\" width=\"24\" \/>\u00a0Track: We have to check if the coordinate &#8220;y&#8221; (vertical position) of the ball is less than the &#8220;y&#8221; coordinate of the racket.<\/p>\n<hr \/>\n<h2><span id=\"Volem_jugar_mes_d8217una_vegada8230\">We want to play more than once &#8230;<\/span><\/h2>\n<p>That the pong is finished at the moment when we can not return the ball, it is not fun.\u00a0We have to have more opportunities to continue playing for a while and thus we will be more capable.\u00a0To achieve this, we will add &#8220;lives&#8221; in our game.<\/p>\n<p>These &#8220;lives&#8221; have to be decreasing each time we lose, that is, their value will vary.\u00a0This means that if we start the game with 4 lives and we lose, we will stay only in three and so on.\u00a0In order to control the variation of this value, we must use a new concept, the one of\u00a0<strong>variable<\/strong>\u00a0that is within the\u00a0<strong>Data<\/strong>\u00a0block\u00a0.<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong21.png\" alt=\"Block data\" \/><\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-icona_tasques.png\" alt=\"Icon tasks\" width=\"32\" \/><strong>Let&#8217;s do it step by step<\/strong><\/p>\n<div>\n<ul>\n<li>We continue working on our\u00a0<strong>m2repte project41<\/strong><\/li>\n<li>Let&#8217;s go to the data block and create a variable with the name of\u00a0<strong>lives<\/strong>\u00a0(or any other name we want, although it is recommended to put names that relate to what we want to keep in order to make the program more clear to follow).<\/li>\n<li>Once we have created a variable, the blog offers the following possibilities:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong22.png\" alt=\"Variable creation\" \/><\/li>\n<li>Once the variable has been created we have to give it an initial value that will be the amount of opportunities we have to lose before the game is finished.<\/li>\n<li>So that each time we start the game the variable &#8220;lives&#8221; start from the initial value we have decided, we must place the corresponding block to the assignment just after the green flag.<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong39.png\" alt=\"Variable creation\" \/><\/li>\n<li>The value of the variable appears on the screen if we have marked it when defining it.\u00a0We can change the way we view it when we are running the project by clicking on it.<\/li>\n<\/ul>\n<\/div>\n<hr \/>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-icona_repte.png\" alt=\"Icon challenge\" width=\"32\" \/>\u00a0<strong>Challenge 2:<\/strong><\/p>\n<p>We add in our\u00a0<strong>m2repte41<\/strong>\u00a0project\u00a0the control of lives, so that they are decreasing every time the ball does not bounce in the racket.\u00a0<strong>We will not control now the end of the game when the lives are over<\/strong>\u00a0, we will do it in the next session.<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-icona_pista.png\" alt=\"Icon track\" width=\"24\" \/>Track: once the variable &#8220;vides&#8221; has been created and we have established its initial value, we must reduce our lives each time we lose.\u00a0At Scratch there is no resting operation, we can do it equally by adding a negative number (-1).\u00a0We will have to use an iteration to repeat the action.<\/p>\n<hr \/>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-icona_projecte2.png\" alt=\"Icon project\" width=\"32\" \/>\u00a0<strong>Our project grows &#8230;<\/strong><\/p>\n<p>It is time to review the description we have made in our\u00a0<b>pinball<\/b>\u00a0project\u00a0considering that we need to decide and add the concept of &#8220;lives.&#8221;\u00a0How many opportunities do we want to give to the players?\u00a0What do we want to happen when the lives end?<\/p>\n<hr \/>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-icona_glosari.png\" alt=\"Glossary icon\" width=\"32\" \/>\u00a0<strong>Because we are programmers and programmers we talk about &#8230;<\/strong><\/p>\n<div>\n<ul>\n<li><b>Variable: These<\/b>\u00a0are spaces where we can store values that will be modified (variant) throughout the program, that is, they do not have a fixed value.<\/li>\n<\/ul>\n<\/div>\n<div class=\"addtoany_share_save_container addtoany_content_bottom\">\n<div class=\"a2a_kit a2a_kit_size_25 addtoany_list\" data-a2a-url=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/curs-scratch-primaria\/modul-2\/sessio-4\/\" data-a2a-title=\"Sessi\u00f3 4.  Quan s\u2019acaba el pong?\"><a class=\"a2a_button_facebook\" title=\"Facebook\" href=\"http:\/\/projectes.xtec.cat\/#facebook\" target=\"_blank\" rel=\"nofollow noopener\"><span class=\"a2a_label\">Facebook<\/span><\/a><a class=\"a2a_button_twitter\" title=\"Twitter\" href=\"http:\/\/projectes.xtec.cat\/#twitter\" target=\"_blank\" rel=\"nofollow noopener\"><span class=\"a2a_label\">Twitter<\/span><\/a><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Work plan<\/p>\n<ul>\n<li>Control of the end of the game<\/li>\n<li>The variable concept<\/li>\n<li>The lives in the game<\/li>\n<\/ul>\n<p>We do not always agree with the racket<br \/>\nWhen we play in the pong and we move the racket, we may not be right to play the ball.\u00a0We have to get control when&hellip;  <a href=\"https:\/\/agora.xtec.cat\/esc-cancoll\/curs-scratch-primaria\/module-2-a-game-or-two\/session-4\/\" title=\"Read Session 4: When is the pong finished?\">Llegeix m\u00e9s\u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":10141,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"class_list":["post-10154","page","type-page","status-publish","hentry"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/pages\/10154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/comments?post=10154"}],"version-history":[{"count":2,"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/pages\/10154\/revisions"}],"predecessor-version":[{"id":10183,"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/pages\/10154\/revisions\/10183"}],"up":[{"embeddable":true,"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/pages\/10141"}],"wp:attachment":[{"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/media?parent=10154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}