Skip to content

Commit

Permalink
Add a lose condition
Browse files Browse the repository at this point in the history
  • Loading branch information
practicingruby committed Sep 25, 2011
1 parent 41110cc commit 5595b3f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions game.rb
Expand Up @@ -51,11 +51,17 @@
@goodies.reject! { |e|
[e.pos.x, e.pos.y, 10, 10].to_rect.inside?([@rect.pos.x, @rect.pos.y, 20, 20])
}

@game_over ||= @baddies.any? { |e|
[e.pos.x, e.pos.y, 15, 15].to_rect.collide?([@rect.pos.x, @rect.pos.y, 20,20])
}
end

render do |win|
if @goodies.empty?
win.draw text("YOU WIN", :at => [100,100], :size => 60)
elsif @game_over
win.draw text("YOU LOSE", :at => [100,100], :size => 60)
else
@goodies.each { |g| win.draw(g) }
@baddies.each { |g| win.draw(g) }
Expand Down

0 comments on commit 5595b3f

Please sign in to comment.