Class: TitleLevel
- Inherits:
-
Object
- Object
- TitleLevel
- Defined in:
- lib/rubyhop.rb
Instance Attribute Summary collapse
-
#window ⇒ Object
Returns the value of attribute window.
Instance Method Summary collapse
- #continue! ⇒ Object
- #create_image! ⇒ Object
- #draw ⇒ Object
-
#initialize(window) ⇒ TitleLevel
constructor
A new instance of TitleLevel.
- #on_continue(&block) ⇒ Object
- #on_quit(&block) ⇒ Object
- #quit! ⇒ Object
- #start! ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(window) ⇒ TitleLevel
Returns a new instance of TitleLevel.
187 188 189 190 191 192 193 194 195 196 |
# File 'lib/rubyhop.rb', line 187 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
#window ⇒ Object
Returns the value of attribute window.
186 187 188 |
# File 'lib/rubyhop.rb', line 186 def window @window end |
Instance Method Details
#continue! ⇒ Object
216 217 218 |
# File 'lib/rubyhop.rb', line 216 def continue! @continue_callbacks.each { |c| c.call } end |
#create_image! ⇒ Object
198 199 200 201 202 203 204 205 206 |
# File 'lib/rubyhop.rb', line 198 def create_image! @msg = Gosu::Image.from_text @window, "Stay alive by hopping!\n" + "Press SPACE to hop!\n" + "Press ESCAPE to close.", Gosu::default_font_name, 24 @msg_x = @window.width/2 - @msg.width/2 @msg_y = @window.height * 2 / 3 end |
#draw ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/rubyhop.rb', line 235 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
208 209 210 |
# File 'lib/rubyhop.rb', line 208 def on_continue &block @continue_callbacks << block end |
#on_quit(&block) ⇒ Object
212 213 214 |
# File 'lib/rubyhop.rb', line 212 def on_quit &block @quit_callbacks << block end |
#quit! ⇒ Object
220 221 222 |
# File 'lib/rubyhop.rb', line 220 def quit! @quit_callbacks.each { |c| c.call } end |
#start! ⇒ Object
224 225 226 |
# File 'lib/rubyhop.rb', line 224 def start! create_image! end |
#update ⇒ Object
228 229 230 231 232 233 |
# File 'lib/rubyhop.rb', line 228 def update quit! if @window. Gosu::KbEscape continue! if ( @window.(Gosu::KbSpace) || @window.(Gosu::KbReturn) || @window.(Gosu::KbEnter) ) end |