class Pacman::GameWindow

game window implements game loop

Attributes

fps[R]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/pacman/GameWindow.rb, line 27
def initialize
  super(16 * 28, 16 * 36, false, 18)
  self.caption = 'Gosu Pac-man'
  init_game
end
run() click to toggle source
# File lib/pacman/GameWindow.rb, line 77
def self.run
  new.show
end

Public Instance Methods

button_down(id) click to toggle source
# File lib/pacman/GameWindow.rb, line 69
def button_down(id)
  close if id == Gosu::KbEscape

  if id == Gosu::KbReturn
    init_game unless @game.win == false && @game.lose == false
  end
end
draw() click to toggle source
# File lib/pacman/GameWindow.rb, line 65
def draw
  @screen.draw
end
init_game() click to toggle source
# File lib/pacman/GameWindow.rb, line 14
def init_game
  @game = Game.new(self)
  @screen = Screen.new(self, @game)
  @last_millis =  Gosu.milliseconds
  @fps = 0
  path = ROOT_PATH + '/media/Intro.ogg'
  @intro = Gosu::Sample.new(self, path)
  @intro.play
  @started = false
  # @started = true
  @count = 0
end
update() click to toggle source
# File lib/pacman/GameWindow.rb, line 33
def update
  if @started == true
    if @game.win == false && @game.lose == false
      if button_down?(Gosu::KbLeft) || button_down?(Gosu::GpLeft)
        @game.pressed_left
      end
      if button_down?(Gosu::KbRight) || button_down?(Gosu::GpRight)
        @game.pressed_right
      end
      if button_down?(Gosu::KbUp) || button_down?(Gosu::GpButton0)
        @game.pressed_up
      end
      if button_down?(Gosu::KbDown) || button_down?(Gosu::GpButton0)
        @game.pressed_down
      end

      @game.update

      millis = Gosu.milliseconds
      @fps = millis - @last_millis
      @fps = (1000 / @fps)
      @last_millis = millis
    end
  else
    @count += 1
    if @count == 260
      @started = true
      @count = 0
    end
  end
end