Class: Rubyhop

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

Constant Summary collapse

VERSION =
"1.4.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Rubyhop.



70
71
72
# File 'lib/rubyhop.rb', line 70

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

Instance Attribute Details

#high_scoreObject (readonly)

Returns the value of attribute high_score.



40
41
42
# File 'lib/rubyhop.rb', line 40

def high_score
  @high_score
end

#scoreObject (readonly)

Returns the value of attribute score.



40
41
42
# File 'lib/rubyhop.rb', line 40

def score
  @score
end

#soundsObject (readonly)

Returns the value of attribute sounds.



40
41
42
# File 'lib/rubyhop.rb', line 40

def sounds
  @sounds
end

#timeObject (readonly)

Returns the value of attribute time.



40
41
42
# File 'lib/rubyhop.rb', line 40

def time
  @time
end

Class Method Details

.image(filename) ⇒ Object



42
43
44
# File 'lib/rubyhop.rb', line 42

def self.image filename
  Image.new filename
end

.method_missing(method, *args) ⇒ Object



66
67
68
# File 'lib/rubyhop.rb', line 66

def self.method_missing method, *args
  self.instance.send(method, *args)
end

.play!Object



62
63
64
# File 'lib/rubyhop.rb', line 62

def self.play!
  self.instance.setup.show
end

.score_fontObject



58
59
60
# File 'lib/rubyhop.rb', line 58

def self.score_font
  @@font ||= Gosu::Font.new Rubyhop.instance, Gosu::default_font_name, 20
end

.song(filename) ⇒ Object



50
51
52
# File 'lib/rubyhop.rb', line 50

def self.song filename
  Song.new filename
end

.sound(filename) ⇒ Object



54
55
56
# File 'lib/rubyhop.rb', line 54

def self.sound filename
  Sound.new filename
end

.text_image(message, font = Gosu::default_font_name, size = 24) ⇒ Object



46
47
48
# File 'lib/rubyhop.rb', line 46

def self.text_image message, font = Gosu::default_font_name, size = 24
  Image.from_text message, font, size
end

Instance Method Details

#button_down(id) ⇒ Object



116
117
118
# File 'lib/rubyhop.rb', line 116

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

#button_up(id) ⇒ Object



120
121
122
# File 'lib/rubyhop.rb', line 120

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

#drawObject



129
130
131
132
# File 'lib/rubyhop.rb', line 129

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

#fail!Object



109
110
111
112
113
114
# File 'lib/rubyhop.rb', line 109

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

#play!Object



104
105
106
107
# File 'lib/rubyhop.rb', line 104

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

#setupObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rubyhop.rb', line 74

def setup
  self.caption = "Ruby Hop - #{VERSION}"
  @background = Rubyhop.image "background.png"

  # Scores
  @score = @high_score = 0

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

  @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!
  self
end

#title!Object



99
100
101
102
# File 'lib/rubyhop.rb', line 99

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

#updateObject



124
125
126
127
# File 'lib/rubyhop.rb', line 124

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