rubyhop 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Manifest.txt +12 -9
- data/Rakefile +1 -1
- data/bin/rubyhop +1 -1
- data/lib/{background.png → rubyhop/assets/background.png} +0 -0
- data/lib/{gameover.mp3 → rubyhop/assets/gameover.mp3} +0 -0
- data/lib/{hoop.png → rubyhop/assets/hoop.png} +0 -0
- data/lib/{hop.mp3 → rubyhop/assets/hop.mp3} +0 -0
- data/lib/{music.mp3 → rubyhop/assets/music.mp3} +0 -0
- data/lib/{rubyguy-dead.png → rubyhop/assets/rubyguy-dead.png} +0 -0
- data/lib/{rubyguy-fall.png → rubyhop/assets/rubyguy-fall.png} +0 -0
- data/lib/{rubyguy-rise.png → rubyhop/assets/rubyguy-rise.png} +0 -0
- data/lib/{rubyguy.png → rubyhop/assets/rubyguy.png} +0 -0
- data/lib/rubyhop/hoop.rb +23 -0
- data/lib/rubyhop/level.rb +181 -0
- data/lib/rubyhop/player.rb +60 -0
- data/lib/rubyhop.rb +43 -285
- data/test/test_rubyhop.rb +114 -2
- metadata +15 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a79c2be24346b3a2b05d7a5faa1a11468f0718d
|
4
|
+
data.tar.gz: 3c4c10013ba91b663be0b2edb21179fb101e3616
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0c2033ee10d5375b6df619e3cd35310644274eebc51f0397dae6a57ff8e2665f2c6558b0163585c90027d10b0da7535a8f55c7f310f1abc0ba2269d60b18150
|
7
|
+
data.tar.gz: 861d015e110241042a446371981cf3e53fb6b038c3daf7257a2631b19e71d8a0ed1e91aaf1a859ff617f050aedaa0ff8698f0484088c6c1a0d6bad870ea4cca1
|
data/Manifest.txt
CHANGED
@@ -4,14 +4,17 @@ Manifest.txt
|
|
4
4
|
README.txt
|
5
5
|
Rakefile
|
6
6
|
bin/rubyhop
|
7
|
-
lib/background.png
|
8
|
-
lib/gameover.mp3
|
9
|
-
lib/hoop.png
|
10
|
-
lib/hop.mp3
|
11
|
-
lib/music.mp3
|
12
|
-
lib/rubyguy-dead.png
|
13
|
-
lib/rubyguy-fall.png
|
14
|
-
lib/rubyguy-rise.png
|
15
|
-
lib/rubyguy.png
|
16
7
|
lib/rubyhop.rb
|
8
|
+
lib/rubyhop/assets/background.png
|
9
|
+
lib/rubyhop/assets/gameover.mp3
|
10
|
+
lib/rubyhop/assets/hoop.png
|
11
|
+
lib/rubyhop/assets/hop.mp3
|
12
|
+
lib/rubyhop/assets/music.mp3
|
13
|
+
lib/rubyhop/assets/rubyguy-dead.png
|
14
|
+
lib/rubyhop/assets/rubyguy-fall.png
|
15
|
+
lib/rubyhop/assets/rubyguy-rise.png
|
16
|
+
lib/rubyhop/assets/rubyguy.png
|
17
|
+
lib/rubyhop/hoop.rb
|
18
|
+
lib/rubyhop/level.rb
|
19
|
+
lib/rubyhop/player.rb
|
17
20
|
test/test_rubyhop.rb
|
data/Rakefile
CHANGED
data/bin/rubyhop
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/rubyhop/hoop.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Hoop
|
2
|
+
attr_accessor :x, :y, :active
|
3
|
+
def initialize
|
4
|
+
@hoop = Rubyhop.image "hoop.png"
|
5
|
+
# center of screen
|
6
|
+
@x = @y = 0
|
7
|
+
@active = true
|
8
|
+
end
|
9
|
+
def miss player
|
10
|
+
if (@x - player.x).abs < 12 &&
|
11
|
+
(@y - player.y).abs > 72
|
12
|
+
# the player missed the hoop
|
13
|
+
return true
|
14
|
+
end
|
15
|
+
false
|
16
|
+
end
|
17
|
+
def update movement
|
18
|
+
@x -= movement
|
19
|
+
end
|
20
|
+
def draw
|
21
|
+
@hoop.draw @x - 66, @y - 98, 1000 - @x
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
class Level
|
2
|
+
def initialize
|
3
|
+
# Add callback holders
|
4
|
+
@continue_callbacks = []
|
5
|
+
@quit_callbacks = []
|
6
|
+
@fail_callbacks = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def on_continue &block
|
10
|
+
@continue_callbacks << block
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_quit &block
|
14
|
+
@quit_callbacks << block
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_fail &block
|
18
|
+
@fail_callbacks << block
|
19
|
+
end
|
20
|
+
|
21
|
+
def continue!
|
22
|
+
@continue_callbacks.each { |c| c.call }
|
23
|
+
end
|
24
|
+
|
25
|
+
def quit!
|
26
|
+
@quit_callbacks.each { |c| c.call }
|
27
|
+
end
|
28
|
+
|
29
|
+
def fail!
|
30
|
+
@fail_callbacks.each { |c| c.call }
|
31
|
+
end
|
32
|
+
|
33
|
+
def start!
|
34
|
+
raise "Must override"
|
35
|
+
end
|
36
|
+
|
37
|
+
def update
|
38
|
+
raise "Must override"
|
39
|
+
end
|
40
|
+
|
41
|
+
def draw
|
42
|
+
raise "Must override"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
class HopLevel < Level
|
48
|
+
attr_accessor :movement, :score
|
49
|
+
def initialize
|
50
|
+
super
|
51
|
+
@music = Rubyhop.song "music.mp3"
|
52
|
+
@music.play true
|
53
|
+
@player = Player.new
|
54
|
+
@hoops = 6.times.map { Hoop.new }
|
55
|
+
init_hoops!
|
56
|
+
@movement = 3
|
57
|
+
end
|
58
|
+
|
59
|
+
def start!
|
60
|
+
@score = 0
|
61
|
+
@movement = 3
|
62
|
+
@player.start!
|
63
|
+
init_hoops!
|
64
|
+
end
|
65
|
+
|
66
|
+
def init_hoops!
|
67
|
+
@hoops.each do |hoop|
|
68
|
+
hoop.y = 325
|
69
|
+
end
|
70
|
+
hoop_start = 400
|
71
|
+
@hoops.each do |hoop|
|
72
|
+
reset_hoop! hoop
|
73
|
+
hoop_start += 200
|
74
|
+
hoop.x = hoop_start
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def reset_hoop! hoop
|
79
|
+
idx = @hoops.index hoop
|
80
|
+
prev = @hoops[idx - 1]
|
81
|
+
new_y = ((prev.y-150..prev.y+125).to_a & (150..500).to_a).sample
|
82
|
+
hoop.x += 1200
|
83
|
+
hoop.y = new_y
|
84
|
+
hoop.active = true
|
85
|
+
end
|
86
|
+
|
87
|
+
def button_down id
|
88
|
+
quit! if id == Gosu::KbEscape
|
89
|
+
@player.hop if id == Gosu::KbSpace
|
90
|
+
end
|
91
|
+
|
92
|
+
def update
|
93
|
+
@movement += 0.0025
|
94
|
+
@player.update
|
95
|
+
if @player.offscreen?
|
96
|
+
# kick out to loading screen to try again?
|
97
|
+
fail!
|
98
|
+
end
|
99
|
+
@hoops.each do |hoop|
|
100
|
+
hoop.update @movement
|
101
|
+
reset_hoop!(hoop) if hoop.x < -200
|
102
|
+
@player.die! if hoop.miss @player
|
103
|
+
# increase score and flag as inactive
|
104
|
+
if hoop.active && @player.alive && hoop.x < @player.x
|
105
|
+
@score += 1
|
106
|
+
hoop.active = false
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def draw
|
112
|
+
@player.draw
|
113
|
+
@hoops.each(&:draw)
|
114
|
+
draw_score
|
115
|
+
end
|
116
|
+
|
117
|
+
def draw_score
|
118
|
+
Rubyhop.score_font.draw "Score: #{@score}", 700, 10, 1, 1.0, 1.0, Gosu::Color::RED
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class MessageLevel < Level
|
123
|
+
def initialize
|
124
|
+
super
|
125
|
+
@rubyguy = Rubyhop.image "rubyguy.png"
|
126
|
+
|
127
|
+
create_image!
|
128
|
+
end
|
129
|
+
|
130
|
+
def message
|
131
|
+
"This is a dumb message, you should override it"
|
132
|
+
end
|
133
|
+
|
134
|
+
def create_image!
|
135
|
+
@msg = Rubyhop.text_image message
|
136
|
+
end
|
137
|
+
|
138
|
+
def start!
|
139
|
+
create_image!
|
140
|
+
end
|
141
|
+
|
142
|
+
def update
|
143
|
+
quit! if Rubyhop.button_down? Gosu::KbEscape
|
144
|
+
continue! if ( Rubyhop.button_down?(Gosu::KbSpace) ||
|
145
|
+
Rubyhop.button_down?(Gosu::KbReturn) ||
|
146
|
+
Rubyhop.button_down?(Gosu::KbEnter) )
|
147
|
+
end
|
148
|
+
|
149
|
+
def draw
|
150
|
+
c = Math.cos(Rubyhop.time*4)
|
151
|
+
half_w = Rubyhop.width / 2
|
152
|
+
half_h = Rubyhop.height / 2
|
153
|
+
scale = 1.0+c*0.1
|
154
|
+
@rubyguy.draw_rot(half_w, half_h - 80, 1,
|
155
|
+
0, 0.5, 0.5, scale, scale)
|
156
|
+
|
157
|
+
s = Math.sin Rubyhop.time
|
158
|
+
scale = 1.0+(0.1*s**3).abs
|
159
|
+
@msg.draw_rot( (half_w + (100*(s)).to_i),
|
160
|
+
(half_h + 160 + (50*s**3).abs),
|
161
|
+
1, s*5, 0.5, 0.5, scale, scale,
|
162
|
+
Gosu::Color::RED )
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
class TitleLevel < MessageLevel
|
167
|
+
def message
|
168
|
+
"Stay alive by hopping!\n" +
|
169
|
+
"Press SPACE to hop!\n" +
|
170
|
+
"Press ESCAPE to close."
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class FailLevel < MessageLevel
|
175
|
+
def message
|
176
|
+
"You scored #{Rubyhop.score}.\n" +
|
177
|
+
"Your high score is #{Rubyhop.high_score}.\n" +
|
178
|
+
"Press SPACE if you dare to continue...\n" +
|
179
|
+
"Or ESCAPE if it is just too much for you."
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class Player
|
2
|
+
attr_accessor :x, :y, :alive
|
3
|
+
def initialize
|
4
|
+
# position
|
5
|
+
start!
|
6
|
+
@gravity = -0.25
|
7
|
+
@hop = 7.5
|
8
|
+
# sounds
|
9
|
+
@sound = Rubyhop.sound "hop.mp3"
|
10
|
+
@gameover = Rubyhop.sound "gameover.mp3"
|
11
|
+
# images
|
12
|
+
@rise = Rubyhop.image "rubyguy-rise.png"
|
13
|
+
@fall = Rubyhop.image "rubyguy-fall.png"
|
14
|
+
@dead = Rubyhop.image "rubyguy-dead.png"
|
15
|
+
end
|
16
|
+
def hop
|
17
|
+
if @alive
|
18
|
+
@sound.play
|
19
|
+
@velocity += @hop
|
20
|
+
end
|
21
|
+
end
|
22
|
+
def start!
|
23
|
+
@x = Rubyhop.width / 3
|
24
|
+
@y = Rubyhop.height / 2
|
25
|
+
@velocity = 0.0
|
26
|
+
@alive = true
|
27
|
+
end
|
28
|
+
def die!
|
29
|
+
if @alive
|
30
|
+
# Set velocity to one last hop
|
31
|
+
@velocity = 5.0
|
32
|
+
@gameover.play
|
33
|
+
@alive = false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
def update
|
37
|
+
@velocity += @gravity
|
38
|
+
@y -= @velocity
|
39
|
+
if @alive && (@y < 32 || @y > Rubyhop.height - 32)
|
40
|
+
die!
|
41
|
+
end
|
42
|
+
end
|
43
|
+
def offscreen?
|
44
|
+
@y > 1000
|
45
|
+
end
|
46
|
+
def draw
|
47
|
+
image.draw @x - 32, @y - 32, 1000 - @x
|
48
|
+
end
|
49
|
+
def image
|
50
|
+
if @alive
|
51
|
+
if @velocity >= 0
|
52
|
+
@rise
|
53
|
+
else
|
54
|
+
@fall
|
55
|
+
end
|
56
|
+
else
|
57
|
+
@dead
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/rubyhop.rb
CHANGED
@@ -1,330 +1,87 @@
|
|
1
1
|
require "gosu"
|
2
|
+
require "singleton"
|
3
|
+
require "rubyhop/level"
|
4
|
+
require "rubyhop/player"
|
5
|
+
require "rubyhop/hoop"
|
2
6
|
|
3
7
|
def get_my_file file
|
4
|
-
"#{File.dirname(__FILE__)}/#{file}"
|
8
|
+
"#{File.dirname(__FILE__)}/rubyhop/assets/#{file}"
|
5
9
|
end
|
6
10
|
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
@level = level
|
11
|
-
@window = @level.window
|
12
|
-
# position
|
13
|
-
start!
|
14
|
-
@gravity = -0.25
|
15
|
-
@hop = 7.5
|
16
|
-
# sounds
|
17
|
-
@sound = Gosu::Sample.new @window, get_my_file("hop.mp3")
|
18
|
-
@gameover = Gosu::Sample.new @window, get_my_file("gameover.mp3")
|
19
|
-
# images
|
20
|
-
@rise = Gosu::Image.new @window, get_my_file("rubyguy-rise.png")
|
21
|
-
@fall = Gosu::Image.new @window, get_my_file("rubyguy-fall.png")
|
22
|
-
@dead = Gosu::Image.new @window, get_my_file("rubyguy-dead.png")
|
23
|
-
end
|
24
|
-
def hop
|
25
|
-
if @alive
|
26
|
-
@sound.play
|
27
|
-
@velocity += @hop
|
28
|
-
end
|
29
|
-
end
|
30
|
-
def start!
|
31
|
-
@x = @window.width/3
|
32
|
-
@y = @window.height/2
|
33
|
-
@velocity = 0.0
|
34
|
-
@alive = true
|
35
|
-
end
|
36
|
-
def die!
|
37
|
-
if @alive
|
38
|
-
# Set velocity to one last hop
|
39
|
-
@velocity = 5.0
|
40
|
-
@gameover.play
|
41
|
-
@alive = false
|
42
|
-
end
|
43
|
-
end
|
44
|
-
def update
|
45
|
-
@velocity += @gravity
|
46
|
-
@y -= @velocity
|
47
|
-
if @alive && (@y < 32 || @y > @window.height - 32)
|
48
|
-
die!
|
49
|
-
end
|
50
|
-
if @y > 1000
|
51
|
-
# kick out to loading screen to try again?
|
52
|
-
@level.fail!
|
53
|
-
end
|
54
|
-
end
|
55
|
-
def draw
|
56
|
-
image.draw @x - 32, @y - 32, 1000 - @x
|
57
|
-
end
|
58
|
-
def image
|
59
|
-
if @alive
|
60
|
-
if @velocity >= 0
|
61
|
-
@rise
|
62
|
-
else
|
63
|
-
@fall
|
64
|
-
end
|
65
|
-
else
|
66
|
-
@dead
|
67
|
-
end
|
11
|
+
class Sound < Gosu::Sample
|
12
|
+
def initialize filename
|
13
|
+
super Rubyhop.instance, get_my_file(filename)
|
68
14
|
end
|
69
15
|
end
|
70
16
|
|
71
|
-
class
|
72
|
-
|
73
|
-
|
74
|
-
@level = level
|
75
|
-
@window = @level.window
|
76
|
-
@hoop = Gosu::Image.new @window, get_my_file("hoop.png")
|
77
|
-
# center of screen
|
78
|
-
@x = @y = 0
|
79
|
-
@active = true
|
80
|
-
end
|
81
|
-
def miss player
|
82
|
-
if (@x - player.x).abs < 12 &&
|
83
|
-
(@y - player.y).abs > 72
|
84
|
-
# the player missed the hoop
|
85
|
-
return true
|
86
|
-
end
|
87
|
-
false
|
88
|
-
end
|
89
|
-
def update
|
90
|
-
@x -= @level.movement
|
91
|
-
end
|
92
|
-
def draw
|
93
|
-
@hoop.draw @x - 66, @y - 98, 1000 - @x
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
class HopLevel
|
98
|
-
attr_accessor :window, :movement, :score
|
99
|
-
def initialize window
|
100
|
-
@window = window
|
101
|
-
@music = Gosu::Song.new @window, get_my_file("music.mp3")
|
102
|
-
@music.play true
|
103
|
-
@player = Player.new self
|
104
|
-
@hoops = 6.times.map { Hoop.new self }
|
105
|
-
init_hoops!
|
106
|
-
@font = Gosu::Font.new @window, Gosu::default_font_name, 20
|
107
|
-
@movement = 3
|
108
|
-
|
109
|
-
# Add callback holders
|
110
|
-
@fail_callbacks = []
|
111
|
-
@quit_callbacks = []
|
112
|
-
end
|
113
|
-
|
114
|
-
def on_fail &block
|
115
|
-
@fail_callbacks << block
|
116
|
-
end
|
117
|
-
|
118
|
-
def on_quit &block
|
119
|
-
@quit_callbacks << block
|
120
|
-
end
|
121
|
-
|
122
|
-
def start!
|
123
|
-
@score = 0
|
124
|
-
@movement = 3
|
125
|
-
@player.start!
|
126
|
-
init_hoops!
|
127
|
-
end
|
128
|
-
|
129
|
-
def fail!
|
130
|
-
@fail_callbacks.each { |c| c.call }
|
131
|
-
end
|
132
|
-
|
133
|
-
def quit!
|
134
|
-
@quit_callbacks.each { |c| c.call }
|
135
|
-
end
|
136
|
-
|
137
|
-
def init_hoops!
|
138
|
-
@hoops.each do |hoop|
|
139
|
-
hoop.y = 325
|
140
|
-
end
|
141
|
-
hoop_start = 400
|
142
|
-
@hoops.each do |hoop|
|
143
|
-
reset_hoop! hoop
|
144
|
-
hoop_start += 200
|
145
|
-
hoop.x = hoop_start
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def reset_hoop! hoop
|
150
|
-
idx = @hoops.index hoop
|
151
|
-
prev = @hoops[idx - 1]
|
152
|
-
new_y = ((prev.y-150..prev.y+125).to_a & (150..500).to_a).sample
|
153
|
-
hoop.x += 1200
|
154
|
-
hoop.y = new_y
|
155
|
-
hoop.active = true
|
156
|
-
end
|
157
|
-
|
158
|
-
def button_down id
|
159
|
-
quit! if id == Gosu::KbEscape
|
160
|
-
@player.hop if id == Gosu::KbSpace
|
161
|
-
end
|
162
|
-
|
163
|
-
def update
|
164
|
-
@movement += 0.0025
|
165
|
-
@player.update
|
166
|
-
@hoops.each do |hoop|
|
167
|
-
hoop.update
|
168
|
-
reset_hoop!(hoop) if hoop.x < -200
|
169
|
-
@player.die! if hoop.miss @player
|
170
|
-
# increase score and flag as inactive
|
171
|
-
if hoop.active && @player.alive && hoop.x < @player.x
|
172
|
-
@score += 1
|
173
|
-
hoop.active = false
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def draw
|
179
|
-
@player.draw
|
180
|
-
@hoops.each &:draw
|
181
|
-
@font.draw "Score: #{@score}", 700, 10, 1, 1.0, 1.0, Gosu::Color::RED
|
17
|
+
class Song < Gosu::Song
|
18
|
+
def initialize filename
|
19
|
+
super Rubyhop.instance, get_my_file(filename)
|
182
20
|
end
|
183
21
|
end
|
184
22
|
|
185
|
-
class
|
186
|
-
attr_accessor :
|
187
|
-
def initialize
|
188
|
-
@
|
189
|
-
|
190
|
-
|
191
|
-
create_image!
|
192
|
-
|
193
|
-
# Add callback holders
|
194
|
-
@continue_callbacks = []
|
195
|
-
@quit_callbacks = []
|
196
|
-
end
|
197
|
-
|
198
|
-
def create_image!
|
199
|
-
@msg = Gosu::Image.from_text @window,
|
200
|
-
"Stay alive by hopping!\n" +
|
201
|
-
"Press SPACE to hop!\n" +
|
202
|
-
"Press ESCAPE to close.",
|
203
|
-
Gosu::default_font_name, 24
|
204
|
-
@msg_x = @window.width/2 - @msg.width/2
|
205
|
-
@msg_y = @window.height * 2 / 3
|
206
|
-
end
|
207
|
-
|
208
|
-
def on_continue &block
|
209
|
-
@continue_callbacks << block
|
210
|
-
end
|
211
|
-
|
212
|
-
def on_quit &block
|
213
|
-
@quit_callbacks << block
|
214
|
-
end
|
215
|
-
|
216
|
-
def continue!
|
217
|
-
@continue_callbacks.each { |c| c.call }
|
23
|
+
class Image < Gosu::Image
|
24
|
+
attr_accessor :filename
|
25
|
+
def initialize filename
|
26
|
+
@filename = filename
|
27
|
+
super Rubyhop.instance, get_my_file(filename)
|
218
28
|
end
|
219
29
|
|
220
|
-
def
|
221
|
-
|
222
|
-
end
|
223
|
-
|
224
|
-
def start!
|
225
|
-
create_image!
|
226
|
-
end
|
227
|
-
|
228
|
-
def update
|
229
|
-
quit! if @window.button_down? Gosu::KbEscape
|
230
|
-
continue! if ( @window.button_down?(Gosu::KbSpace) ||
|
231
|
-
@window.button_down?(Gosu::KbReturn) ||
|
232
|
-
@window.button_down?(Gosu::KbEnter) )
|
233
|
-
end
|
234
|
-
|
235
|
-
def draw
|
236
|
-
c = Math.cos(@window.time*4)
|
237
|
-
@rubyguy.draw_rot(((@window.width)/2), ((@window.height)/2 - 80), 1, 0,
|
238
|
-
0.5, 0.5, 1.0+c*0.1, 1.0+c*0.1)
|
239
|
-
s = Math.sin @window.time
|
240
|
-
@msg.draw_rot( ((@window.width)/2 + (100*(s)).to_i),
|
241
|
-
((@window.height)/2 + 160 + s*s*s.abs*50),
|
242
|
-
1, s*5, 0.5, 0.5,
|
243
|
-
1.0+(0.1*s*s*s.abs), 1.0+(0.1*s*s*s.abs),
|
244
|
-
Gosu::Color::RED )
|
30
|
+
def self.from_text message, font = Gosu::default_font_name, size = 24
|
31
|
+
super Rubyhop.instance, message, font, size
|
245
32
|
end
|
246
33
|
end
|
247
34
|
|
248
|
-
class
|
249
|
-
|
250
|
-
def initialize window
|
251
|
-
@window = window
|
252
|
-
@rubyguy = Gosu::Image.new @window, get_my_file("rubyguy.png")
|
35
|
+
class Rubyhop < Gosu::Window
|
36
|
+
VERSION = "1.4.0"
|
253
37
|
|
254
|
-
|
38
|
+
include Singleton
|
255
39
|
|
256
|
-
|
257
|
-
@continue_callbacks = []
|
258
|
-
@quit_callbacks = []
|
259
|
-
end
|
260
|
-
|
261
|
-
def create_image!
|
262
|
-
@msg = Gosu::Image.from_text @window,
|
263
|
-
"You scored #{@window.score}.\n" +
|
264
|
-
"Your high score is #{@window.high_score}.\n" +
|
265
|
-
"Press SPACE if you dare to continue...\n" +
|
266
|
-
"Or ESCAPE if it is just too much for you.",
|
267
|
-
Gosu::default_font_name, 24
|
268
|
-
@msg_x = @window.width/2 - @msg.width/2
|
269
|
-
@msg_y = @window.height * 2 / 3
|
270
|
-
end
|
40
|
+
attr_reader :time, :sounds, :score, :high_score
|
271
41
|
|
272
|
-
def
|
273
|
-
|
42
|
+
def self.image filename
|
43
|
+
Image.new filename
|
274
44
|
end
|
275
45
|
|
276
|
-
def
|
277
|
-
|
46
|
+
def self.text_image message, font = Gosu::default_font_name, size = 24
|
47
|
+
Image.from_text message, font, size
|
278
48
|
end
|
279
49
|
|
280
|
-
def
|
281
|
-
|
50
|
+
def self.song filename
|
51
|
+
Song.new filename
|
282
52
|
end
|
283
53
|
|
284
|
-
def
|
285
|
-
|
54
|
+
def self.sound filename
|
55
|
+
Sound.new filename
|
286
56
|
end
|
287
57
|
|
288
|
-
def
|
289
|
-
|
58
|
+
def self.score_font
|
59
|
+
@@font ||= Gosu::Font.new Rubyhop.instance, Gosu::default_font_name, 20
|
290
60
|
end
|
291
61
|
|
292
|
-
def
|
293
|
-
|
294
|
-
continue! if ( @window.button_down?(Gosu::KbSpace) ||
|
295
|
-
@window.button_down?(Gosu::KbReturn) ||
|
296
|
-
@window.button_down?(Gosu::KbEnter) )
|
62
|
+
def self.play!
|
63
|
+
self.instance.setup.show
|
297
64
|
end
|
298
65
|
|
299
|
-
def
|
300
|
-
|
301
|
-
@rubyguy.draw_rot(((@window.width)/2), ((@window.height)/2 - 80), 1, 0,
|
302
|
-
0.5, 0.5, 1.0+c*0.1, 1.0+c*0.1)
|
303
|
-
s = Math.sin @window.time
|
304
|
-
@msg.draw_rot( ((@window.width)/2 + (100*(s)).to_i),
|
305
|
-
((@window.height)/2 + 160 + s*s*s.abs*50),
|
306
|
-
1, s*5, 0.5, 0.5,
|
307
|
-
1.0+(0.1*s*s*s.abs), 1.0+(0.1*s*s*s.abs),
|
308
|
-
Gosu::Color::RED )
|
66
|
+
def self.method_missing method, *args
|
67
|
+
self.instance.send(method, *args)
|
309
68
|
end
|
310
|
-
end
|
311
69
|
|
312
|
-
class RubyhopGame < Gosu::Window
|
313
|
-
VERSION = "1.3.1"
|
314
|
-
attr_reader :time, :sounds, :score, :high_score
|
315
70
|
def initialize width=800, height=600, fullscreen=false
|
316
71
|
super
|
72
|
+
end
|
317
73
|
|
74
|
+
def setup
|
318
75
|
self.caption = "Ruby Hop - #{VERSION}"
|
319
|
-
@background =
|
76
|
+
@background = Rubyhop.image "background.png"
|
320
77
|
|
321
78
|
# Scores
|
322
79
|
@score = @high_score = 0
|
323
80
|
|
324
81
|
# Levels
|
325
|
-
@title = TitleLevel.new
|
326
|
-
@hop = HopLevel.new
|
327
|
-
@fail = FailLevel.new
|
82
|
+
@title = TitleLevel.new
|
83
|
+
@hop = HopLevel.new
|
84
|
+
@fail = FailLevel.new
|
328
85
|
|
329
86
|
@title.on_continue { play! }
|
330
87
|
@title.on_quit { close }
|
@@ -336,6 +93,7 @@ class RubyhopGame < Gosu::Window
|
|
336
93
|
@fail.on_quit { close }
|
337
94
|
|
338
95
|
title!
|
96
|
+
self
|
339
97
|
end
|
340
98
|
|
341
99
|
def title!
|
data/test/test_rubyhop.rb
CHANGED
@@ -1,8 +1,120 @@
|
|
1
|
-
require "
|
1
|
+
require "minitest/autorun"
|
2
2
|
require "rubyhop"
|
3
3
|
|
4
|
-
class TestRubyhop < Test
|
4
|
+
class TestRubyhop < MiniTest::Test
|
5
5
|
def test_sanity
|
6
6
|
flunk "write tests or I will kneecap you"
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
class TestLevel < MiniTest::Test
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@callbacks = {quit: 0, fail: 0, continue: 0}
|
14
|
+
@level = Level.new
|
15
|
+
@level.on_quit { @callbacks[:quit] += 1 }
|
16
|
+
@level.on_fail { @callbacks[:fail] += 1 }
|
17
|
+
@level.on_continue { @callbacks[:continue] += 1 }
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_fail
|
21
|
+
assert_equal 0, @callbacks[:fail]
|
22
|
+
@level.fail!
|
23
|
+
assert_equal 1, @callbacks[:fail]
|
24
|
+
@level.fail!
|
25
|
+
@level.fail!
|
26
|
+
assert_equal 3, @callbacks[:fail]
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_quit
|
30
|
+
assert_equal 0, @callbacks[:quit]
|
31
|
+
@level.quit!
|
32
|
+
assert_equal 1, @callbacks[:quit]
|
33
|
+
@level.quit!
|
34
|
+
@level.quit!
|
35
|
+
assert_equal 3, @callbacks[:quit]
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_continue
|
39
|
+
assert_equal 0, @callbacks[:continue]
|
40
|
+
@level.continue!
|
41
|
+
assert_equal 1, @callbacks[:continue]
|
42
|
+
@level.continue!
|
43
|
+
@level.continue!
|
44
|
+
assert_equal 3, @callbacks[:continue]
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_raises
|
48
|
+
assert_raises RuntimeError do
|
49
|
+
@level.start!
|
50
|
+
end
|
51
|
+
assert_raises RuntimeError do
|
52
|
+
@level.update
|
53
|
+
end
|
54
|
+
assert_raises RuntimeError do
|
55
|
+
@level.draw
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class TestPlayer < MiniTest::Test
|
61
|
+
|
62
|
+
def setup
|
63
|
+
@player = Player.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_initialization
|
67
|
+
assert_equal 266, @player.x
|
68
|
+
assert_equal 300, @player.y
|
69
|
+
assert_equal true, @player.alive
|
70
|
+
assert_equal 'rubyguy-rise.png', @player.image.filename
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_hop
|
74
|
+
@player.hop
|
75
|
+
@player.update
|
76
|
+
assert_equal 266, @player.x
|
77
|
+
assert_equal 292.75, @player.y
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_gravity
|
81
|
+
3.times do
|
82
|
+
@player.update
|
83
|
+
end
|
84
|
+
assert_equal 'rubyguy-fall.png', @player.image.filename
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_die_bang
|
88
|
+
@player.die!
|
89
|
+
assert_equal false, @player.alive
|
90
|
+
assert_equal 'rubyguy-dead.png', @player.image.filename
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_offscreen_eh
|
94
|
+
assert_equal false, @player.offscreen?
|
95
|
+
140.times do
|
96
|
+
@player.update
|
97
|
+
end
|
98
|
+
assert_equal true, @player.offscreen?
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class TestHoop < MiniTest::Test
|
103
|
+
|
104
|
+
def setup
|
105
|
+
@hoop = Hoop.new
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_initialize
|
109
|
+
assert_equal 0, @hoop.x
|
110
|
+
assert_equal 0, @hoop.y
|
111
|
+
assert_equal true, @hoop.active
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_update
|
115
|
+
@hoop.update 10
|
116
|
+
assert_equal -10, @hoop.x
|
117
|
+
assert_equal 0, @hoop.y
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyhop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -70,16 +70,19 @@ files:
|
|
70
70
|
- README.txt
|
71
71
|
- Rakefile
|
72
72
|
- bin/rubyhop
|
73
|
-
- lib/background.png
|
74
|
-
- lib/gameover.mp3
|
75
|
-
- lib/hoop.png
|
76
|
-
- lib/hop.mp3
|
77
|
-
- lib/music.mp3
|
78
|
-
- lib/rubyguy-dead.png
|
79
|
-
- lib/rubyguy-fall.png
|
80
|
-
- lib/rubyguy-rise.png
|
81
|
-
- lib/rubyguy.png
|
82
73
|
- lib/rubyhop.rb
|
74
|
+
- lib/rubyhop/assets/background.png
|
75
|
+
- lib/rubyhop/assets/gameover.mp3
|
76
|
+
- lib/rubyhop/assets/hoop.png
|
77
|
+
- lib/rubyhop/assets/hop.mp3
|
78
|
+
- lib/rubyhop/assets/music.mp3
|
79
|
+
- lib/rubyhop/assets/rubyguy-dead.png
|
80
|
+
- lib/rubyhop/assets/rubyguy-fall.png
|
81
|
+
- lib/rubyhop/assets/rubyguy-rise.png
|
82
|
+
- lib/rubyhop/assets/rubyguy.png
|
83
|
+
- lib/rubyhop/hoop.rb
|
84
|
+
- lib/rubyhop/level.rb
|
85
|
+
- lib/rubyhop/player.rb
|
83
86
|
- test/test_rubyhop.rb
|
84
87
|
homepage: http://blowmage.com/rubyhop
|
85
88
|
licenses:
|
@@ -103,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
106
|
version: '0'
|
104
107
|
requirements: []
|
105
108
|
rubyforge_project: rubyhop
|
106
|
-
rubygems_version: 2.2.
|
109
|
+
rubygems_version: 2.2.2
|
107
110
|
signing_key:
|
108
111
|
specification_version: 4
|
109
112
|
summary: Super awesome Ruby-themed game
|