Skip to content
Open
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
36 changes: 36 additions & 0 deletions lib/rubyhop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Player
def initialize level
@level = level
@window = @level.window
@skilled = false
# position
start!
@gravity = -0.25
Expand All @@ -21,6 +22,12 @@ def initialize level
@fall = Gosu::Image.new @window, get_my_file("rubyguy-fall.png")
@dead = Gosu::Image.new @window, get_my_file("rubyguy-dead.png")
end
def skilled?
@skilled
end
def toggle_skilled!
@skilled = !@skilled
end
def hop
if @alive
@sound.play
Expand Down Expand Up @@ -78,7 +85,24 @@ def initialize level
@x = @y = 0
@active = true
end
def support_factor
@support_factor ||= 250
end
def miss player
if player.alive &&
player.skilled? &&
(@x - player.x) <= 100 &&
(@x - player.x) >= 12 &&

# split the difference
difference = @y - player.y
adjustment = difference / 20
adjustment = -support_factor if adjustment < -support_factor
adjustment = support_factor if adjustment > support_factor

player.y += adjustment
# player.y = @y
end
if (@x - player.x).abs < 12 &&
(@y - player.y).abs > 72
# the player missed the hoop
Expand Down Expand Up @@ -159,6 +183,18 @@ def reset_hoop! hoop
def button_down id
quit! if id == Gosu::KbEscape
@player.hop if id == Gosu::KbSpace
if id == Gosu::KbG
@player.toggle_skilled!
if @player.skilled?
@window.caption = "Ruby Hop (assisted mode)"
else
@window.caption = "Ruby Hop"
end
end
if id == Gosu::KbS
@player.toggle_skilled!
@window.caption = "Ruby Hop"
end
end

def update
Expand Down