Skip to content

Commit

Permalink
Keep red square trapped in box
Browse files Browse the repository at this point in the history
  • Loading branch information
practicingruby committed Sep 25, 2011
1 parent 7da2104 commit b4a395a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions game.rb
Expand Up @@ -21,12 +21,24 @@
end

always do
@rect.pos += [-2, 0] if holding?(:left)
@rect.pos += [2, 0] if holding?(:right)
@rect.pos += [0, -2] if holding?(:up)
@rect.pos += [0, 2] if holding?(:down)
if @rect.pos.x - 2 > 0
@rect.pos += [-2, 0] if holding?(:left)
end

if @rect.pos.x + 2 < window.size.width
@rect.pos += [2, 0] if holding?(:right)
end

if @rect.pos.y - 2 > 0
@rect.pos += [0, -2] if holding?(:up)
end

if @rect.pos.y + 2 < window.size.height
@rect.pos += [0, 2] if holding?(:down)
end
end


render do |win|
@goodies.each { |g| win.draw(g) }
win.draw @rect
Expand Down

0 comments on commit b4a395a

Please sign in to comment.