rubygoal 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rubygoal +12 -2
  3. data/lib/rubygoal.rb +1 -18
  4. data/lib/rubygoal/ball.rb +60 -0
  5. data/lib/rubygoal/coach.rb +81 -0
  6. data/lib/rubygoal/coach_definition.rb +54 -0
  7. data/lib/rubygoal/coach_loader.rb +55 -0
  8. data/lib/rubygoal/coaches/coach_definition_away.rb +72 -0
  9. data/lib/rubygoal/coaches/coach_definition_home.rb +76 -0
  10. data/lib/rubygoal/configuration.rb +49 -0
  11. data/lib/rubygoal/coordinate.rb +33 -0
  12. data/lib/rubygoal/field.rb +134 -0
  13. data/lib/rubygoal/formation.rb +73 -0
  14. data/lib/rubygoal/formation/formation_dsl.rb +67 -0
  15. data/lib/rubygoal/game.rb +162 -0
  16. data/lib/rubygoal/goal.rb +26 -0
  17. data/lib/rubygoal/match_data.rb +130 -0
  18. data/lib/rubygoal/moveable.rb +68 -0
  19. data/lib/rubygoal/player.rb +87 -0
  20. data/lib/rubygoal/players/average.rb +16 -0
  21. data/lib/rubygoal/players/captain.rb +15 -0
  22. data/lib/rubygoal/players/fast.rb +16 -0
  23. data/lib/rubygoal/players/goalkeeper.rb +26 -0
  24. data/lib/rubygoal/players/player_movement.rb +98 -0
  25. data/lib/rubygoal/recorder.rb +53 -0
  26. data/lib/rubygoal/simulator.rb +33 -0
  27. data/lib/rubygoal/team.rb +198 -0
  28. data/lib/rubygoal/teams/away.rb +15 -0
  29. data/lib/rubygoal/teams/home.rb +15 -0
  30. data/lib/rubygoal/util.rb +36 -0
  31. data/lib/rubygoal/version.rb +3 -0
  32. metadata +35 -23
  33. data/lib/rubygoal/gui.rb +0 -20
  34. data/lib/rubygoal/gui/ball.rb +0 -26
  35. data/lib/rubygoal/gui/field.rb +0 -21
  36. data/lib/rubygoal/gui/game.rb +0 -166
  37. data/lib/rubygoal/gui/goal.rb +0 -23
  38. data/lib/rubygoal/gui/players.rb +0 -28
  39. data/lib/rubygoal/gui/version.rb +0 -5
  40. data/media/average_away.png +0 -0
  41. data/media/average_home.png +0 -0
  42. data/media/background.png +0 -0
  43. data/media/ball.png +0 -0
  44. data/media/captain_away.png +0 -0
  45. data/media/captain_home.png +0 -0
  46. data/media/fast_away.png +0 -0
  47. data/media/fast_home.png +0 -0
  48. data/media/goal.png +0 -0
@@ -1,20 +0,0 @@
1
- require 'rubygoal'
2
- require 'rubygoal/gui/game'
3
-
4
- module Rubygoal
5
- module Gui
6
- class << self
7
- def start
8
- game = Rubygoal::Game.new(load_coach(:home), load_coach(:away))
9
- gui = Game.new(game)
10
- gui.show
11
- end
12
-
13
- private
14
-
15
- def load_coach(side)
16
- CoachLoader.new(side).coach
17
- end
18
- end
19
- end
20
- end
@@ -1,26 +0,0 @@
1
- require 'gosu'
2
-
3
- module Rubygoal::Gui
4
- class Ball
5
- IMAGE_SIZE = 20
6
-
7
- def initialize(window, ball)
8
- @ball = ball
9
-
10
- image_path = File.dirname(__FILE__) + '/../../../media/ball.png'
11
- @image = Gosu::Image.new(window, image_path, false)
12
- end
13
-
14
- def draw
15
- half_side_lenght = IMAGE_SIZE / 2
16
- image_center_x = ball.position.x - half_side_lenght
17
- image_center_y = ball.position.y - half_side_lenght
18
-
19
- image.draw(image_center_x, image_center_y, 1)
20
- end
21
-
22
- private
23
-
24
- attr_reader :ball, :image
25
- end
26
- end
@@ -1,21 +0,0 @@
1
- require 'gosu'
2
-
3
- require 'rubygoal/gui/ball'
4
- require 'rubygoal/gui/players'
5
-
6
- module Rubygoal::Gui
7
- class Field
8
- def initialize(window)
9
- image_path = File.dirname(__FILE__) + '/../../../media/background.png'
10
- @background_image = Gosu::Image.new(window, image_path, true)
11
- end
12
-
13
- def draw
14
- background_image.draw(0, 0, 0);
15
- end
16
-
17
- private
18
-
19
- attr_reader :background_image
20
- end
21
- end
@@ -1,166 +0,0 @@
1
- require 'gosu'
2
-
3
- require 'rubygoal/gui/goal'
4
- require 'rubygoal/gui/field'
5
- require 'rubygoal/gui/ball'
6
- require 'rubygoal/gui/players'
7
-
8
- require 'rubygoal/coordinate'
9
- require 'rubygoal/game'
10
-
11
- module Rubygoal::Gui
12
- class Game < Gosu::Window
13
- WINDOW_WIDTH = 1920
14
- WINDOW_HEIGHT = 1080
15
-
16
- TIME_LABEL_POSITION = Rubygoal::Position.new(870, 68)
17
- SCORE_HOME_LABEL_POSITION = Rubygoal::Position.new(1150, 68)
18
- SCORE_AWAY_LABEL_POSITION = Rubygoal::Position.new(1220, 68)
19
-
20
- TEAM_NAME_HOME_LABEL_POSITION = Rubygoal::Position.new(105, 580)
21
- TEAM_NAME_AWAY_LABEL_POSITION = Rubygoal::Position.new(1815, 580)
22
-
23
- DEFAULT_FONT_SIZE = 48
24
-
25
- LABEL_IMAGE_FONT_SIZE = 64
26
- LABEL_IMAGE_WIDTH = 669
27
-
28
- def initialize(game)
29
- super(WINDOW_WIDTH, WINDOW_HEIGHT, false)
30
- self.caption = "Ruby Goal"
31
-
32
- @game = game
33
-
34
- @gui_field = Field.new(self)
35
- @gui_goal = Goal.new(self)
36
- @gui_ball = Ball.new(self, game.ball)
37
- @gui_players = players.map { |p| Players.new(self, p) }
38
-
39
- @font = Gosu::Font.new(
40
- self,
41
- Gosu.default_font_name,
42
- DEFAULT_FONT_SIZE
43
- )
44
-
45
- @home_team_label = create_label_image(game.coach_home.name)
46
- @away_team_label = create_label_image(game.coach_away.name)
47
- end
48
-
49
- def update
50
- game.update
51
- end
52
-
53
- def draw
54
- gui_field.draw
55
- gui_ball.draw
56
- gui_players.each(&:draw)
57
-
58
- draw_scoreboard
59
- draw_team_labels
60
- gui_goal.draw if game.celebrating_goal?
61
- end
62
-
63
- def button_down(id)
64
- if id == Gosu::KbEscape
65
- close
66
- end
67
- end
68
-
69
- private
70
-
71
- def players
72
- game.players
73
- end
74
-
75
- def create_label_image(name)
76
- name_characters_limit = 20
77
- name = truncate_label(name, name_characters_limit)
78
-
79
- font_name = Gosu.default_font_name
80
- font_size = LABEL_IMAGE_FONT_SIZE
81
- line_spacing = 1
82
- label_width = LABEL_IMAGE_WIDTH
83
- alignment = :center
84
-
85
- Gosu::Image.from_text(
86
- self,
87
- name,
88
- font_name,
89
- font_size,
90
- line_spacing,
91
- label_width,
92
- alignment
93
- )
94
- end
95
-
96
- def truncate_label(name, limit)
97
- words = name.split
98
-
99
- left = limit
100
- truncated = []
101
- words.each do |word|
102
- break unless left > 0
103
-
104
- truncated << word
105
- left -= word.length + 1
106
- end
107
-
108
- truncated.join(' ')
109
- end
110
-
111
- def draw_scoreboard
112
- draw_text(time_text, TIME_LABEL_POSITION, :gray)
113
- draw_text(game.score_home.to_s, SCORE_HOME_LABEL_POSITION, :white)
114
- draw_text(game.score_away.to_s, SCORE_AWAY_LABEL_POSITION, :white)
115
- end
116
-
117
- def draw_team_labels
118
- draw_vertical_text(home_team_label, TEAM_NAME_HOME_LABEL_POSITION, :down)
119
- draw_vertical_text(away_team_label, TEAM_NAME_AWAY_LABEL_POSITION, :up)
120
- end
121
-
122
- def draw_text(text, position, color, scale = 1)
123
- horizontal_alignment = 0.5
124
- vertical_alignment = 0.5
125
- z_order = 1
126
- horizontal_scale = scale
127
- vertical_scale = scale
128
-
129
- font.draw_rel(
130
- text,
131
- position.x,
132
- position.y,
133
- horizontal_alignment,
134
- vertical_alignment,
135
- z_order,
136
- horizontal_scale,
137
- vertical_scale,
138
- color_to_hex(color)
139
- )
140
- end
141
-
142
- def draw_vertical_text(label, position, direction = :down)
143
- angle = direction == :down ? -90 : 90
144
- label.draw_rot(position.x, position.y, 1, angle)
145
- end
146
-
147
- def time_text
148
- minutes = Integer(game.time) / 60
149
- seconds = Integer(game.time) % 60
150
- "%d:%02d" % [minutes, seconds]
151
- end
152
-
153
- def color_to_hex(color)
154
- case color
155
- when :white
156
- 0xffffffff
157
- when :gray
158
- 0xff6d6e70
159
- end
160
- end
161
-
162
- attr_reader :game, :gui_field, :gui_goal,
163
- :gui_ball, :gui_players,
164
- :font, :home_team_label, :away_team_label
165
- end
166
- end
@@ -1,23 +0,0 @@
1
- require 'gosu'
2
-
3
- require 'rubygoal/coordinate'
4
-
5
- module Rubygoal::Gui
6
- class Goal
7
- CELEBRATION_IMAGE_POSITION = Rubygoal::Position.new(680, 466)
8
-
9
- def initialize(window)
10
- image_path = File.dirname(__FILE__) + '/../../../media/goal.png'
11
- @image = Gosu::Image.new(window, image_path, true)
12
- end
13
-
14
- def draw
15
- position = CELEBRATION_IMAGE_POSITION
16
- image.draw(position.x, position.y, 1)
17
- end
18
-
19
- private
20
-
21
- attr_reader :image
22
- end
23
- end
@@ -1,28 +0,0 @@
1
- require 'gosu'
2
- require 'forwardable'
3
-
4
- require 'rubygoal/util'
5
-
6
- module Rubygoal::Gui
7
- class Players
8
- extend Forwardable
9
- def_delegators :player, :type, :side, :position, :destination, :rotation, :moving?
10
-
11
- def initialize(window, player)
12
- @player = player
13
- @image = Gosu::Image.new(window, image_filename, false)
14
- end
15
-
16
- def draw
17
- image.draw_rot(position.x, position.y, 1, rotation - 180)
18
- end
19
-
20
- private
21
-
22
- def image_filename
23
- File.dirname(__FILE__) + "/../../../media/#{type}_#{side}.png"
24
- end
25
-
26
- attr_reader :player, :image
27
- end
28
- end
@@ -1,5 +0,0 @@
1
- module Rubygoal
2
- module Gui
3
- VERSION = Gem::Version.new '2.0.0'
4
- end
5
- end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file