{"author_name":"BlueShaman","cat":"LD #22","comments":[],"epoch":1323200340,"likes":2,"metadata":{"p_key":"63193","p_author":"BlueShaman","p_authorkey":"4891","p_urlkey":"98971","p_title":"Hallo.","p_cat":"LD #22","p_event":"LD22","p_time":"1323200340","p_likes":"2","p_comments":"0","p_status":"UPD5","us_key":"4891","us_name":"BlueShaman","us_username":"blueshaman","event_start":"1323993600","event_key":"8","event_name":"LD22"},"text":"<p>Last compo I wrote a platformer.<\/p>\n <p>This took an unusually long amount of time.<\/p>\n <p>This worries me for the next one coming up, so I&#8217;ve decided I might commit myself to simply using old code (as allowed by &#8216;base code&#8217;, although I&#8217;m going to try to confirm this <em>specifically<\/em>\u00a0with as many LD&#8217;ers as I can before the compo).<\/p>\n <p>Code:<\/p>\n <p>player_x and player_y are float values, of the center of the player (which is a 16&#215;16 box).<\/p>\n <p>player_vspeed and player_hspeed correspond to the vertical and horizontal speed of the player (in pixels\/frame).<\/p>\n <p>current_map is a two dimensional boolean array, where true corresponds to a block and false not.<\/p>\n <p>(Written with Processing.org in mind; any math functions such as min \/ max can be referenced through the Math java library, or really any programming language&#8217;s math library).<\/p>\n <p>Up\/down\/left\/right are booleans corresponding to the pressed-state of the cardinal keys, used for movement.<\/p>\n <pre> int LX = int((player_x-5)\/16);\n int LY = int((player_y+12)\/16);\n int RX = int((player_x+5)\/16);\n int RY = int((player_y+12)\/16);\n int MY = int((player_y+5)\/16);\n int TY = int((player_y-8)\/16);\n if ( (current_map[RX][RY] || current_map[LX][LY]) &amp;&amp; player_vspeed &gt; 0 )\n {\n player_vspeed = 0;\n player_y = RY*16-12;\n }\n if (current_map[RX][RY] || current_map[LX][LY] )\n {\n \/\/On ground.\n if (up)\n {\n up = false;\n player_vspeed = -5; \/\/Jump speed.\n }\n if (!left &amp;&amp; !right)\n {\n player_hspeed = player_hspeed * 0.8; \/\/Horizontal velocity damping.\n }\n if (left)\n {\n player_hspeed = max(-3,player_hspeed - 0.3); \/\/Accelerate to the left, with a maximum speed.\n }\n if (right)\n {\n player_hspeed = min(3,player_hspeed + 0.3); \/\/Accelerate to the right, with a maximum speed.\n }\n }\n else\n {\n player_vspeed = player_vspeed + 0.3; \/\/Gravity. Accelerate down.\n \/\/In air.\n if (left)\n {\n player_hspeed = max(-3,player_hspeed - 0.1); \/\/For, in the air, horizontal acceleration from arrow keys.\n }\n if (right)\n {\n player_hspeed = min(3,player_hspeed + 0.1);\n }\n }\n if (current_map[RX][TY] || current_map[LX][TY] )\n {\n player_vspeed = 0;\n player_y = player_y + 2; \/\/Hit the floor.\n }\n if (current_map[int((player_x+8.1)\/16)][MY] &amp;&amp; player_hspeed &gt;= 0)\n {\n player_x = int((player_x+8.1)\/16)*16-8.2;\n player_hspeed = 0; \/\/Hit a wall.\n }\n if (current_map[int((player_x-8.1)\/16)][MY] &amp;&amp; player_hspeed &lt;= 0)\n {\n player_x = int((player_x-8.1)\/16)*16 + 24.2;\n player_hspeed = 0; \/\/Hit a wall.\n }\n player_y = player_y + player_vspeed; \/\/Accelerate the player.\n player_x = player_x + player_hspeed;\n player_vspeed = min(player_vspeed,5);<\/pre>","time":"December 6th, 2011 2:39 pm","title":"Hallo."}