Class: Rubygoal::Field

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game_window) ⇒ Field

Returns a new instance of Field.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rubygoal/field.rb', line 19

def initialize(game_window)
  @game_window = game_window
  @background_image = Gosu::Image.new(game_window, Config.field.background_image_file, true)

  @ball = Ball.new(game_window, FieldMetrics.center_position)

  coach_home = CoachLoader.get(CoachHome)
  coach_away = CoachLoader.get(CoachAway)

  puts "Home coach: #{coach_home.class.name}"
  puts "Away coach: #{coach_away.class.name}"

  @team_home = Team.new(game_window, :home, coach_home)
  @team_away = Team.new(game_window, :away, coach_away)
end

Instance Attribute Details

#ballObject (readonly)

Returns the value of attribute ball.



14
15
16
# File 'lib/rubygoal/field.rb', line 14

def ball
  @ball
end

#team_awayObject (readonly)

Returns the value of attribute team_away.



14
15
16
# File 'lib/rubygoal/field.rb', line 14

def team_away
  @team_away
end

#team_homeObject (readonly)

Returns the value of attribute team_home.



14
15
16
# File 'lib/rubygoal/field.rb', line 14

def team_home
  @team_home
end

Instance Method Details

#drawObject



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

def draw
  background_image.draw(0, 0, 0);
  ball.draw
  team_home.draw
  team_away.draw
end

#reinitializeObject



35
36
37
38
39
# File 'lib/rubygoal/field.rb', line 35

def reinitialize
  team_home.players_to_initial_position
  team_away.players_to_initial_position
  ball.position = FieldMetrics.center_position
end

#team_namesObject



41
42
43
44
45
46
# File 'lib/rubygoal/field.rb', line 41

def team_names
  {
    home: team_home.name,
    away: team_away.name
  }
end

#updateObject



48
49
50
51
52
# File 'lib/rubygoal/field.rb', line 48

def update
  team_home.update(game_data(:home))
  team_away.update(game_data(:away))
  ball.update
end