{"author_name":"ippa","cat":"LD #16 - Exploration - 2009","comments":[{"author_name":"sfernald","time":"December 15, 2009 11:41 am","epoch":1260895260,"text":"I liked this game so much I think I&#8217;m going to try to make my own level. Since the level code is so clean, I expect this to be quite easy. We&#8217;ll see.","spam":"N"},{"author_name":"sfernald","time":"December 15, 2009 5:41 pm","epoch":1260916860,"text":"Hey, I made a new level for your game. I has given me a chance to play around with Chingu. Must say it&#8217;s pretty cool.","spam":"N"},{"author_name":"sfernald","time":"December 17, 2009 3:52 pm","epoch":1261083120,"text":"I finished my little sequel of sorts. Here it is:","spam":"N"},{"author_name":"ippa","time":"December 18, 2009 2:50 am","epoch":1261122600,"text":"I love it :D.. you&#8217;ve made a better game then the original! Played through it, damn it was hard.","spam":"N"},{"author_name":"ippa","time":"December 18, 2009 3:33 am","epoch":1261125180,"text":"Blogpost + Windows EXE:","spam":"N"},{"author_name":"sfernald","time":"December 18, 2009 9:53 am","epoch":1261147980,"text":"Very cool.","spam":"N"}],"epoch":1260776460,"likes":0,"metadata":{"p_key":"71768","p_author":"ippa","p_authorkey":"1087","p_urlkey":"107590","p_title":"Ruby, OpenGL and Pixels","p_cat":"LD #16 - Exploration - 2009","p_event":"LD16","p_time":"1260776460","p_likes":"0","p_comments":"6","p_status":"UPD5","us_key":"1087","us_name":"ippa","us_username":"ippa","event_start":"1260489600","event_key":"2","event_name":"LD16"},"text":"<p>I used my favorite language of all time, <a href=\"http:\/\/ruby-lang.org\">Ruby<\/a>. With 1.9 Ruby has picked up speed and with <a href=\"http:\/\/github.com\/larsch\/ocra\">Ocra<\/a> you easily make a ~1-2 meg exe-file out of it. Also the excellent (and german precision engineered)\u00a0 <a href=\"http:\/\/github.com\/larsch\/ocra\">Gosu<\/a> enables OpenGL accelerated 2D. On top of that I used my own Ruby\/Gosu-specific framework <a href=\"http:\/\/ippa.se\/chingu\">Chingu<\/a> to get game states, re-usable game logic and a boiler plate &#8220;game object&#8221;. To get a speedy get_pixel() I used the awesome <a href=\"http:\/\/banisterfiend.wordpress.com\/2008\/08\/23\/texplay-an-image-manipulation-tool-for-ruby-and-gosu\/\">Texplay<\/a> by <a href=\"http:\/\/github.com\/banister\">John Mair<\/a>.<\/p>\n <p>I have a pixel fetish. I love retro-looks in games, and I love pixel-perfect-collisions, a fetish that probably came into existence playing hours and hours of Lemmings 2-player mode on the classic Amiga 500.<\/p>\n <p>So, the most time was spent up building a good pixel-perfect-collision algo, and it came out very playable, but not perfect. I ranted about it in my last blogpost.<\/p>\n <p>With Ruby and Chingu my level-building got very clean, I think even ppl not into Ruby could understand what&#8217;s happening here:<\/p>\n <blockquote>\n <pre>class Level7 &lt; Level\n \u00a0 def setup\n \u00a0\u00a0\u00a0 self.background = \"level7.bmp\"\n \u00a0\u00a0\u00a0 every(1000) { Enemy.create(:image =&gt; \"acid_drop.bmp\", x =&gt; 150, :velocity_y =&gt; 5) }\n every(1500) { Enemy.create(:image =&gt; \"acid_drop.bmp\", x =&gt; 250, :velocity_y =&gt; 5) }\n \u00a0 end\n end<\/pre>\n <\/blockquote>\n <p>or here (this is from the mainloop):<\/p>\n <blockquote>\n <pre>player.each_collision(Enemy) do |player, enemy|\n unless player.paused?\n player.pause!\n Sound[\"die.wav\"].play(0.3)\n after(1000) {  player.x = @entry_x; player.y = @entry_y; player.unpause!; }\n end\n end<\/pre>\n <\/blockquote>\n <p>It&#8217;s nice when it&#8217;s silly simple building readable levels.<\/p>\n <p>I also got a very basic and simple Map-class going so I could build on my matrix of screens that made up the game:<\/p>\n <blockquote>\n <pre>map = [\n [LevelUp, nil, nil, nil],\n [Level1, Level2,Level22, nil],\n [LevelAir, nil, Level3, nil],\n [LevelAir2, Level5, Level4, nil],\n [nil, Level6, Level7, nil],\n [nil, Level8, Level9, End],\n ]<\/pre>\n <\/blockquote>\n <p>Basically if you exited a screen to the right I would increment a column_counter and fetch a new screen from the matrix. If exiting downwards, increment row_counter an fetch a new screen.<\/p>\n <p>If you like OO, short readable code and scripting languages in general and haven&#8217;t checked out Ruby or Gosu yet, now is the time to do it.<\/p>","time":"December 14th, 2009 2:41 am","title":"Ruby, OpenGL and Pixels"}