{"assets":[{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/1-550x69.jpg","local":"\/data\/posts\/2014\/06\/77ef7e2deea9a5b915207d9f761421c6.jpg"},{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/2-550x104.jpg","local":"\/data\/posts\/2014\/06\/d1b8bb6610a1d70ad37f94de0ac56662.jpg"},{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/3.jpg","local":"\/data\/posts\/2014\/06\/ba0698d28788909f5a1cd40444146a21.jpg"},{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/3.jpg","local":"\/data\/posts\/2014\/06\/ba0698d28788909f5a1cd40444146a21.jpg"}],"author_link":"author\/xrxr\/","author_name":"XrXr","cat":"MiniLD","categories":["MiniLD"],"comments":[],"epoch":1401782520,"event":"","likes":10,"metadata":{"p_key":"82234","p_author":"XrXr","p_authorkey":"0","p_urlkey":"292966","p_title":"Rapid Pygame!","p_cat":"MiniLD","p_event":"LD29","p_time":"1401782520","p_likes":"10","p_comments":"0","p_status":"WAYBACK","us_key":null,"us_name":null,"us_username":null,"event_start":"1398384000","event_key":"22","event_name":"LD29"},"source_url":"2014\/06\/03\/rapid-pygame\/","text":"<p>LD 29 is the first LD that I participated in. The jam went okay, beside not having a great idea, I didn\u2019t get to finish all that I wanted to do. The game didn\u2019t do too well in the rankings, but its not a big deal. Every time I make a game using Pygame, I find myself typing in the same thing over and over, wasting time. That\u2019s why I made Rapid Pygame for MiniLD 51.<\/p>\n<p><a href=\"https:\/\/github.com\/XrXr\/RapidPygame\">Rapid Pygame<\/a> is a set of classes and tools that help accelerate the game development process when using Pygame, letting the developers to focus on game play features rather than the tiny building blocks behind the scene. It requires Python 3+ (Its time to move on)<\/p>\n<p>Now of course, since Pygame uses Python, no body is going to use it, let alone this library. However I did spent a lot of time writing the <a href=\"http:\/\/xrxr.github.io\/RapidPygame\/\">docs<\/a> for this project.<\/p>\n<p>Enough words! Lets see what it can do!<\/p>\n<p><strong>Painless relative loading<\/strong><\/p>\n<p>Games load stuff. Images, sound, levels\u2026 And its pretty common to load a file relative to the executable or script. How do you do it in Pygame normally?<\/p>\n<p><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/1.jpg\"><img alt=\"1\" class=\"alignnone wp-image-364753 size-large\" height=\"69\" sizes=\"(max-width: 550px) 100vw, 550px\" src=\"\/data\/posts\/2014\/06\/77ef7e2deea9a5b915207d9f761421c6.jpg\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/1-300x38.jpg 300w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/1-550x69.jpg 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/1.jpg 1158w\" width=\"550\"\/><\/a><\/p>\n<p>(Getting the path of the script, and then use os.path.join to join together path names. Loading from \u201c.\/\u201d wouldn\u2019t always work since its relative to the current working directory)<\/p>\n<p>Its fairly easy to read and understand, but its long and kind of messy.<\/p>\n<p>Enter the ImageLoader class<\/p>\n<p><img alt=\"2\" class=\"alignnone wp-image-364754 size-large\" height=\"104\" sizes=\"(max-width: 550px) 100vw, 550px\" src=\"\/data\/posts\/2014\/06\/d1b8bb6610a1d70ad37f94de0ac56662.jpg\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/2-550x104.jpg 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/2.jpg 835w\" width=\"550\"\/><br\/>\nEasier to read and understand. Loading using the instance is all relative to the path given in the constructor. Cross-platform relative path loading made easier.<\/p>\n<p>It would be a pretty boring helper class if that\u2019s all it can do. ImageLoader is also capable of\u00a0 other things outline <a href=\"http:\/\/xrxr.github.io\/RapidPygame\/loader.html\">here<\/a>. Loading all images in a folder, loading a sequence of images and giving back a path string relative to the origin if you don\u2019t want to load an image.<\/p>\n<p><strong>Collision powered level manager<\/strong><\/p>\n<p>One approach of managing a map in games is using collision, the player can move around, as long as he\/she is not colliding with the level. Its intuitive and powerful. Rapid Pygame provides a way of quickly getting a level up and running.<\/p>\n<p><a href=\"\/data\/posts\/2014\/06\/ba0698d28788909f5a1cd40444146a21.jpg\"><img alt=\"3\" class=\"alignnone wp-image-364755 size-full\" height=\"829\" sizes=\"(max-width: 589px) 100vw, 589px\" src=\"\/data\/posts\/2014\/06\/ba0698d28788909f5a1cd40444146a21.jpg\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/3-213x300.jpg 213w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/3-550x774.jpg 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/3.jpg 589w\" width=\"589\"\/><\/a><\/p>\n<p>This will produce a level that a player can move around in (left right and jump). The level manager will take care of gravity, player movement and level collision. Pretty simple right? A 60 line basic game :). This will become even shorter and simpler in future version of the library. The details about the level format and the player class can all be found in the <a href=\"http:\/\/xrxr.github.io\/RapidPygame\/\">docs<\/a>.<\/p>\n<p><strong>Behind the scenes<\/strong><\/p>\n<p>That\u2019s pretty much all the features of the library, other than the\u00a0pre-made Player class that renders animation for you.\u00a0 Below is a bit about how the level manager behind the scenes.<\/p>\n<p>One thing the level manger do is take the level landscape, and break it down into rectangles, which are then used for collision checking with the player. I\u2019ve made some improvement to the algorithm compare to the old ones I used in the past. Each block represents a rectangle<\/p>\n<p>The old approach is to break the level down into strips either vertically or horizontally.<\/p>\n<p><img alt=\"3_result\" class=\"alignnone size-full wp-image-364761\" height=\"28\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/3_result.jpg\" width=\"88\"\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <img alt=\"1_result\" class=\"alignnone size-medium wp-image-364763\" height=\"45\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/1_result.jpg\" width=\"116\"\/><\/p>\n<p>The algorithm in the library will try to maximize the area of the rectangles, producing fewer rectangles for faster collision checking<\/p>\n<p><img alt=\"4_result\" class=\"alignnone size-full wp-image-364760\" height=\"44\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/4_result.jpg\" width=\"121\"\/><\/p>\n<p>Although its not prefect<\/p>\n<p><img alt=\"2_result\" class=\"alignnone size-full wp-image-364762\" height=\"44\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/06\/2_result.jpg\" width=\"89\"\/><\/p>\n<p>Both methods are probably fast enough to not have a real impact on the game\u2019s performance, but its nice to know that the algorithm that powers the manager is semi-smart XD<\/p>\n<p>\u00a0<\/p>\n<p>Well, hopefully I didn\u2019t just waste my time typing this up, even though I highly doubt it. Thanks for reading and good luck to everyone in your future LD endeavors! Whether you use Pygame or not<\/p>","time":"June 3rd, 2014 8:02 am","title":"Rapid Pygame!","title_was_empty":false}