Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Showcase / Furry Dangerzone
- - By jellymann Date 2014-04-18 23:38 Edited 2014-04-21 02:07
Hi Everyone

This is my first Gosu game :) It's called "Furry Dangerzone."

Download it here.

You can also check out the code on github.

Here are some screens:





Parent - - By jlnr (dev) Date 2014-04-19 08:02
I like the amount of polish :)

And this was a fun Ruby/Gosu optimisation exercise too: The game jitters a lot as soon as the player bursts into particles. It's not the CPU, because then it would be consistently slow (and Ruby is not that bad) - it's this loop which is creating lots of work for the garbage collector:

      @particles.each do |particle|
        (1..MOTION_BLUR).each do |i|
          xoffset = i*MOTION_BLUR_OFFSET*0.4
          yoffset = i*particle[:vy]*MOTION_DT
          alpha = ((1.0 - i.to_f/MOTION_BLUR)*MOTION_BLUR_ALPHA).to_i
          @particle.draw particle[:x]-@particle.width-xoffset, particle[:y]-@particle.height-yoffset, 0, 1, 1, Gosu::Color.new(alpha,255,255,255)
        end
        @particle.draw particle[:x]-@particle.width, particle[:y]-@particle.height, 0
      end


I don't know if all the temporary Floats are still an issue (they should be immediate objects on 64-bit Ruby 2.0, right?), but the Gosu::Color is definitely causing trouble. Quick loop refactoring:

      (1..MOTION_BLUR).each do |i|
        xoffset = i*MOTION_BLUR_OFFSET*0.4
        alpha = ((1.0 - i.to_f/MOTION_BLUR)*MOTION_BLUR_ALPHA).to_i
        color = Gosu::Color.new(alpha,255,255,255)
        @particles.each do |particle|
          yoffset = i*particle[:vy]*MOTION_DT
          @particle.draw particle[:x]-@particle.width-xoffset, particle[:y]-@particle.height-yoffset, 0, 1, 1, color
        end
      end
      @particles.each do |particle|
        @particle.draw particle[:x]-@particle.width, particle[:y]-@particle.height, 0
      end


Et voila, the jitter is gone (at least to my eyes) :)
Parent - - By jellymann Date 2014-04-19 12:01
Thanks :) I'm glad you enjoyed it and fixing it :)

I didn't really notice the jitter that much because I developed it on my desktop which has some pretty fast memory and a lot of it, too. This morning I played it on my Mac and noticed it a lot. I thought maybe I would just reduce the number of particles, but your fix lets me have my particles and eat them too :P

Making games on garbage-collected system can be such a pain sometimes! I imagine my whole game could run a whole lot better if I optimised out a lot of GC bottlenecks, but I have a feeling the code would start looking a little horrid after a while >.<

Thanks again for looking at my game :)
Parent - - By jlnr (dev) Date 2014-04-19 13:54
It's getting better though! Immediate Floats in Ruby 2.0 on 64-bit are a big step forward. Now it's mostly Gosu::Color that is dangerous, and you can often use 0xaarrggbb constants (only a little bit horrid).
Parent - - By jellymann Date 2014-04-19 14:33
I've added a few more optimisations. Firstly I took your optimisation to the next level and just keep an array of Gosu::Color objects for the levels of alpha, and reuse them throughout the game. Secondly, to remove all object allocations from the update method during actual play-time, I made a simple object pool for the Danger objects. I just wonder if it's actually helping anything.
Parent - - By jlnr (dev) Date 2014-04-20 14:50
You can always increase the motion blur level to 1000 to find out; self.caption = Gosu::fps.to_s is your friend ;)
Parent - By EdwinOdesseiron Date 2014-04-21 13:14
There's a Gosu::fps function? I wrote a code just to do that ;_;
Parent - - By jellymann Date 2014-04-21 19:02
Thanks :) I tried running it on my dad's ancient netbook and found out it was lagging horribly whenever you explode, so I optimised it even more by only drawing the motion blur trail once in a record block and then only drawing one image per particle. Makes a huge difference.
Parent - By jlnr (dev) Date 2014-04-22 19:14
Ha! :) That's a good optimisation indeed.
Parent - By jellymann Date 2014-04-20 11:54
I've made a few changes. Added high score, made a few cosmetic adjustments. Screenshots have been updated.
Parent - By jellymann Date 2014-04-21 02:09
Quick update: I've added a link to download a standalone copy of the game in the OP.
Parent - - By jahmaican Date 2014-04-21 08:59
That's one quite relaxing game. I'm suprised you didn't call it "Flappy Cotton Candy".
Parent - By jellymann Date 2014-04-23 12:34
Haha, I didn't choose the name, though. I just created a github repo and went with the generated suggestion.
Up Topic Gosu / Gosu Showcase / Furry Dangerzone

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill