{"author_name":"toxicfork","cat":"LD #20 - It's Dangerous to go Alone! Take This!","comments":[{"author_name":"snowyowl","time":"April 30, 2011 7:49 am","epoch":1304167740,"text":"Wow. That is an awesome sprite sheet.","spam":"N"}],"epoch":1304167020,"likes":0,"metadata":{"p_key":"66533","p_author":"toxicfork","p_authorkey":"508669","p_urlkey":"102329","p_title":"2D Tile Engine!","p_cat":"LD #20 - It's Dangerous to go Alone! Take This!","p_event":"LD20","p_time":"1304167020","p_likes":"0","p_comments":"1","p_status":"UPD5","us_key":"508669","us_name":"toxicfork","us_username":"toxicfork","event_start":"1304035200","event_key":"6","event_name":"LD20"},"text":"<p>Yay!<\/p>\n <p>Just a few demos using only 10&#215;10 tiles:<\/p>\n <p><a href=\"http:\/\/toxicfork.com\/upload\/1304173236555.jpg\"><img class=\"aligncenter\" src=\"http:\/\/toxicfork.com\/upload\/1304173236555.jpg\" alt=\"\" width=\"365\" height=\"367\" \/><\/a><\/p>\n <p><a href=\"http:\/\/toxicfork.com\/upload\/1304173308941.jpg\"><img class=\"aligncenter\" src=\"http:\/\/toxicfork.com\/upload\/1304173308941.jpg\" alt=\"\" width=\"394\" height=\"367\" \/><\/a><\/p>\n <p><span id=\"more-47010\"><\/span><\/p>\n <p>How it happens:<br \/>\n A 10&#215;10 tile is created using a boolean array:<\/p>\n <pre>for(int i=0;i&lt;10;i++){\n for(int j=0;j&lt;10;j++){\n tiles[i,j] = (Random.Range(0.0f,1.0f)&gt;=0.5f);\n }\n }<\/pre>\n <p>Then each tile checks its surrounding tiles and records the environment status into a flag:<\/p>\n <pre>byte getFlagsForTile(int i, int j){\n byte result = 0;\n int curPos = 0;\n for(int k=-1;k&lt;=1;k++){\n for(int l=-1;l&lt;=1;l++){\n if(!(k==0&amp;&amp;l==0)){\n if(hasTile(i+k,j+l))\n result|=(byte)(1&lt;&lt;curPos);\n curPos++;\n }\n }\n }\n return result;\n }<\/pre>\n <p>Based on this flag system:<\/p>\n <p><a href=\"http:\/\/toxicfork.com\/upload\/1304173960554.jpg\"><img class=\"aligncenter\" src=\"http:\/\/toxicfork.com\/upload\/1304173960554.jpg\" alt=\"\" width=\"342\" height=\"267\" \/><\/a><\/p>\n <p>So if the flag&#8217;s first bit is 1, that means there&#8217;s a tile on the lower right of this tile.<\/p>\n <p>Using the flag as a guide, the tile can then pick its graphics from this sprite sheet:<\/p>\n <p><a href=\"http:\/\/toxicfork.com\/upload\/1304174086960.jpg\"><img class=\"aligncenter\" src=\"http:\/\/toxicfork.com\/upload\/1304174086960.jpg\" alt=\"\" width=\"96\" height=\"544\" \/><\/a><\/p>\n <p>&nbsp;<\/p>\n <p>That&#8217;s it &#8230; also I will use the flag information to generate collision.<\/p>","time":"April 30th, 2011 7:37 am","title":"2D Tile Engine!"}