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.
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/rubyhop.rb', line 188 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.
187 188 189 |
# File 'lib/rubyhop.rb', line 187 def window @window end |
Instance Method Details
#continue! ⇒ Object
217 218 219 |
# File 'lib/rubyhop.rb', line 217 def continue! @continue_callbacks.each { |c| c.call } end |
#create_image! ⇒ Object
199 200 201 202 203 204 205 206 207 |
# File 'lib/rubyhop.rb', line 199 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
236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/rubyhop.rb', line 236 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
209 210 211 |
# File 'lib/rubyhop.rb', line 209 def on_continue &block @continue_callbacks << block end |
#on_quit(&block) ⇒ Object
213 214 215 |
# File 'lib/rubyhop.rb', line 213 def on_quit &block @quit_callbacks << block end |
#quit! ⇒ Object
221 222 223 |
# File 'lib/rubyhop.rb', line 221 def quit! @quit_callbacks.each { |c| c.call } end |
#start! ⇒ Object
225 226 227 |
# File 'lib/rubyhop.rb', line 225 def start! create_image! end |
#update ⇒ Object
229 230 231 232 233 234 |
# File 'lib/rubyhop.rb', line 229 def update quit! if @window. Gosu::KbEscape continue! if ( @window.(Gosu::KbSpace) || @window.(Gosu::KbReturn) || @window.(Gosu::KbEnter) ) end |