Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/rubyhop
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#!/usr/bin/env ruby
require "rubyhop"
RubyhopGame.new.show

if ARGV[0] == "--mute"
RubyhopGame.new(800, 600, false, false).show
else
RubyhopGame.new(800, 600, false, true).show
end
28 changes: 16 additions & 12 deletions lib/rubyhop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@ def get_my_file file

class Player
attr_accessor :x, :y, :alive
def initialize level
def initialize level, sounds
@level = level
@window = @level.window
# position
start!
@gravity = -0.25
@hop = 7.5
# sounds
@sound = Gosu::Sample.new @window, get_my_file("hop.mp3")
@gameover = Gosu::Sample.new @window, get_my_file("gameover.mp3")
if sounds
@sound = Gosu::Sample.new @window, get_my_file("hop.mp3")
@gameover = Gosu::Sample.new @window, get_my_file("gameover.mp3")
end
# images
@rise = Gosu::Image.new @window, get_my_file("rubyguy-rise.png")
@fall = Gosu::Image.new @window, get_my_file("rubyguy-fall.png")
@dead = Gosu::Image.new @window, get_my_file("rubyguy-dead.png")
end
def hop
if @alive
@sound.play
@sound.play unless @sound.nil?
@velocity += @hop
end
end
Expand All @@ -37,7 +39,7 @@ def die!
if @alive
# Set velocity to one last hop
@velocity = 5.0
@gameover.play
@gameover.play unless @sound.nil?
@alive = false
end
end
Expand Down Expand Up @@ -96,11 +98,13 @@ def draw

class HopLevel
attr_accessor :window, :movement, :score
def initialize window
def initialize window, sounds
@window = window
@music = Gosu::Song.new @window, get_my_file("music.mp3")
@music.play true
@player = Player.new self
if sounds
@music = Gosu::Song.new @window, get_my_file("music.mp3")
@music.play true
end
@player = Player.new self, sounds
@hoops = 6.times.map { Hoop.new self }
init_hoops!
@font = Gosu::Font.new @window, Gosu::default_font_name, 20
Expand Down Expand Up @@ -312,8 +316,8 @@ def draw
class RubyhopGame < Gosu::Window
VERSION = "1.3.1"
attr_reader :time, :sounds, :score, :high_score
def initialize width=800, height=600, fullscreen=false
super
def initialize width=800, height=600, fullscreen=false, sound=true
super(width, height, fullscreen)

self.caption = "Ruby Hop - #{VERSION}"
@background = Gosu::Image.new self, get_my_file("background.png")
Expand All @@ -323,7 +327,7 @@ def initialize width=800, height=600, fullscreen=false

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

@title.on_continue { play! }
Expand Down