Class: FailLevel

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#windowObject

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

#drawObject



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

#updateObject



42
43
44
45
46
47
# File 'lib/escape_to_rubyconf/fail_level.rb', line 42

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