rubygoal 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/rubygoal +12 -2
- data/lib/rubygoal.rb +1 -18
- data/lib/rubygoal/ball.rb +60 -0
- data/lib/rubygoal/coach.rb +81 -0
- data/lib/rubygoal/coach_definition.rb +54 -0
- data/lib/rubygoal/coach_loader.rb +55 -0
- data/lib/rubygoal/coaches/coach_definition_away.rb +72 -0
- data/lib/rubygoal/coaches/coach_definition_home.rb +76 -0
- data/lib/rubygoal/configuration.rb +49 -0
- data/lib/rubygoal/coordinate.rb +33 -0
- data/lib/rubygoal/field.rb +134 -0
- data/lib/rubygoal/formation.rb +73 -0
- data/lib/rubygoal/formation/formation_dsl.rb +67 -0
- data/lib/rubygoal/game.rb +162 -0
- data/lib/rubygoal/goal.rb +26 -0
- data/lib/rubygoal/match_data.rb +130 -0
- data/lib/rubygoal/moveable.rb +68 -0
- data/lib/rubygoal/player.rb +87 -0
- data/lib/rubygoal/players/average.rb +16 -0
- data/lib/rubygoal/players/captain.rb +15 -0
- data/lib/rubygoal/players/fast.rb +16 -0
- data/lib/rubygoal/players/goalkeeper.rb +26 -0
- data/lib/rubygoal/players/player_movement.rb +98 -0
- data/lib/rubygoal/recorder.rb +53 -0
- data/lib/rubygoal/simulator.rb +33 -0
- data/lib/rubygoal/team.rb +198 -0
- data/lib/rubygoal/teams/away.rb +15 -0
- data/lib/rubygoal/teams/home.rb +15 -0
- data/lib/rubygoal/util.rb +36 -0
- data/lib/rubygoal/version.rb +3 -0
- metadata +35 -23
- data/lib/rubygoal/gui.rb +0 -20
- data/lib/rubygoal/gui/ball.rb +0 -26
- data/lib/rubygoal/gui/field.rb +0 -21
- data/lib/rubygoal/gui/game.rb +0 -166
- data/lib/rubygoal/gui/goal.rb +0 -23
- data/lib/rubygoal/gui/players.rb +0 -28
- data/lib/rubygoal/gui/version.rb +0 -5
- data/media/average_away.png +0 -0
- data/media/average_home.png +0 -0
- data/media/background.png +0 -0
- data/media/ball.png +0 -0
- data/media/captain_away.png +0 -0
- data/media/captain_home.png +0 -0
- data/media/fast_away.png +0 -0
- data/media/fast_home.png +0 -0
- data/media/goal.png +0 -0
data/lib/rubygoal/gui.rb
DELETED
@@ -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
|
data/lib/rubygoal/gui/ball.rb
DELETED
@@ -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
|
data/lib/rubygoal/gui/field.rb
DELETED
@@ -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
|
data/lib/rubygoal/gui/game.rb
DELETED
@@ -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
|
data/lib/rubygoal/gui/goal.rb
DELETED
@@ -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
|
data/lib/rubygoal/gui/players.rb
DELETED
@@ -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
|
data/lib/rubygoal/gui/version.rb
DELETED
data/media/average_away.png
DELETED
Binary file
|
data/media/average_home.png
DELETED
Binary file
|
data/media/background.png
DELETED
Binary file
|
data/media/ball.png
DELETED
Binary file
|
data/media/captain_away.png
DELETED
Binary file
|
data/media/captain_home.png
DELETED
Binary file
|
data/media/fast_away.png
DELETED
Binary file
|
data/media/fast_home.png
DELETED
Binary file
|
data/media/goal.png
DELETED
Binary file
|