{"assets":[{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/thing.png","local":"\/data\/posts\/2013\/04\/628d3fb225071a2f3b317e7a193dfe1e.png"},{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/obstacle.png","local":"\/data\/posts\/2013\/04\/d6ffcc5e25f674b8944947be69d4e30e.png"},{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/thing.png","local":"\/data\/posts\/2013\/04\/628d3fb225071a2f3b317e7a193dfe1e.png"},{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/obstacle.png","local":"\/data\/posts\/2013\/04\/d6ffcc5e25f674b8944947be69d4e30e.png"}],"author_link":"author\/sko\/","author_name":"Avant-Marde","cat":"LD #26","categories":["LD #26"],"comments":[],"epoch":1366871160,"event":"LD26","likes":0,"metadata":{"p_key":"80239","p_author":"Avant-Marde","p_authorkey":"0","p_urlkey":"289249","p_title":"Rectangle collision (SFML 2.0)","p_cat":"LD #26","p_event":"LD26","p_time":"1366871160","p_likes":"0","p_comments":"0","p_status":"WAYBACK","us_key":null,"us_name":null,"us_username":null,"event_start":"1366934400","event_key":"16","event_name":"LD26"},"source_url":"2013\/04\/25\/rectangle-collision-sfml-2-0\/","text":"<p>Perhaps somebody saw <a href=\"http:\/\/www.ludumdare.com\/compo\/2013\/04\/24\/holy-trinity-of-sfml-2-0-how-to-set-up\/\">my post about how I set up SFML 2.0 for cross-compilation<\/a>. I have one more thing to share. It is in no way necessarily connected to SFML 2.0, but that was what I used here, so modifications would have to be made for other frameworks (or other languages than C++).<\/p>\n<p>What I have made is a very simple demo where a \u201ccharacter\u201d with a rectangular hitbox may be moved with the arrow keys and unable to go through other solid objects, also with rectangular hitboxes \u2013 walls, simply. Topdown view.<\/p>\n<p>Here is the source code:<br\/>\n<a href=\"http:\/\/pastebin.com\/gHvAQ1as\">http:\/\/pastebin.com\/gHvAQ1as<\/a><a href=\"http:\/\/pastebin.com\/jWRfx7xu\"><br\/>\n<\/a><\/p>\n<p>To note:<\/p>\n<ul>\n<li><span style=\"line-height: 13px\">The arrow keys are used to steer.<\/span><\/li>\n<li>The character\u2019s sprite is 24\u00d724 and the obstacle sprites are 64\u00d764. I made two quick and ugly sprites.<br\/>\n<a href=\"\/data\/posts\/2013\/04\/628d3fb225071a2f3b317e7a193dfe1e.png\"><img alt=\"thing\" class=\"alignnone size-full wp-image-229082\" height=\"24\" src=\"\/data\/posts\/2013\/04\/628d3fb225071a2f3b317e7a193dfe1e.png\" width=\"24\"\/><\/a>\u00a0<a href=\"\/data\/posts\/2013\/04\/d6ffcc5e25f674b8944947be69d4e30e.png\"><img alt=\"obstacle\" class=\"alignnone size-full wp-image-229083\" height=\"64\" src=\"\/data\/posts\/2013\/04\/d6ffcc5e25f674b8944947be69d4e30e.png\" width=\"64\"\/><\/a><\/li>\n<li>The\u00a0<em>resourcePath()<\/em> thing is an OS X only thing needed before the resource paths. It comes with the OS X OpenGL demo for SFML 2.0.<\/li>\n<li>The obstacles are stored as <em>sf::Vector2f<\/em>\u2018s (co\u00f6rdinates) in an <em>std::vector<\/em> (container). Different types of vectors, thus. The same sprite handle is used to draw all of them.<\/li>\n<\/ul>\n<p>This is the only thing I\u2019ve done for LD that may be considered a \u201cwarmup\u201d so far. I did it during a one-hour train ride when I had nothing better to do. Perhaps somebody will find this useful during the competition.<\/p>\n<p>Tags: <a href=\"http:\/\/ludumdare.com\/compo\/tag\/collision-detection-rectangle-example-sfml\/\" rel=\"tag\">collision detection rectangle example sfml<\/a><\/p>","time":"April 25th, 2013 6:26 am","title":"Rectangle collision (SFML 2.0)","title_was_empty":false}