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.



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

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.



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

def window
  @window
end

Instance Method Details

#continue!Object



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

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

#create_image!Object



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

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



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

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



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

def on_continue &block
  @continue_callbacks << block
end

#on_quit(&block) ⇒ Object



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

def on_quit &block
  @quit_callbacks << block
end

#quit!Object



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

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

#start!Object



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

def start!
  create_image!
end

#updateObject



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

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