{"id":1,"date":"2018-07-09T00:33:22","date_gmt":"2018-07-09T00:33:22","guid":{"rendered":"http:\/\/www.projectimmerse.com\/?p=1"},"modified":"2020-06-16T22:40:38","modified_gmt":"2020-06-16T22:40:38","slug":"building-a-tetris-game-with-javascript","status":"publish","type":"post","link":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/","title":{"rendered":"Building a Tetris Game with Javascript"},"content":{"rendered":"<p>Welcome to my first post, what better way to start with a super complex but fun project. Before I start, I&#8217;d like to give credit to the original creator of this game &#8211; Pontus. Feel free to visit his <a href=\"https:\/\/github.com\/meth-meth-method\" title=\"Github Account\">Github<\/a> and <a href=\"https:\/\/www.youtube.com\/channel\/UC8A0M0eDttdB11MHxX58vXQ\" title=\"Youtube Channel\">Youtube Channel<\/a> for more of his projects and videos. <\/p>\n<p>My intent is to complete this project and provide an unbiased review.<\/p>\n<p><!--more--><\/p>\n<p>Now, a few things to note before we get started. This project assumes you are armed with ES6 and functional programming knowledge, besides this the directory structure is pretty straightforward. The video itself is a good 51 minutes and 34 seconds, so buckle up, this will be quite the ride.<\/p>\n<p>The markup itself is super simple:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;title&gt;Tetris&lt;\/title&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;canvas id=&quot;tetris&quot; width=&quot;240&quot; height=&quot;400&quot;&gt;&lt;\/canvas&gt;\r\n    &lt;script src=&quot;tetris.js&quot;&gt;&lt;\/script&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>And the first few lines of Javascript:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nconst canvas = document.getElementById('tetris');\r\nconst context = canvas.getContext('2d');\r\n\r\ncontext.fillStyle = '#000000';\r\ncontext.fillRect = (0, 0, canvas.width, canvas.height);\r\n<\/pre>\n<h2>The Canvas Element<\/h2>\n<p>Just make sure the <strong>canvas<\/strong> element is on your page, this allows access to methods and properties associated with the canvas object. This is basically the basic foundation of the game and a thorough understanding of this fundamental concept is paramount to building anything on canvas. <\/p>\n<h2>The fillRect() method<\/h2>\n<p><strong>fillRect(x-axis, y-axis, canvas width, canvas height)<\/strong><\/p>\n<p>This method takes 4 arguments. <\/p>\n<ul>\n<li>An integer for the x axis<\/li>\n<li>An integer for the y axis<\/li>\n<li>The width of the canvas<\/li>\n<li>The height of the canvas<\/li>\n<\/ul>\n<p>The result should look like the following image below. Very simple but foundational concept in constructing a canvas object via javascript.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.projectimmerse.com\/wp-content\/uploads\/2018\/07\/tetris-canvas1-300x217.png\" alt=\"\" width=\"300\" height=\"217\" class=\"aligncenter size-medium wp-image-29\" srcset=\"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-canvas1-300x217.png 300w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-canvas1-768x555.png 768w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-canvas1-80x58.png 80w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-canvas1.png 900w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<h2>Tetris Pieces<\/h2>\n<p>Yup let&#8217;s reference some visuals, all you needed to do is google &#8220;tetris pieces&#8221; and you get some useful images. I went ahead and snagged one for visual reference. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.projectimmerse.com\/wp-content\/uploads\/2018\/07\/tetris-pieces-300x216.png\" alt=\"\" width=\"300\" height=\"216\" class=\"aligncenter size-medium wp-image-23\" srcset=\"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-pieces-300x216.png 300w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-pieces-80x57.png 80w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-pieces.png 679w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<h2>Setting up the Matrix<\/h2>\n<p>Cool about 3 minutes in&#8230; Let&#8217;s draw a T using a 2 dimensional matrix as a starting point. <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nconst matrix = &#x5B;\r\n  &#x5B;0, 0, 0], \/\/ determines the center of the piece\r\n  &#x5B;1, 1, 1],\r\n  &#x5B;0, 1, 0],\r\n];\r\n\r\nmatrix.forEach((row, y) =&gt; {\r\n  row.forEach((value, x) =&gt; {\r\n    if (value !== 0) {\r\n      context.fillStyle = 'red';\r\n      context.fillRect(x, y, 1, 1);\r\n    }\r\n  });\r\n});\r\n<\/pre>\n<p>Will result in the following on your browser. This is a preliminary step so in order to see this one you will have to zoom in.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.projectimmerse.com\/wp-content\/uploads\/2018\/07\/tetris-t-shape-300x225.png\" alt=\"\" width=\"300\" height=\"225\" class=\"aligncenter size-medium wp-image-36\" srcset=\"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-t-shape-300x225.png 300w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-t-shape-768x577.png 768w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-t-shape-200x150.png 200w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-t-shape-80x60.png 80w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-t-shape.png 934w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<h2>The forEach() method and the arrow functions (=>) explained<\/h2>\n<p>I was curious what the <strong>forEach()<\/strong> method was doing here. I lazily assumed that the first parameter was the key, and the second was the value translating into a <strong>key, value<\/strong> sequence. <\/p>\n<p>In javascript however, these parameters are flipped when using the <strong>forEach()<\/strong> method. <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\nforEach(value, key);\r\n\r\n<\/pre>\n<p>Now with arrow functions &#8211; this subject deserves a post of its own so I&#8217;ll cover that topic in a future post. To understand arrow functions, you will need a thorough understanding of scope, lexical environments and the &#8216;this&#8217; keyword. <\/p>\n<h2>Wrapping everything into a function<\/h2>\n<p>The cool part about functional programming and just about any programming language is eliminating the need for repetition by encapsulating a set of operations within a function scope. The first tetris piece looks good, except it needs to be scaled first. <\/p>\n<p>This will scale the drawn objects 20 times, simple as that.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\ncontext.scale(20, 20);\r\n\r\n<\/pre>\n<p>The drawMatrix() function takes care of building each tetris piece, pretty awesome!<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\nfunction drawMatrix(matrix, offset) {\r\n  matrix.forEach((row, y) =&gt; {\r\n    row.forEach((value, x) =&gt; {\r\n      if (value !== 0) {\r\n        context.fillStyle = 'red';\r\n        context.fillRect(x + offset.x,\r\n                        y + offset.y,\r\n                        1, 1);\r\n      }\r\n    });\r\n  });\r\n}\r\n\r\ndrawMatrix(matrix, {x: 5, y: 5});\r\n\r\n<\/pre>\n<p>And Voila! Lookin&#8217; good!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.projectimmerse.com\/wp-content\/uploads\/2018\/07\/t-piece-matrix-offset-239x300.png\" alt=\"\" width=\"239\" height=\"300\" class=\"aligncenter size-medium wp-image-47\" srcset=\"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/t-piece-matrix-offset-239x300.png 239w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/t-piece-matrix-offset-80x100.png 80w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/t-piece-matrix-offset.png 582w\" sizes=\"auto, (max-width: 239px) 100vw, 239px\" \/><\/p>\n<h2>requestAnimationFrame() and a few helper functions<\/h2>\n<p>Breaking it down:<\/p>\n<ul>\n<li>requestAnimationFrame() &#8211; this powerful method makes animation possible, so we will be using this a lot!<\/li>\n<li>draw() &#8211; The draw() function paints the object itself<\/li>\n<li>update() &#8211; the update() function is what makes the object actually move. This requires dynamically repainting the object itself, through a method called recursion. An operation which involves calling itself.<\/li>\n<\/ul>\n<h2>Creating the player object<\/h2>\n<p>The player object will contain object position and the matrix responsible for creating a tetris piece. So let&#8217;s create this first before adding the functions described previously.<\/p>\n<p>Pretty self explanatory, below were creating offsets based on x and y coordinates. 5px from the top and 5px left.The matrix property contains the matrix object. <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nconst player = {\r\n  pos: {\r\n    x: 5,\r\n    y: 5\r\n  },\r\n  matrix: matrix\r\n\r\n}\r\n<\/pre>\n<h2>Where is the player object being passed around and where is it being updated?<\/h2>\n<p>The draw() function!<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\nfunction draw() {\r\n\r\n  context.fillStyle = '#000000';\r\n  context.fillRect(0, 0, canvas.width, canvas.height);\r\n\r\n  drawMatrix(player.matrix, player.pos);\r\n}\r\n\r\n<\/pre>\n<p>Continuously draw our animation with the update() function, defined below. Notice we are defining the update function and then immediately calling itself after the we&#8217;ve painted the objects on canvas. <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction update() {\r\n  draw();\r\n  requestAnimationFrame(update);\r\n}\r\n<\/pre>\n<p>We can control the positioning of a tetris piece through the console. We will have to play around with manipulating time in the next section. First, we create the actual object onto our canvas and make them moveable through object methods and properties &#8211; in this case the player object.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.projectimmerse.com\/wp-content\/uploads\/2018\/07\/player-position-300x186.png\" alt=\"\" width=\"300\" height=\"186\" class=\"aligncenter size-medium wp-image-72\" srcset=\"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/player-position-300x186.png 300w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/player-position-768x476.png 768w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/player-position-80x50.png 80w, https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/player-position.png 974w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Then we call the update() function at very bottom of our file.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nupdate();\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to my first post, what better way to start with a super complex but fun project. Before I start, I&#8217;d like to give credit to the original creator of this game &#8211; Pontus. Feel free to visit his Github and Youtube Channel for more of his projects and videos. My intent is to complete &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Building a Tetris Game with Javascript&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1112,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Building a Tetris Game with Javascript - Project Immerse<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building a Tetris Game with Javascript - Project Immerse\" \/>\n<meta property=\"og:description\" content=\"Welcome to my first post, what better way to start with a super complex but fun project. Before I start, I&#8217;d like to give credit to the original creator of this game &#8211; Pontus. Feel free to visit his Github and Youtube Channel for more of his projects and videos. My intent is to complete &hellip; Continue reading &quot;Building a Tetris Game with Javascript&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Project Immerse\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-09T00:33:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-06-16T22:40:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-game-using-javsacript.png\" \/>\n\t<meta property=\"og:image:width\" content=\"750\" \/>\n\t<meta property=\"og:image:height\" content=\"750\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"projectimmerse\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"projectimmerse\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/\"},\"author\":{\"name\":\"projectimmerse\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/#\\\/schema\\\/person\\\/c53f2864be524ee6fa08a7e4800dd1e5\"},\"headline\":\"Building a Tetris Game with Javascript\",\"datePublished\":\"2018-07-09T00:33:22+00:00\",\"dateModified\":\"2020-06-16T22:40:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/\"},\"wordCount\":894,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/tetris-game-using-javsacript.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/\",\"url\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/\",\"name\":\"Building a Tetris Game with Javascript - Project Immerse\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/tetris-game-using-javsacript.png\",\"datePublished\":\"2018-07-09T00:33:22+00:00\",\"dateModified\":\"2020-06-16T22:40:38+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/#\\\/schema\\\/person\\\/c53f2864be524ee6fa08a7e4800dd1e5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/tetris-game-using-javsacript.png\",\"contentUrl\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/tetris-game-using-javsacript.png\",\"width\":750,\"height\":750,\"caption\":\"Tetris Game using Javascript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/building-a-tetris-game-with-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building a Tetris Game with Javascript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/\",\"name\":\"Project Immerse\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/#\\\/schema\\\/person\\\/c53f2864be524ee6fa08a7e4800dd1e5\",\"name\":\"projectimmerse\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d06955033d6227bfdcf30014e457e4334f7deeb73907de49b65ec2484921931?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d06955033d6227bfdcf30014e457e4334f7deeb73907de49b65ec2484921931?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d06955033d6227bfdcf30014e457e4334f7deeb73907de49b65ec2484921931?s=96&d=mm&r=g\",\"caption\":\"projectimmerse\"},\"url\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/author\\\/projectimmerse\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Building a Tetris Game with Javascript - Project Immerse","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Building a Tetris Game with Javascript - Project Immerse","og_description":"Welcome to my first post, what better way to start with a super complex but fun project. Before I start, I&#8217;d like to give credit to the original creator of this game &#8211; Pontus. Feel free to visit his Github and Youtube Channel for more of his projects and videos. My intent is to complete &hellip; Continue reading \"Building a Tetris Game with Javascript\"","og_url":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/","og_site_name":"Project Immerse","article_published_time":"2018-07-09T00:33:22+00:00","article_modified_time":"2020-06-16T22:40:38+00:00","og_image":[{"width":750,"height":750,"url":"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-game-using-javsacript.png","type":"image\/png"}],"author":"projectimmerse","twitter_card":"summary_large_image","twitter_misc":{"Written by":"projectimmerse","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/#article","isPartOf":{"@id":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/"},"author":{"name":"projectimmerse","@id":"https:\/\/www.projectimmerse.com\/blog\/#\/schema\/person\/c53f2864be524ee6fa08a7e4800dd1e5"},"headline":"Building a Tetris Game with Javascript","datePublished":"2018-07-09T00:33:22+00:00","dateModified":"2020-06-16T22:40:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/"},"wordCount":894,"commentCount":0,"image":{"@id":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-game-using-javsacript.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/","url":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/","name":"Building a Tetris Game with Javascript - Project Immerse","isPartOf":{"@id":"https:\/\/www.projectimmerse.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-game-using-javsacript.png","datePublished":"2018-07-09T00:33:22+00:00","dateModified":"2020-06-16T22:40:38+00:00","author":{"@id":"https:\/\/www.projectimmerse.com\/blog\/#\/schema\/person\/c53f2864be524ee6fa08a7e4800dd1e5"},"breadcrumb":{"@id":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/#primaryimage","url":"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-game-using-javsacript.png","contentUrl":"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/tetris-game-using-javsacript.png","width":750,"height":750,"caption":"Tetris Game using Javascript"},{"@type":"BreadcrumbList","@id":"https:\/\/www.projectimmerse.com\/blog\/building-a-tetris-game-with-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.projectimmerse.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Building a Tetris Game with Javascript"}]},{"@type":"WebSite","@id":"https:\/\/www.projectimmerse.com\/blog\/#website","url":"https:\/\/www.projectimmerse.com\/blog\/","name":"Project Immerse","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.projectimmerse.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.projectimmerse.com\/blog\/#\/schema\/person\/c53f2864be524ee6fa08a7e4800dd1e5","name":"projectimmerse","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4d06955033d6227bfdcf30014e457e4334f7deeb73907de49b65ec2484921931?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4d06955033d6227bfdcf30014e457e4334f7deeb73907de49b65ec2484921931?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d06955033d6227bfdcf30014e457e4334f7deeb73907de49b65ec2484921931?s=96&d=mm&r=g","caption":"projectimmerse"},"url":"https:\/\/www.projectimmerse.com\/blog\/author\/projectimmerse\/"}]}},"_links":{"self":[{"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"count":50,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":474,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/posts\/1\/revisions\/474"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/media\/1112"}],"wp:attachment":[{"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}