From a4909d10598c0cb622f551231999a460ea801e4d Mon Sep 17 00:00:00 2001 From: David Richards Date: Mon, 10 Feb 2014 00:42:40 -0800 Subject: [PATCH] Add an assist mode. If I'm frustrated, I can hit G and get some help playing the game. If I'm devious, I can hit S and get secret help with the game (it looks like all the skills are mine, without a changed caption). A player can still die in assisted mode, just not as easily. --- lib/rubyhop.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/rubyhop.rb b/lib/rubyhop.rb index 2cf7396..6820b92 100644 --- a/lib/rubyhop.rb +++ b/lib/rubyhop.rb @@ -9,6 +9,7 @@ class Player def initialize level @level = level @window = @level.window + @skilled = false # position start! @gravity = -0.25 @@ -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 @@ -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 @@ -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