rubyhop 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +5 -0
  3. data/lib/rubyhop.rb +87 -17
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 957ec92efc1036be06cb60d23aedad68cf0ad1da
4
- data.tar.gz: f7aac31a776fa91c8451d67322acf0f86f09bd2c
3
+ metadata.gz: 14cab3b2f1ec3a04694a4d96317b67a420eb33bf
4
+ data.tar.gz: aa1825f9d0bd7c1480bf59d23f3d175e8879140a
5
5
  SHA512:
6
- metadata.gz: 903d1ebedb4f768e933a46c1e01ccf7b88c5aa14ed53717e5eb781ac02dd320f323dfdc805fc9ebe2a1fa7646427bb472d86d9056c16a767853f2fb6d33f77e8
7
- data.tar.gz: fd21aa49f77ccba3f7397692a5200f314f9978ab7d5216030696133cc66936c87e0797610e51b6a5fdc093c48ada750d4007083635f1404af31bd0267f482c0f
6
+ metadata.gz: 9b1e12acaea1fc4a04d52f459408d3dc9acd443389fb37b6e702738f15b06b899f5366ec94fa40f5cb92aedae187b91891da7541303f50af1bf2351125245073
7
+ data.tar.gz: c15cc7cbb0c65a011c2281dcc1b48eb01ba62a19e6acfdec62628e8ed54a75034da20de988eb9ba0896e2bd36ec091dbf91f1c9f05fda00b3184fac044a490b7
data/Rakefile CHANGED
@@ -7,3 +7,8 @@ Hoe.plugin :minitest
7
7
  Hoe.spec "rubyhop" do
8
8
  developer "Mike Moore", "mike@blowmage.com"
9
9
  end
10
+
11
+ desc "Run the game"
12
+ task :run do
13
+ `ruby -Ilib -e "require 'rubyhop'; RubyhopGame.new.show"`
14
+ end
data/lib/rubyhop.rb CHANGED
@@ -28,7 +28,7 @@ class Player
28
28
  end
29
29
  end
30
30
  def start!
31
- @x = @window.width/2
31
+ @x = @window.width/3
32
32
  @y = @window.height/2
33
33
  @velocity = 0.0
34
34
  @alive = true
@@ -101,12 +101,11 @@ class HopLevel
101
101
  @window.caption = "Ruby Hop"
102
102
  @music = Gosu::Song.new @window, get_my_file("music.mp3")
103
103
  @music.play true
104
- @background = Gosu::Image.new @window, get_my_file("background.png")
105
104
  @player = Player.new self
106
105
  @hoops = 6.times.map { Hoop.new self }
107
106
  init_hoops!
108
107
  @font = Gosu::Font.new @window, Gosu::default_font_name, 20
109
- @movement = 2
108
+ @movement = 3
110
109
 
111
110
  # Add callback holders
112
111
  @fail_callbacks = []
@@ -123,7 +122,7 @@ class HopLevel
123
122
 
124
123
  def start!
125
124
  @score = 0
126
- @movement = 2
125
+ @movement = 3
127
126
  @player.start!
128
127
  init_hoops!
129
128
  end
@@ -140,7 +139,7 @@ class HopLevel
140
139
  @hoops.each do |hoop|
141
140
  hoop.y = 325
142
141
  end
143
- hoop_start = 600
142
+ hoop_start = 400
144
143
  @hoops.each do |hoop|
145
144
  reset_hoop! hoop
146
145
  hoop_start += 200
@@ -163,7 +162,7 @@ class HopLevel
163
162
  end
164
163
 
165
164
  def update
166
- @movement += 0.003
165
+ @movement += 0.0025
167
166
  @player.update
168
167
  @hoops.each do |hoop|
169
168
  hoop.update
@@ -178,18 +177,79 @@ class HopLevel
178
177
  end
179
178
 
180
179
  def draw
181
- @background.draw 0, 0, 0
182
180
  @player.draw
183
181
  @hoops.each &:draw
184
182
  @font.draw "Score: #{@score}", 700, 10, 1, 1.0, 1.0, Gosu::Color::RED
185
183
  end
186
184
  end
187
185
 
186
+ class TitleLevel
187
+ attr_accessor :window
188
+ def initialize window
189
+ @window = window
190
+ @rubyguy = Gosu::Image.new @window, get_my_file("rubyguy.png")
191
+
192
+ create_image!
193
+
194
+ # Add callback holders
195
+ @continue_callbacks = []
196
+ @quit_callbacks = []
197
+ end
198
+
199
+ def create_image!
200
+ @msg = Gosu::Image.from_text @window,
201
+ "Stay alive by hopping!\n" +
202
+ "Press SPACE to hop!\n" +
203
+ "Press ESCAPE to close.",
204
+ Gosu::default_font_name, 24
205
+ @msg_x = @window.width/2 - @msg.width/2
206
+ @msg_y = @window.height * 2 / 3
207
+ end
208
+
209
+ def on_continue &block
210
+ @continue_callbacks << block
211
+ end
212
+
213
+ def on_quit &block
214
+ @quit_callbacks << block
215
+ end
216
+
217
+ def continue!
218
+ @continue_callbacks.each { |c| c.call }
219
+ end
220
+
221
+ def quit!
222
+ @quit_callbacks.each { |c| c.call }
223
+ end
224
+
225
+ def start!
226
+ create_image!
227
+ end
228
+
229
+ def update
230
+ quit! if @window.button_down? Gosu::KbEscape
231
+ continue! if ( @window.button_down?(Gosu::KbSpace) ||
232
+ @window.button_down?(Gosu::KbReturn) ||
233
+ @window.button_down?(Gosu::KbEnter) )
234
+ end
235
+
236
+ def draw
237
+ c = Math.cos(@window.time*4)
238
+ @rubyguy.draw_rot(((@window.width)/2), ((@window.height)/2 - 80), 1, 0,
239
+ 0.5, 0.5, 1.0+c*0.1, 1.0+c*0.1)
240
+ s = Math.sin @window.time
241
+ @msg.draw_rot( ((@window.width)/2 + (100*(s)).to_i),
242
+ ((@window.height)/2 + 160 + s*s*s.abs*50),
243
+ 1, s*5, 0.5, 0.5,
244
+ 1.0+(0.1*s*s*s.abs), 1.0+(0.1*s*s*s.abs),
245
+ Gosu::Color::RED )
246
+ end
247
+ end
248
+
188
249
  class FailLevel
189
250
  attr_accessor :window
190
251
  def initialize window
191
252
  @window = window
192
- @background = Gosu::Image.new @window, get_my_file("background.png")
193
253
  @rubyguy = Gosu::Image.new @window, get_my_file("rubyguy.png")
194
254
 
195
255
  create_image!
@@ -238,7 +298,6 @@ class FailLevel
238
298
  end
239
299
 
240
300
  def draw
241
- @background.draw 0, 0, 0
242
301
  c = Math.cos(@window.time*4)
243
302
  @rubyguy.draw_rot(((@window.width)/2), ((@window.height)/2 - 80), 1, 0,
244
303
  0.5, 0.5, 1.0+c*0.1, 1.0+c*0.1)
@@ -252,27 +311,37 @@ class FailLevel
252
311
  end
253
312
 
254
313
  class RubyhopGame < Gosu::Window
255
- VERSION = "1.2.0"
314
+ VERSION = "1.3.0"
256
315
  attr_reader :time, :sounds, :score, :high_score
257
316
  def initialize width=800, height=600, fullscreen=false
258
317
  super
259
318
 
260
319
  self.caption = 'Ruby Hop'
320
+ @background = Gosu::Image.new self, get_my_file("background.png")
261
321
 
262
322
  # Scores
263
323
  @score = @high_score = 0
264
324
 
265
325
  # Levels
266
- @hop = HopLevel.new self
267
- @fail = FailLevel.new self
326
+ @title = TitleLevel.new self
327
+ @hop = HopLevel.new self
328
+ @fail = FailLevel.new self
329
+
330
+ @title.on_continue { play! }
331
+ @title.on_quit { close }
268
332
 
269
- @hop.on_fail { fail! }
270
- @hop.on_quit { close }
333
+ @hop.on_fail { fail! }
334
+ @hop.on_quit { close }
271
335
 
272
- @fail.on_continue { play! }
273
- @fail.on_quit { close }
336
+ @fail.on_continue { play! }
337
+ @fail.on_quit { close }
274
338
 
275
- play!
339
+ title!
340
+ end
341
+
342
+ def title!
343
+ @level = @title
344
+ @level.start!
276
345
  end
277
346
 
278
347
  def play!
@@ -301,6 +370,7 @@ class RubyhopGame < Gosu::Window
301
370
  end
302
371
 
303
372
  def draw
373
+ @background.draw 0, 0, 0
304
374
  @level.draw
305
375
  end
306
376
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyhop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore