class SnakeGame::SnakeTheGame
Root class of the Snake
game
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/snake_the_game.rb, line 10 def initialize super WIDTH, HEIGHT self.caption = 'Snake Game' @snake = Snake.new @bait_manager = BaitManager.new @frame_counter = 0.0 @pause = false @font = Gosu::Font.new(20) @color = Gosu::Color.new 60, 0, 255, 255 end
Public Instance Methods
draw()
click to toggle source
# File lib/snake_the_game.rb, line 45 def draw @bait_manager.draw @snake.draw # @background_image.draw(0, 0, 0) @font.draw("Score: #{@snake.score} Speed: #{@snake.speed.round(1)}", 0, HEIGHT - 20, 0, 1.0, 1.0, @color) end
update()
click to toggle source
# File lib/snake_the_game.rb, line 22 def update @frame_counter += 1 @snake.process_input return unless @frame_counter >= (FPS / @snake.speed) update_game_objects @frame_counter -= (FPS / @snake.speed) end
update_game_objects()
click to toggle source
# File lib/snake_the_game.rb, line 32 def update_game_objects @pause = !@pause if Gosu.button_down? Gosu::KB_SPACE if @snake.gameover if Gosu.button_down? Gosu::KB_RETURN @snake = Snake.new @bait_manager = BaitManager.new end elsif !@pause @snake.update @bait_manager @bait_manager.update @snake end end