Coder Social home page Coder Social logo

hasu's Introduction

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.

hasu's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.