Class: FailLevel
- Inherits:
-
Object
- Object
- FailLevel
- Defined in:
- lib/escape_to_rubyconf/fail_level.rb
Instance Attribute Summary collapse
-
#window ⇒ Object
Returns the value of attribute window.
Instance Method Summary collapse
- #continue! ⇒ Object
- #draw ⇒ Object
-
#initialize(window) ⇒ FailLevel
constructor
A new instance of FailLevel.
- #on_continue(&block) ⇒ Object
- #on_quit(&block) ⇒ Object
- #quit! ⇒ Object
- #start! ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(window) ⇒ FailLevel
Returns a new instance of FailLevel.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/escape_to_rubyconf/fail_level.rb', line 5 def initialize window @window = window @fail = Gosu::Image.new @window, File.dirname(__FILE__) + '/assets/fail.png' @msg = Gosu::Image.from_text @window, "You were defeated!\n" + "Press ESCAPE to quit. Quitter\n" + "Or SPACE to try again. Doubt it.", Gosu::default_font_name, 24 @msg_x = @window.width/2 - @msg.width/2 @msg_y = @window.height * 2 / 3 @sound = Gosu::Sample.new @window, File.dirname(__FILE__) + '/assets/fail.wav' # Add callback holders @continue_callbacks = [] @quit_callbacks = [] end |
Instance Attribute Details
#window ⇒ Object
Returns the value of attribute window.
4 5 6 |
# File 'lib/escape_to_rubyconf/fail_level.rb', line 4 def window @window end |
Instance Method Details
#continue! ⇒ Object
30 31 32 |
# File 'lib/escape_to_rubyconf/fail_level.rb', line 30 def continue! @continue_callbacks.each { |c| c.call } end |
#draw ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/escape_to_rubyconf/fail_level.rb', line 49 def draw c = Math.cos(@window.time*4) @fail.draw_rot(((@window.width)/2), ((@window.height)/2 - 80), 1, 0, 0.5, 0.5, 1.0+c*0.25, 1.0+c*0.25) 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
22 23 24 |
# File 'lib/escape_to_rubyconf/fail_level.rb', line 22 def on_continue &block @continue_callbacks << block end |
#on_quit(&block) ⇒ Object
26 27 28 |
# File 'lib/escape_to_rubyconf/fail_level.rb', line 26 def on_quit &block @quit_callbacks << block end |
#quit! ⇒ Object
34 35 36 |
# File 'lib/escape_to_rubyconf/fail_level.rb', line 34 def quit! @quit_callbacks.each { |c| c.call } end |
#start! ⇒ Object
38 39 40 |
# File 'lib/escape_to_rubyconf/fail_level.rb', line 38 def start! @sound.play end |
#update ⇒ Object
42 43 44 45 46 47 |
# File 'lib/escape_to_rubyconf/fail_level.rb', line 42 def update quit! if @window. Gosu::KbEscape continue! if ( @window.(Gosu::KbSpace) || @window.(Gosu::KbReturn) || @window.(Gosu::KbEnter) ) end |