Class: Rubygoal::Game

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGame

Returns a new instance of Game.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubygoal/game.rb', line 16

def initialize
  super(1920, 1080, true)
  self.caption = "Ruby Goal"

  @field = Field.new(self)
  @goal = Goal.new(self)

  @state = :playing

  @time = Config.game.time
  @score_home = 0
  @score_away = 0

  @font = Gosu::Font.new(
    self,
    Gosu.default_font_name,
    Config.game.default_font_size
  )

  @home_team_label = create_label_image(name_home)
  @away_team_label = create_label_image(name_away)
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



11
12
13
# File 'lib/rubygoal/game.rb', line 11

def field
  @field
end

#score_awayObject

Returns the value of attribute score_away.



11
12
13
# File 'lib/rubygoal/game.rb', line 11

def score_away
  @score_away
end

#score_homeObject

Returns the value of attribute score_home.



11
12
13
# File 'lib/rubygoal/game.rb', line 11

def score_home
  @score_home
end

#timeObject

Returns the value of attribute time.



11
12
13
# File 'lib/rubygoal/game.rb', line 11

def time
  @time
end

Instance Method Details

#button_down(id) ⇒ Object



61
62
63
64
65
# File 'lib/rubygoal/game.rb', line 61

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

#drawObject



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

def draw
  field.draw
  draw_scoreboard
  draw_team_labels
  goal.draw if field.goal?
end

#updateObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubygoal/game.rb', line 39

def update
  return if state == :ended

  update_elapsed_time

  if field.goal?
    update_goal
  else
    update_remaining_time
    field.update
  end

  end_match! if time <= 0
end