{"id":309,"date":"2009-06-07T12:11:44","date_gmt":"2009-06-07T19:11:44","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1505"},"modified":"2009-06-07T12:11:44","modified_gmt":"2009-06-07T19:11:44","slug":"quickbox2d-tetris-pieces","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=309","title":{"rendered":"QuickBox2D Tetris Pieces"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\n\r\n&#x5B;SWF(backgroundColor=0x000000, width=700, height=600, frameRate=60)]\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this);\r\n\r\nsim.setDefault({fillColor:0x003366, lineColor:0x2B80D5, isBullet:true});\r\nsim.createStageWalls();\r\n\r\nvar shapes:Array = &#x5B;];\r\nshapes&#x5B;0] = &#x5B;&#x5B;1,1,1,1]];\r\nshapes&#x5B;1] = &#x5B;&#x5B;1, 0, 0], &#x5B;1, 1, 1]];\r\nshapes&#x5B;2] = &#x5B;&#x5B;0, 0, 1], &#x5B;1, 1, 1]];\r\nshapes&#x5B;3] = &#x5B;&#x5B;1, 1], &#x5B;1, 1]];\r\nshapes&#x5B;4] = &#x5B;&#x5B;0, 1, 1], &#x5B;1, 1, 0]];\r\nshapes&#x5B;5] = &#x5B;&#x5B;0, 1, 0], &#x5B;1, 1, 1]];\r\nshapes&#x5B;6] = &#x5B;&#x5B;1, 1, 0], &#x5B;0, 1, 1]];\r\nvar cols:Array = &#x5B;0xFF0000,  0xFFFF00, 0xFF00FF, 0x0000FF, 0x00FF00,0x00FFFF, 0x00FF00,0xFAA703];\r\nvar angs:Array =  &#x5B;0, Math.PI \/ 2, Math.PI, Math.PI + Math.PI \/ 2];\r\nvar bev:BevelFilter = new BevelFilter();\r\nwith (bev) blurX = 10, blurY = 10, strength = 0.5;\r\n\r\nvar inc:int = 9;\r\nfor (var i:int = 0; i&lt;shapes.length; i++){\r\n\tsim.setDefault({fillColor:cols&#x5B;inc % cols.length]});\r\n\tinc++\r\n\tmakePiece(shapes&#x5B;i], 3 + i * 3, 3);\r\n\tsim.setDefault({fillColor:cols&#x5B;inc % cols.length]});\r\n\tinc++\r\n\tmakePiece(shapes&#x5B;i], 3 + i * 3, 8);\r\n}\r\n\r\nfunction makePiece(pattern:Array, xp:Number, yp:Number, scale:Number = 0.7):QuickObject{\r\n\tvar parts:Array = &#x5B;];\r\n\tfor (var i:int = 0; i&lt;pattern.length; i++){\r\n\t\tfor (var j:int = 0; j&lt;pattern&#x5B;i].length; j++){\r\n\t\t\tif (pattern&#x5B;i]&#x5B;j] == 1){\r\n\t\t\t\tparts.push(sim.addBox({x:j * scale, y:i * scale, width:scale, height:scale, restitution:0, friction:1, isBullet:true}));\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tvar ang:Number = angs&#x5B;int(Math.random()*angs.length)];\r\n\tvar piece:QuickObject =  sim.addGroup({objects:parts, x:xp, y:yp, angle:ang});\r\n\t\r\n\tpiece.userData.filters = &#x5B;bev];\r\n\treturn piece;\r\n}\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n<p>This snippet uses the <a href=\"https:\/\/actionsnippet.com\/?page_id=1391\" target=\"blank\">QuickBox2D library<\/a> to create some Tetris pieces.<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"http:\/\/www.actionsnippet.com\/swfs\/qbox_tetris.html\" target=\"blank\"><br \/>\nHave a look at the swf here&#8230;<br \/>\n<img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/qb2d_tetris.gif\"\/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/qbox_tetris.swf&quot;,&quot;title&quot;:&quot;qbox tetris&quot;,&quot;width&quot;:700,&quot;height&quot;:600,&quot;missing&quot;:false,&quot;allowScriptAccess&quot;:false,&quot;backgroundColor&quot;:&quot;#000000&quot;}\"><button type=\"button\" hidden aria-expanded=\"false\">Play demo<span class=\"screen-reader-text\">: qbox tetris<\/span><\/button><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import com.actionsnippet.qbox.*; &#x5B;SWF(backgroundColor=0x000000, width=700, height=600, frameRate=60)] var sim:QuickBox2D = new QuickBox2D(this); sim.setDefault({fillColor:0x003366, lineColor:0x2B80D5, isBullet:true}); sim.createStageWalls(); var shapes:Array = &#x5B;]; shapes&#x5B;0] = &#x5B;&#x5B;1,1,1,1]]; shapes&#x5B;1] = &#x5B;&#x5B;1, 0, 0], &#x5B;1, 1, 1]]; shapes&#x5B;2] = &#x5B;&#x5B;0, 0, 1], &#x5B;1, 1, 1]]; shapes&#x5B;3] = &#x5B;&#x5B;1, 1], &#x5B;1, 1]]; shapes&#x5B;4] = &#x5B;&#x5B;0, 1, 1], &#x5B;1, 1, 0]]; shapes&#x5B;5] = &#x5B;&#x5B;0, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,94,12],"tags":[3,14,15,4],"class_list":["post-309","post","type-post","status-publish","format-standard","hentry","category-box2d","category-misc","category-quickbox2d","tag-actionscript","tag-as3","tag-box2d","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=309"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/309\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}