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 +4 -4
- data/README.md +94 -1
- data/examples/chingu/Gemfile +4 -0
- data/examples/chingu/ball.rb +30 -0
- data/examples/chingu/game.rb +20 -0
- data/{example → examples/gosu}/example.rb +0 -0
- data/{example → examples/gosu}/rect.rb +0 -0
- data/lib/hasu/version.rb +1 -1
- data/lib/hasu/window.rb +2 -2
- data/todo +4 -0
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2f7ee58112372fb8e8114ae99fc4a7b8befe080
|
4
|
+
data.tar.gz: 736cb6f783a78dc33339df3cc2660ff29d400ebe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c3d778bf199a8d6d2314d1dd0ef65f70dc460fec6ff75eb75098290a6db82ee4f160b1c301c8f679a6c8f98aef476b117030ca40d4157530c60a11ad577a712
|
7
|
+
data.tar.gz: e44614e265e3bcf6a23ff988676e35a3c54b0d0a824076cfdea4f907e6fc9929a7499b13ac3604c8bdc0064907fb2f34218a0a2a55c592e8c58d123be820cb21
|
data/README.md
CHANGED
@@ -1 +1,94 @@
|
|
1
|
-
|
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,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
|
data/lib/hasu/version.rb
CHANGED
data/lib/hasu/window.rb
CHANGED
data/todo
ADDED
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
|
+
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:
|
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
|
-
-
|
68
|
-
-
|
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
|