{"id":10162,"date":"2018-09-24T13:27:10","date_gmt":"2018-09-24T11:27:10","guid":{"rendered":"http:\/\/agora.xtec.cat\/esc-cancoll\/?page_id=10162"},"modified":"2019-02-20T12:52:16","modified_gmt":"2019-02-20T11:52:16","slug":"session-8","status":"publish","type":"page","link":"https:\/\/agora.xtec.cat\/esc-cancoll\/curs-scratch-primaria\/module-2-a-game-or-two\/session-8\/","title":{"rendered":"Session 8: We play one against one"},"content":{"rendered":"<h2><span id=\"Pla_de_treball\">Work plan<\/span><\/h2>\n<div>\n<ul>\n<li>We add players<\/li>\n<li>We limit the playing field<\/li>\n<\/ul>\n<h2><span id=\"Dos_jugadors\">Two players<\/span><\/h2>\n<p>So far we have programmed a solo game against the ball.\u00a0Let&#8217;s see how we can do to play more players at the same time.<\/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>Entering our Scratch account, we open the\u00a0<strong>m2repte71<\/strong>\u00a0project\u00a0and set it as\u00a0<strong>m2repte81<\/strong><\/li>\n<li>In order for two players to take, for example, the original Pong made by Atari in 1972:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong45.jpg\" alt=\"Atari 1972\" \/><\/li>\n<li>We need two rackets, and they are vertical.\u00a0So, we turn 90 degrees the racket that we currently have and we double it to have two.\u00a0We put one on each side of the field.\u00a0Remember to place the center of the dress wherever you touch<\/li>\n<li>Each of the rackets must be moved independently.\u00a0We can maintain that the racquet on the right is moved with the arrow keys on the keyboard, while the left racket can be moved, for example, with the &#8220;W&#8221; (up) and &#8220;S&#8221; keys (to go down )<\/li>\n<li>We need two lines of death.\u00a0Therefore, we modify the line of death that we have right now, we duplicate it and put one in each side of the field, just by touching the edge<\/li>\n<li>We need two variables to count each player&#8217;s points separately.\u00a0We create the variables &#8220;player 1&#8221; and &#8220;player 2&#8221;<\/li>\n<li>We consider that the player on the left is &#8220;player 1&#8221; and adds a point when the ball touches the line of death from the right.\u00a0Consequently, the player on the right is &#8220;player 2&#8221; and will add a point when the ball touches the line of the left&#8217;s death<\/li>\n<li>Our screen of the Pong should stay more or less like this:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong46.jpg\" alt=\"Pong two players\" \/><\/li>\n<li>We need to modify the logic of the program by replacing the variable &#8220;points&#8221; for the two new variables we have created.\u00a0These two variables have to be initialized to zero at the beginning of the program and we have to do that they are increased when the ball touches the line of the opposite death<\/li>\n<li>The end of game condition must also be changed so that the game ends when one of the players reaches, for example, at 15 points<\/li>\n<li>We can also maintain the increase of the difficulty so that when a player arrives at 5 or 10 points his racket is made a little smaller<\/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>Let&#8217;s make a copy of the\u00a0<strong>m2repte81<\/strong>\u00a0project\u00a0and set it as\u00a0<strong>m2repte82.\u00a0<\/strong>We modify it so that four players can play as if it were a tennis match, where there are two more advanced players and two more behind them:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong47.jpg\" alt=\"Pong four tennis players\" \/><\/p>\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>Let&#8217;s make a copy of the\u00a0<strong>m2repte81<\/strong>\u00a0project\u00a0and set it as\u00a0<strong>m2repte83.\u00a0<\/strong>We modify it so that four players can play cooperatively where the objective is to make the maximum number of racket hits between all four without touching any edge:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-pong48.jpg\" alt=\"Pong four cooperative players\" \/><\/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: Since the goal is not to touch any edge, the game we can do with lines of death or controlling the contact with the edges:<br \/>\n<img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/projectes.xtec.cat\/programacioirobotica\/wp-content\/uploads\/usu604\/2017\/06\/scratch-sensors_tocantvora.png\" alt=\"Touching edge\" \/><\/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>Our\u00a0<b>pinball<\/b>\u00a0project\u00a0\u00a0will also have to take into account two players, since we will have to position both sides of the output hole two blades to prevent the ball from falling too fast and to push it up again.\u00a0We must add this fact to the description that we are developing.<\/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>Controls:<\/b>\u00a0defined keys to interact on the game by directing some characters.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Work plan<\/p>\n<ul>\n<li>We add players<\/li>\n<li>We limit the playing field<\/li>\n<\/ul>\n<p>Two players<br \/>\nSo far we have programmed a solo game against the ball.\u00a0Let&#8217;s see how we can do to play more players at the same time.<br \/>\n\u00a0Let&#8217;s do it step by step<\/p>\n<ul>\n<li>Entering our Scratch account, we open the\u00a0m2repte71\u00a0project\u00a0and set it&hellip;  <a href=\"https:\/\/agora.xtec.cat\/esc-cancoll\/curs-scratch-primaria\/module-2-a-game-or-two\/session-8\/\" title=\"Read Session 8: We play one against one\">Llegeix m\u00e9s\u00bb<\/a><br \/>\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-10162","page","type-page","status-publish","hentry"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/pages\/10162","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=10162"}],"version-history":[{"count":2,"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/pages\/10162\/revisions"}],"predecessor-version":[{"id":10187,"href":"https:\/\/agora.xtec.cat\/esc-cancoll\/wp-json\/wp\/v2\/pages\/10162\/revisions\/10187"}],"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=10162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}