Project

hasu

0.02
No commit activity in last 3 years
No release in over 3 years
Prototype Gosu games with ease
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0

Runtime

>= 0
 Project Readme

Hasu

Helps you develop Gosu games more quickly.

How?

Hot code loading

Normally, when you change the code for a Gosu game, you have to close and restart the game for the code to take affect. With Hasu, modified source files will be reloaded each time through the game loop.

Exception catching

When an exception bubbles up out of your game loop, Gosu will crash. When an exception occurs in a Hasu game, Hasu pauses your game, prints the exception details into your window, and resumes your game once the code that fixes it is loaded.

Reset

Hot code loading unfortunately is worthless for your initialize method since your window will only be initialized once, Instead of putting your game's setup code in initialize, place it in reset and press R whenever you want to re-initialize your game state.

Using Hasu

The above features only work on Ruby 2+, though Hasu will still load on earlier versions (in case you want to pack up your game with Releasy).

0: Install Hasu

Add this line to your application's Gemfile:

gem hasu

Or install it yourself as:

$ gem install hasu

1: Subclass Hasu::Window (or prepend Hasu::Guard).

Instead of subclassing Gosu::Window, use Hasu::Window:

class Game < Hasu::Window
  def initialize
    super(640, 480, false)
  end

  def reset
    # ...
  end

  def update
    # ...
  end

  def draw
    # ...
  end
end

If you're using Chingu (or another library which has its own window subclass), you can prepend Hasu::Guard onto your window for the same effect:

class Game < Chingu::Window
  prepend Hasu::Guard

  def initialize
    super(640, 480, false)
  end

  def reset
    # ...
  end

  def update
    # ...
  end

  def draw
    # ...
  end
end

2: Use Hasu.load to require your game's files.

For the files you want to be hot loaded, use Hasu.load instead of require.

Hasu.load "ball.rb"

3: Run your game with .run

Instead of Game.new.show, run your Hasu game with Game.run.