{"author_name":"SpaceManiac","cat":"MiniLD","comments":[{"author_name":"demize","time":"October 6, 2008 7:58 pm","epoch":1223341080,"text":"Hmm&#8230; If the player has a floor below them, then don&#8217;t let them move down. All it takes is: if(player.y != floor.y+z){(insert your downwards movement code here)}. Replace z with how much you move per frame, and change this to support how you&#8217;re doing it.","spam":"N"},{"author_name":"wonderwhy-er","time":"October 7, 2008 2:43 am","epoch":1223365380,"text":"Not enough info it seems&#8230; Is it only floor or there are walls. Is it platformer style where you can jump trough some platforms etc etc. More info please <img src=\"http:\/\/ludumdare.com\/compo\/wp-includes\/images\/smilies\/simple-smile.png\" alt=\":)\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/>","spam":"N"},{"author_name":"","time":"October 7, 2008 12:38 pm","epoch":1223401080,"text":"I usually have a &#8216;grounded&#8217; variable on objects, and a conditional splits up what movement I allow it  before input and collision, where I may need to move the object again or change its grounded variable for the next tick (or whatever you call a timer event) ^_^","spam":"N"},{"author_name":"SpaceManiac","time":"October 7, 2008 1:51 pm","epoch":1223405460,"text":"Only walls &#8211; no platforms you can sometimes go through. I&#8217;m thinking of the kind of walls in Ninja Kitty Vs. The Nukebots. They way the cat hits the walls in that game is almost exactly what I&#8217;m looking for.","spam":"N"}],"epoch":1223334180,"likes":0,"metadata":{"p_key":"74498","p_author":"SpaceManiac","p_authorkey":"412","p_urlkey":"110330","p_title":"Collisions","p_cat":"MiniLD","p_event":"LD12","p_time":"1223334180","p_likes":"0","p_comments":"5","p_status":"UPD5","us_key":"412","us_name":"SpaceManiac","us_username":"spacemaniac","event_start":"1218153600","event_key":"89","event_name":"LD12"},"text":"<p>I need help with collision code. I want to keep the player from falling through floors, pretty much. Help?<\/p>\n <p>EDIT: Okay, I&#8217;ve got some good collision detection, but there&#8217;s something wrong with my moving code.<\/p>\n <blockquote><p>bool checkCollision(SDL_Rect &amp;movable, double &amp;vx, double &amp;vy, SDL_Rect solid, bool move) {<br \/>\n int moveLeft = movable.x;<br \/>\n int moveTop = movable.y;<br \/>\n int moveRight = moveLeft + movable.w;<br \/>\n int moveBottom = moveTop + movable.h;<\/p>\n <p>int solidLeft = solid.x;<br \/>\n int solidTop = solid.y;<br \/>\n int solidRight = solidLeft + solid.w;<br \/>\n int solidBottom = solidTop + solid.h;<\/p>\n <p>int clipLeft = max(moveLeft, solidLeft);<br \/>\n int clipTop = max(moveTop, solidTop);<br \/>\n int clipRight = min(moveRight, solidRight);<br \/>\n int clipBottom = min(moveBottom, solidBottom);<\/p>\n <p>if(clipLeft == clipRight || clipTop == clipBottom)<br \/>\n return false;<\/p>\n <p>if(!move)<br \/>\n return true;<\/p>\n <p>int clipWidth = clipRight &#8211; clipLeft;<br \/>\n int clipHeight = clipBottom &#8211; clipTop;<\/p>\n <p>if(clipWidth  solidX) {<br \/>\n \/\/ moving to right<br \/>\n movable.x += solidRight &#8211; moveLeft;<br \/>\n } else {<br \/>\n \/\/ moving to left<br \/>\n movable.x -= moveRight &#8211; solidLeft;<br \/>\n }<br \/>\n } else {<br \/>\n \/\/ moving along y axis<br \/>\n vy = 0;<br \/>\n int moveY = moveTop + movable.h \/ 2;<br \/>\n int solidY = solidLeft + solid.h \/ 2;<br \/>\n if(moveY &gt; solidY) {<br \/>\n \/\/ moving to bottom<br \/>\n movable.y += solidBottom &#8211; moveTop;<br \/>\n } else {<br \/>\n \/\/ moving to top<br \/>\n movable.y -= moveBottom &#8211; solidTop;<br \/>\n }<br \/>\n }<\/p>\n <p>return true;<br \/>\n }<\/p><\/blockquote>\n <p>Please help! If you&#8217;re interested in seeing what&#8217;s happening, here&#8217;s the program: http:\/\/files.chocoboheaven.com\/uploads\/Guests\/files\/85267_PaintWorld.zip<\/p>\n \n <p>Tags: <a href=\"http:\/\/ludumdare.com\/compo\/tag\/c\/\" rel=\"tag\">C++<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/help\/\" rel=\"tag\">help<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/physics\/\" rel=\"tag\">physics<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/platformer\/\" rel=\"tag\">platformer<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/walls\/\" rel=\"tag\">walls<\/a><\/p>","time":"October 6th, 2008 6:03 pm","title":"Collisions"}