hasu 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3cfdb948da98b6e0712df3e70d5632c96122f95
4
- data.tar.gz: 548c124e21f6282c6a38a5b99907bc7da88ca2a8
3
+ metadata.gz: b2f7ee58112372fb8e8114ae99fc4a7b8befe080
4
+ data.tar.gz: 736cb6f783a78dc33339df3cc2660ff29d400ebe
5
5
  SHA512:
6
- metadata.gz: d1d630051aa3183af6e2cebeaaf61c731bf0489eaf2c25d6de96842e0ce8864a989e7c6087eb527fcda7b1a6ed4752c7b9c8391a5c648dc2428daf27d95ca43d
7
- data.tar.gz: 8f8e1b297e61a1280b7a905da1ab451081a7c26ee374a215f5e0b50503aaf3ec8a1cda2415ca2ae49d8c385ce3e947fbc81713b5ebe59e2dbba3c16fe532c972
6
+ metadata.gz: 9c3d778bf199a8d6d2314d1dd0ef65f70dc460fec6ff75eb75098290a6db82ee4f160b1c301c8f679a6c8f98aef476b117030ca40d4157530c60a11ad577a712
7
+ data.tar.gz: e44614e265e3bcf6a23ff988676e35a3c54b0d0a824076cfdea4f907e6fc9929a7499b13ac3604c8bdc0064907fb2f34218a0a2a55c592e8c58d123be820cb21
data/README.md CHANGED
@@ -1 +1,94 @@
1
- Makes iterating with Gosu more better.
1
+ # Hasu
2
+
3
+ Helps you develop [Gosu](http://www.libgosu.org/) games more quickly.
4
+
5
+ ## How?
6
+
7
+ ### Hot code loading
8
+
9
+ Normally, when you change the code for a Gosu game, you have to close and restart the game for the code to take affect.
10
+ With Hasu, modified source files will be reloaded each time through the game loop.
11
+
12
+ ### Exception catching
13
+
14
+ When an exception bubbles up out of your game loop, Gosu will crash.
15
+ 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.
16
+
17
+ ### Reset
18
+
19
+ Hot code loading unfortunately is worthless for your `initialize` method since your window will only be initialized once,
20
+ 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.
21
+
22
+ ## Using Hasu
23
+
24
+ __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).__
25
+
26
+ ### 0: Install Hasu
27
+
28
+ Add this line to your application's Gemfile:
29
+
30
+ gem hasu
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install hasu
35
+
36
+ ### 1: Subclass `Hasu::Window` (or prepend `Hasu::Guard`).
37
+
38
+ Instead of subclassing `Gosu::Window`, use `Hasu::Window`:
39
+
40
+ ```ruby
41
+ class Game < Hasu::Window
42
+ def initialize
43
+ super(640, 480, false)
44
+ end
45
+
46
+ def reset
47
+ # ...
48
+ end
49
+
50
+ def update
51
+ # ...
52
+ end
53
+
54
+ def draw
55
+ # ...
56
+ end
57
+ end
58
+ ```
59
+
60
+ 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:
61
+
62
+ ```ruby
63
+ class Game < Chingu::Window
64
+ prepend Hasu::Guard
65
+
66
+ def initialize
67
+ super(640, 480, false)
68
+ end
69
+
70
+ def reset
71
+ # ...
72
+ end
73
+
74
+ def update
75
+ # ...
76
+ end
77
+
78
+ def draw
79
+ # ...
80
+ end
81
+ end
82
+ ```
83
+
84
+ ### 2: Use `Hasu.load` to require your game's files.
85
+
86
+ For the files you want to be hot loaded, use `Hasu.load` instead of `require`.
87
+
88
+ ```ruby
89
+ Hasu.load "ball.rb"
90
+ ```
91
+
92
+ ### 3: Run your game with `.run`
93
+
94
+ Instead of `Game.new.show`, run your Hasu game with `Game.run`.
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "hasu", :path => "../../"
4
+ gem "chingu"
@@ -0,0 +1,30 @@
1
+ class Ball < Chingu::GameObject
2
+ SIZE = 20
3
+
4
+ def initialize(*)
5
+ super
6
+
7
+ @x = 320
8
+ @y = 240
9
+
10
+ @dx = rand * 10
11
+ @dy = rand * 10
12
+ end
13
+
14
+ def update
15
+ @x += @dx
16
+ if @x < 0 || @x > 640
17
+ @dx *= -1
18
+ end
19
+
20
+ @y += @dy
21
+ if @y < 0 || @y > 480
22
+ @dy *= -1
23
+ end
24
+ end
25
+
26
+ def draw
27
+ rect = Chingu::Rect.new(@x - SIZE/2, @y - SIZE/2, SIZE, SIZE)
28
+ $window.draw_rect(rect, Gosu::Color::RED, 0)
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ require "chingu"
2
+ require "hasu"
3
+
4
+ Hasu.load "ball.rb"
5
+
6
+ class Game < Chingu::Window
7
+ prepend Hasu::Guard
8
+
9
+ def initialize
10
+ super(640, 480, false)
11
+ reset
12
+ end
13
+
14
+ def reset
15
+ Ball.create
16
+ Ball.create
17
+ end
18
+ end
19
+
20
+ Game.new.show
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module Hasu
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -18,10 +18,10 @@ module Hasu
18
18
  reset unless Hasu.error
19
19
  end
20
20
 
21
- def self.run
21
+ def self.run(*args)
22
22
  unless @running
23
23
  @running = true
24
- new.show
24
+ new(*args).show
25
25
  end
26
26
  end
27
27
  end
data/todo ADDED
@@ -0,0 +1,4 @@
1
+ guard "macro"
2
+ dead code removal
3
+ autoload?
4
+ constant reloading?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hasu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Fairley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-23 00:00:00.000000000 Z
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -64,13 +64,17 @@ files:
64
64
  - LICENSE.txt
65
65
  - README.md
66
66
  - Rakefile
67
- - example/example.rb
68
- - example/rect.rb
67
+ - examples/chingu/Gemfile
68
+ - examples/chingu/ball.rb
69
+ - examples/chingu/game.rb
70
+ - examples/gosu/example.rb
71
+ - examples/gosu/rect.rb
69
72
  - hasu.gemspec
70
73
  - lib/hasu.rb
71
74
  - lib/hasu/guard.rb
72
75
  - lib/hasu/version.rb
73
76
  - lib/hasu/window.rb
77
+ - todo
74
78
  homepage: https://github.com/michaelfairley/hasu
75
79
  licenses:
76
80
  - MIT