Class: RubyhopGame

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/rubyhop.rb

Constant Summary collapse

VERSION =
"1.3.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width = 800, height = 600, fullscreen = false) ⇒ RubyhopGame

Returns a new instance of RubyhopGame.



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/rubyhop.rb', line 316

def initialize width=800, height=600, fullscreen=false
  super

  self.caption = 'Ruby Hop'
  @background = Gosu::Image.new self, get_my_file("background.png")

  # Scores
  @score = @high_score = 0

  # Levels
  @title = TitleLevel.new self
  @hop   = HopLevel.new   self
  @fail  = FailLevel.new  self

  @title.on_continue { play! }
  @title.on_quit     { close }

  @hop.on_fail       { fail! }
  @hop.on_quit       { close }

  @fail.on_continue  { play! }
  @fail.on_quit      { close }

  title!
end

Instance Attribute Details

#high_scoreObject (readonly)

Returns the value of attribute high_score.



315
316
317
# File 'lib/rubyhop.rb', line 315

def high_score
  @high_score
end

#scoreObject (readonly)

Returns the value of attribute score.



315
316
317
# File 'lib/rubyhop.rb', line 315

def score
  @score
end

#soundsObject (readonly)

Returns the value of attribute sounds.



315
316
317
# File 'lib/rubyhop.rb', line 315

def sounds
  @sounds
end

#timeObject (readonly)

Returns the value of attribute time.



315
316
317
# File 'lib/rubyhop.rb', line 315

def time
  @time
end

Instance Method Details

#button_down(id) ⇒ Object



359
360
361
# File 'lib/rubyhop.rb', line 359

def button_down id
  @level.button_down id if @level.respond_to? :button_down
end

#button_up(id) ⇒ Object



363
364
365
# File 'lib/rubyhop.rb', line 363

def button_up id
  @level.button_up id if @level.respond_to? :button_up
end

#drawObject



372
373
374
375
# File 'lib/rubyhop.rb', line 372

def draw
  @background.draw 0, 0, 0
  @level.draw
end

#fail!Object



352
353
354
355
356
357
# File 'lib/rubyhop.rb', line 352

def fail!
  @score = @hop.score
  @high_score = @score if @score > @high_score
  @level = @fail
  @level.start!
end

#play!Object



347
348
349
350
# File 'lib/rubyhop.rb', line 347

def play!
  @level = @hop
  @level.start!
end

#title!Object



342
343
344
345
# File 'lib/rubyhop.rb', line 342

def title!
  @level = @title
  @level.start!
end

#updateObject



367
368
369
370
# File 'lib/rubyhop.rb', line 367

def update
  @time = Time.now.to_f
  @level.update
end