Class: Rubygoal::Gui::Game

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/rubygoal/gui/game.rb

Constant Summary collapse

WINDOW_WIDTH =
1920
WINDOW_HEIGHT =
1080
TIME_LABEL_POSITION =
Rubygoal::Position.new(870, 68)
SCORE_HOME_LABEL_POSITION =
Rubygoal::Position.new(1150, 68)
SCORE_AWAY_LABEL_POSITION =
Rubygoal::Position.new(1220, 68)
TEAM_NAME_HOME_LABEL_POSITION =
Rubygoal::Position.new(105, 580)
TEAM_NAME_AWAY_LABEL_POSITION =
Rubygoal::Position.new(1815, 580)
DEFAULT_FONT_SIZE =
48
LABEL_IMAGE_FONT_SIZE =
64
LABEL_IMAGE_WIDTH =
669

Instance Method Summary collapse

Constructor Details

#initialize(game) ⇒ Game

Returns a new instance of Game.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rubygoal/gui/game.rb', line 28

def initialize(game)
  super(WINDOW_WIDTH, WINDOW_HEIGHT, false)
  self.caption = "Ruby Goal"

  @game = game

  @gui_field = Field.new(self)
  @gui_goal = Goal.new(self)
  @gui_ball = Ball.new(self, game.ball)
  @gui_players = players.map { |p| Players.new(self, p) }

  @font = Gosu::Font.new(
    self,
    Gosu.default_font_name,
    DEFAULT_FONT_SIZE
  )

  @home_team_label = create_label_image(game.coach_home.name)
  @away_team_label = create_label_image(game.coach_away.name)
end

Instance Method Details

#button_down(id) ⇒ Object



63
64
65
66
67
# File 'lib/rubygoal/gui/game.rb', line 63

def button_down(id)
  if id == Gosu::KbEscape
    close
  end
end

#drawObject



53
54
55
56
57
58
59
60
61
# File 'lib/rubygoal/gui/game.rb', line 53

def draw
  gui_field.draw
  gui_ball.draw
  gui_players.each(&:draw)

  draw_scoreboard
  draw_team_labels
  gui_goal.draw if game.celebrating_goal?
end

#updateObject



49
50
51
# File 'lib/rubygoal/gui/game.rb', line 49

def update
  game.update
end