Class: Rubyhop
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- Rubyhop
- Includes:
- Singleton
- Defined in:
- lib/rubyhop.rb
Constant Summary collapse
- VERSION =
"1.4.0"
Instance Attribute Summary collapse
-
#high_score ⇒ Object
readonly
Returns the value of attribute high_score.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#sounds ⇒ Object
readonly
Returns the value of attribute sounds.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
- .image(filename) ⇒ Object
- .method_missing(method, *args) ⇒ Object
- .play! ⇒ Object
- .score_font ⇒ Object
- .song(filename) ⇒ Object
- .sound(filename) ⇒ Object
- .text_image(message, font = Gosu::default_font_name, size = 24) ⇒ Object
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #button_up(id) ⇒ Object
- #draw ⇒ Object
- #fail! ⇒ Object
-
#initialize(width = 800, height = 600, fullscreen = false) ⇒ Rubyhop
constructor
A new instance of Rubyhop.
- #play! ⇒ Object
- #setup ⇒ Object
- #title! ⇒ Object
- #update ⇒ Object
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_score ⇒ Object (readonly)
Returns the value of attribute high_score.
40 41 42 |
# File 'lib/rubyhop.rb', line 40 def high_score @high_score end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
40 41 42 |
# File 'lib/rubyhop.rb', line 40 def score @score end |
#sounds ⇒ Object (readonly)
Returns the value of attribute sounds.
40 41 42 |
# File 'lib/rubyhop.rb', line 40 def sounds @sounds end |
#time ⇒ Object (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_font ⇒ Object
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 |
Instance Method Details
#button_down(id) ⇒ Object
116 117 118 |
# File 'lib/rubyhop.rb', line 116 def id @level. id if @level.respond_to? :button_down end |
#button_up(id) ⇒ Object
120 121 122 |
# File 'lib/rubyhop.rb', line 120 def id @level. id if @level.respond_to? :button_up end |
#draw ⇒ Object
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 |
#setup ⇒ Object
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. = "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 |
#update ⇒ Object
124 125 126 127 |
# File 'lib/rubyhop.rb', line 124 def update @time = Time.now.to_f @level.update end |