{"id":10143,"date":"2018-09-24T13:24:54","date_gmt":"2018-09-24T11:24:54","guid":{"rendered":"http:\/\/agora.xtec.cat\/esc-cancoll\/?page_id=10143"},"modified":"2018-10-10T15:11:27","modified_gmt":"2018-10-10T13:11:27","slug":"session-1","status":"publish","type":"page","link":"https:\/\/agora.xtec.cat\/esc-cancoll\/curs-scratch-primaria\/module-2-a-game-or-two\/session-1\/","title":{"rendered":"Session 1: Start the game of the Pong"},"content":{"rendered":"<h2><span id=\"Pla_de_treball\">Work plan<\/span><\/h2>\n<div>\n<ul>\n<li>Know the game of the pong<\/li>\n<li>Customize the characters<\/li>\n<li>Movement of the characters<\/li>\n<\/ul>\n<\/div>\n<h2><span id=\"El_joc_del_Pong_La_pilota\">The Pong game: The ball<\/span><\/h2>\n<p>The Pong is one of the first videogames that was created.\u00a0You can have levels of difficulty, one or two players, penalizing or adding lives &#8230; In this module we will discover the basic tools to build one.\u00a0We will start with a simple version and from there we will be doing it more and more complex.\u00a0We see an example of Pong made with the Scratch:<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/uploads.scratch.mit.edu\/projects\/thumbnails\/1779\/0336.png\" \/><\/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=\"Step by step\" width=\"32\" \/>\u00a0<strong>Let&#8217;s do it step by step<\/strong><\/p>\n<div>\n<ul>\n<li>We entered our Scratch account and created a new project with the name\u00a0<strong>m2repte11<\/strong><\/li>\n<li>We choose two new characters from the gallery, which will be the ball and the racket, we can choose the characters &#8220;Ball&#8221; and &#8220;Paddle&#8221;<\/li>\n<li>The ball must move around the stage, so if it touches any of the walls it has to bounce.\u00a0We already saw how to do it in module 1:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong01.png\" alt=\"Move and bounce\" \/><\/li>\n<li>We have to put an initial position on it, which we must always do with all the characters.\u00a0If we do not do it, the character will start wherever he lasted.<\/li>\n<li>We also have to tell the ball in which direction we want it to start.\u00a0If we do not say anything, it will only go from right to left which is the default address:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong02.png\" alt=\"Initial values\" \/><\/li>\n<\/ul>\n<\/div>\n<p><strong>Challenge 1<\/strong>\u00a0<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\" \/><\/p>\n<p>As we have the ball now it always does the same route;\u00a0predictable and boring.\u00a0Let the starting point be random, but that the &#8220;y&#8221; is always above 100. We also make the direction not fixed, but rather it is random, but starting at the bottom, for example, between -60 and 60<\/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: Let&#8217;s remember the\u00a0<strong>random number<\/strong>\u00a0operator\u00a0and the &#8220;wind rose&#8221; of the Scratch directions that we saw in module 1 in session 7.<\/p>\n<hr \/>\n<h2><span id=\"I_la_raqueta\">And the racket?<\/span><\/h2>\n<p>Now that we have the program of the ball, we need to program the movement of the racket.<\/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=\"Step by step\" width=\"32\" \/>\u00a0<strong>Let&#8217;s do it step by step<\/strong><\/p>\n<div>\n<ul>\n<li>We continue with the project\u00a0<strong>m2repte11<\/strong><\/li>\n<li>An option to program the movement of the racket is to use the position of the mouse, which we can know with the\u00a0<strong>mouse<\/strong>block\u00a0<strong>X<\/strong>\u00a0of the category\u00a0<strong>Sensors<\/strong>\u00a0:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-sensors_ratolix.png\" alt=\"Value X of the mouse\" \/><\/li>\n<li>In this way, the racket program would look like this:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong03.png\" alt=\"Movement of the racket with the mouse position\" \/><\/li>\n<li>Another option we can use is to move the racket with the keyboard.\u00a0To do this we use keyboard events:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-esdeveniments_fletxaesquerra.png\" alt=\"Pressing left arrow\" \/>\u00a0<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-esdeveniments_fletxadreta.png\" alt=\"Pressing the right arrow\" \/><\/li>\n<li>In this way, the racket program would look like this:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong04.png\" alt=\"Racket movement with keyboard events\" \/><\/li>\n<\/ul>\n<\/div>\n<hr \/>\n<p><strong>Challenge 2<\/strong>\u00a0<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\" \/><\/p>\n<p>When we tested this last program of the racket we see that if we keep one of the keys pressed there is a small movement, then a small pause and finally the continuous movement of the racket.\u00a0We have to solve it using the keyboard sensors at\u00a0<strong>m2repte11<\/strong>\u00a0:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-sensors_fletxaesquerra.png\" alt=\"Sensor left arrow\" \/>\u00a0<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-sensors_fletxadreta.png\" alt=\"Sensor right arrow\" \/><\/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: Sensors should always be used within a loop so that the program is continually checking if it is activated:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong05.png\" alt=\"Conditional within loop\" \/><\/p>\n<h2><\/h2>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Work plan<\/p>\n<ul>\n<li>Know the game of the pong<\/li>\n<li>Customize the characters<\/li>\n<li>Movement of the characters<\/li>\n<\/ul>\n<p>The Pong game: The ball<br \/>\nThe Pong is one of the first videogames that was created.\u00a0You can have levels of difficulty, one or two players, penalizing or adding lives &#8230; In this module we will&hellip;  <a href=\"https:\/\/agora.xtec.cat\/esc-cancoll\/curs-scratch-primaria\/module-2-a-game-or-two\/session-1\/\" title=\"Read Session 1: Start the game of the Pong\">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-10143","page","type-page","status-publish","hentry"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/pages\/10143","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=10143"}],"version-history":[{"count":3,"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/pages\/10143\/revisions"}],"predecessor-version":[{"id":10178,"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/pages\/10143\/revisions\/10178"}],"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=10143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}