Class: FailLevel

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyhop.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ FailLevel

Returns a new instance of FailLevel.



250
251
252
253
254
255
256
257
258
259
# File 'lib/rubyhop.rb', line 250

def initialize window
  @window = window
  @rubyguy = Gosu::Image.new @window, get_my_file("rubyguy.png")

  create_image!

  # Add callback holders
  @continue_callbacks = []
  @quit_callbacks = []
end

Instance Attribute Details

#windowObject

Returns the value of attribute window.



249
250
251
# File 'lib/rubyhop.rb', line 249

def window
  @window
end

Instance Method Details

#continue!Object



280
281
282
# File 'lib/rubyhop.rb', line 280

def continue!
  @continue_callbacks.each { |c| c.call }
end

#create_image!Object



261
262
263
264
265
266
267
268
269
270
# File 'lib/rubyhop.rb', line 261

def create_image!
  @msg = Gosu::Image.from_text @window,
                              "You scored #{@window.score}.\n" +
                              "Your high score is #{@window.high_score}.\n" +
                              "Press SPACE if you dare to continue...\n" +
                              "Or ESCAPE if it is just too much for you.",
                              Gosu::default_font_name, 24
  @msg_x = @window.width/2 - @msg.width/2
  @msg_y = @window.height * 2 / 3
end

#drawObject



299
300
301
302
303
304
305
306
307
308
309
# File 'lib/rubyhop.rb', line 299

def draw
  c = Math.cos(@window.time*4)
  @rubyguy.draw_rot(((@window.width)/2), ((@window.height)/2 - 80), 1, 0,
                    0.5, 0.5, 1.0+c*0.1, 1.0+c*0.1)
  s = Math.sin @window.time
  @msg.draw_rot( ((@window.width)/2 + (100*(s)).to_i),
                  ((@window.height)/2 + 160 + s*s*s.abs*50),
                  1, s*5, 0.5, 0.5,
                  1.0+(0.1*s*s*s.abs), 1.0+(0.1*s*s*s.abs),
                  Gosu::Color::RED )
end

#on_continue(&block) ⇒ Object



272
273
274
# File 'lib/rubyhop.rb', line 272

def on_continue &block
  @continue_callbacks << block
end

#on_quit(&block) ⇒ Object



276
277
278
# File 'lib/rubyhop.rb', line 276

def on_quit &block
  @quit_callbacks << block
end

#quit!Object



284
285
286
# File 'lib/rubyhop.rb', line 284

def quit!
  @quit_callbacks.each { |c| c.call }
end

#start!Object



288
289
290
# File 'lib/rubyhop.rb', line 288

def start!
  create_image!
end

#updateObject



292
293
294
295
296
297
# File 'lib/rubyhop.rb', line 292

def update
  quit!     if @window.button_down? Gosu::KbEscape
  continue! if ( @window.button_down?(Gosu::KbSpace)  ||
                 @window.button_down?(Gosu::KbReturn) ||
                 @window.button_down?(Gosu::KbEnter)  )
end