{"author_name":"pht59x","cat":"LD #31","comments":[{"author_name":"","time":"December 26, 2014 3:16 am","epoch":1419581760,"text":"How come I am seeing this post for like the fifth time? Are you reposting \/ editing it or something?","spam":"N"},{"author_name":"pht59x","time":"December 26, 2014 4:24 am","epoch":1419585840,"text":"I have changed the title, hence 2nd time and not 5th. I have also deleted the old one.","spam":"N"},{"author_name":"","time":"December 26, 2014 4:40 am","epoch":1419586800,"text":"Fair enough \u2026","spam":"N"}],"epoch":1419570840,"likes":1,"metadata":{"p_key":"21777","p_author":"pht59x","p_authorkey":"36239","p_urlkey":"57137","p_title":"There is nothing weird with Greeny GRUB controls","p_cat":"LD #31","p_event":"LD31","p_time":"1419570840","p_likes":"1","p_comments":"3","p_status":"UPD5","us_key":"36239","us_name":"pht59x","us_username":"pht59x","event_start":"1417737600","event_key":"26","event_name":"LD31"},"text":"<p>WTF with the weird controls in <a href=\"http:\/\/ludumdare.com\/compo\/ludum-dare-31\/?action=preview&amp;uid=36239\">Greeny GRUB<\/a>? Here is some explaining. Keep reading if you know a little bit about CoffeeScript, Python or C-like syntax:<\/p>\n <p><code># Cursor-keys handling<br \/>\n document.onkeydown = (event) -&gt;<br \/>\n __deltaVelocity = 80 # in pixels per second<br \/>\n __switch event.keyCode<br \/>\n ____when KEY_UP then player.adjustVy(-deltaVelocity)<br \/>\n ____when KEY_LEFT then player.adjustVx(-deltaVelocity)<br \/>\n ____when KEY_DOWN then player.adjustVy(deltaVelocity)<br \/>\n ____when KEY_RIGHT then player.adjustVx(deltaVelocity)<br \/>\n <\/code><\/p>\n <p>where deltaVelocity will be used by:<\/p>\n <ul>\n <li>player.adjustVx() and player.adjustVy() to update vX and Vy velocities.<\/li>\n <li>player.update(fps) to update x and y coordinates<\/li>\n <\/ul>\n <p><code><br \/>\n class Player<br \/>\n __constructor: (@x,@y,@vX,@vY) -&gt;<\/code><\/p>\n <p>__adjustVx: (deltaVx) -&gt;<br \/>\n ____if Math.abs(@vX)&lt;100 or (deltaVx&gt;0 and @vX&lt;0) or (deltaVx&lt;0 and @vX&gt;0)<br \/>\n ______@vX+=deltaVx<\/p>\n <p>__adjustVy: (deltaVy) -&gt;<br \/>\n ____if Math.abs(@vY)&lt;100 or (deltaVy&gt;0 and @vY&lt;0) or (deltaVy&lt;0 and @vY&gt;0)<br \/>\n ______@vY+=deltaVy<\/p>\n <p>__update: (fps)-&gt;<br \/>\n ____@x+=@vX\/fps<br \/>\n ____@y+=@vY\/fps<\/p>\n <p>The weird behaviour comes from the fact that there is no damping on the velocity once it has been passed to the player&#8217;s methods and that I do not handle onkeyup events.<\/p>","time":"December 26th, 2014 12:14 am","title":"There is nothing weird with Greeny GRUB controls"}