rubygoal 0.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bbc8e60812239eff9bfbf2a776ae500a85de10ee
4
- data.tar.gz: d7bc53eac176874eff82bad63e6df77aa427ce39
3
+ metadata.gz: 7a9f36e4a9184d9837b4834ab1449995676e02ca
4
+ data.tar.gz: 6c5e76bef10ba32174430b6ffd68e175eebdb463
5
5
  SHA512:
6
- metadata.gz: f837c177433fdb22d6d015eb31e8b37aa64b4ba5ee3c8ea32c95d4bb24dbb11316a56770fc3847f5ab270073f3a869e603fe43e926ca5e25b9987c4478bfabd2
7
- data.tar.gz: 60666ea38e195caee11e3a4bf97c634c8d17307342deab737da07470dfaa611624912dc4411b9098cf69fa5ec3871c5f8674a08591a82a0c4f3a66bf3a075386
6
+ metadata.gz: 256936663d874aeb3a2c9a690af37da3bc43811c98442d3f73b2321ccc9eb9ea52d3f4466b5964e6d84fa15f5c5398399fe4e8fc47053db2c58a7fd5e87538a9
7
+ data.tar.gz: 135a5704aea61868d8286e619821a56db2e7c923ead040dd1c97d2aa0d5b73b9e2f9067897df4f624e74e4e9ff19d095d71f6b06301bc7201e6fa31921bb86d4
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright 2014 Jorge Bejar
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ -----
16
+
17
+ This does not apply to files under the "media/" folder. For licensing of
18
+ those files refer to the Legal section in the README.md file.
data/README.md CHANGED
@@ -1,62 +1,85 @@
1
- #Bienvenidos a RubyGoal!
1
+ [![Build Status](https://travis-ci.org/wyeworks/rubygoal.png)](https://travis-ci.org/wyeworks/rubygoal)
2
+ [![Code Climate](https://codeclimate.com/github/wyeworks/rubygoal.png)](https://codeclimate.com/github/wyeworks/rubygoal)
3
+ [![Inline docs](http://inch-ci.org/github/wyeworks/rubygoal.png?branch=master)](http://inch-ci.org/github/wyeworks/rubygoal)
2
4
 
3
- ## ¿Qué es RubyGoal?
5
+ #Welcome to RubyGoal!
4
6
 
5
- RubyGoal es un juego en el cual tú serás el coach de un equipo de
6
- fútbol.
7
+ ## What is RubyGoal?
7
8
 
8
- La estrategia del coach la vas a tener que implementar en ruby.
9
+ RubyGoal is a game in which you will be coaching your football team.
9
10
 
10
- ## Dependencias
11
+ You will be coding your strategy in RUBY :D .
11
12
 
12
- GNU/Linux, Asegúrate tener todas las dependencias instaladas.
13
+ ## Dependencies
14
+
15
+ GNU/Linux, Make sure you have all dependencies installed.
13
16
 
14
17
  Ubuntu/Debian:
15
18
 
16
19
  ```bash
17
20
  # Gosu's dependencies for both C++ and Ruby
18
- sudo apt-get install build-essential freeglut3-dev libfreeimage-dev libgl1-mesa-dev \
19
- libopenal-dev libpango1.0-dev libsdl-ttf2.0-dev libsndfile-dev \
20
- libxinerama-dev
21
+ sudo apt-get install build-essential libsdl2-dev libsdl2-ttf-dev
22
+ libpango1.0-dev \
23
+ libgl1-mesa-dev libfreeimage-dev libopenal-dev
24
+ libsndfile-dev
21
25
  ```
22
26
 
23
- Para otras distros: https://github.com/jlnr/gosu/wiki/Getting-Started-on-Linux
27
+ For other distros: https://github.com/jlnr/gosu/wiki/Getting-Started-on-Linux
24
28
 
25
- ## ¿Cómo hago para correrlo?
29
+ ## How do i run it?
26
30
 
27
31
  ```bash
28
32
  gem install rubygoal
29
33
  ```
30
34
 
31
- Correr el juego con los `Coach` de ejemplo
35
+ Run the game with example `CoachDefinition`
32
36
  ```bash
33
37
  rubygoal
34
38
  ```
35
39
 
36
- Correr el juego con tu implementación de `Coach`
40
+ Run the game with your custom `CoachDefinition` implementation
37
41
  ```bash
38
42
  rubygoal coach_1.rb
39
43
  ```
40
44
 
41
- Correr el juego con tu implementación de ambos `Coach`
45
+ Run the game with your home and away `CoachDefinition` implementations
42
46
  ```bash
43
47
  rubygoal coach_1.rb coach_2.rb
44
48
  ```
45
49
 
46
- ## ¿Cómo hago para implementar mi Coach?
50
+ If you want to run the game from the source code, clone the project and
51
+ run the following commands:
47
52
 
48
- Mirate los `Coach` ya definidos en `lib/rubygoal/coaches`, sobre todo lee con
49
- atención y en su totalidad `lib/rubygoal/coaches/template.rb`
53
+ ```bash
54
+ BUNDLE_GEMFILE=Gemfile.dev bundle install
55
+ BUNDLE_GEMFILE=Gemfile.dev bundle exec ruby gui/bin/rubygoal [coach_file] [coach_file]
56
+ ```
50
57
 
51
- ## Legal
58
+ Also, you can simulate a game without the GUI by running
59
+
60
+ ```bash
61
+ bundle install
62
+ bundle exec ruby bin/rubygoal [coach_file] [coach_file]
63
+ ```
52
64
 
53
- Todo el código fuente, salvo los archivos bajo la carpeta `media/`, está
54
- licenciado bajo los términos de la licencia del MIT. Ver el archivo `MIT-LICENSE`
55
- bajo la ruta de la gema.
65
+ When you simuate a game, a JSON file is created in the same folder. You
66
+ could run this using our experiment webcomponent to play Rubygoal in the
67
+ web: https://github.com/jmbejar/rubygoal-webplayer
68
+
69
+ ## How do i write my own coach class?
70
+
71
+ You can find a complete guide explaining how to program a coach in
72
+ www.rubygoal.com
73
+
74
+ Aditionally, you can take a look to the already defined `CoachDefinition` at
75
+ `lib/rubygoal/coach_definition`.
76
+ Specially pay attention to the example coaches in `lib/rubygoal/coaches/`
77
+
78
+
79
+ ## Legal
80
+ All source code, except the files under the `media/` folder, is
81
+ licensed under the Apache License 2.0. Please see the `LICENSE` file under
82
+ the gem root folder.
56
83
 
57
- La imagen de Alberto Kesman utilizada en el archivo `media/goal.png` fue
58
- tomada de https://commons.wikimedia.org/wiki/File:Albertok.jpg que se
59
- encuentra licenciada bajo los términos de la licencia CC-BY-SA 3.0
60
- (https://creativecommons.org/licenses/by-sa/3.0/deed.es). Como
61
- consecuencia, el archivo `media/goal.png` queda licenciado también bajo
62
- esta licencia como trabajo derivado.
84
+ All media files under the `media/` folder are licensed under the Creative
85
+ Commons 4.0 Attribution license. Please see https://creativecommons.org/licenses/by/4.0/
data/bin/rubygoal CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- mode: ruby -*-
3
3
 
4
- require 'rubygoal'
5
- Rubygoal.start
4
+ require 'rubygoal/gui'
5
+ Rubygoal::Gui.start
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,166 @@
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
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,28 @@
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
@@ -0,0 +1,5 @@
1
+ module Rubygoal
2
+ module Gui
3
+ VERSION = Gem::Version.new '2.0.0'
4
+ end
5
+ end
@@ -0,0 +1,20 @@
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.rb CHANGED
@@ -1,7 +1,18 @@
1
- require 'rubygoal/game'
1
+ require 'rubygoal-core'
2
+ require 'rubygoal/gui/game'
2
3
 
3
4
  module Rubygoal
4
- def self.start
5
- Game.new.show
5
+ class << self
6
+ def start
7
+ game = Game.new(load_coach(:home), load_coach(:away))
8
+ gui = Gui::Game.new(game)
9
+ gui.show
10
+ end
11
+
12
+ private
13
+
14
+ def load_coach(side)
15
+ CoachLoader.new(side).coach
16
+ end
6
17
  end
7
18
  end
data/media/background.png CHANGED
Binary file
data/media/goal.png CHANGED
Binary file
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubygoal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorge Bejar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-23 00:00:00.000000000 Z
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: gosu
14
+ name: rubygoal-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.7.50
19
+ version: 1.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.7.50
26
+ version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: timecop
28
+ name: gosu
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.7'
34
- type: :development
33
+ version: '0.9'
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.7'
40
+ version: '0.9'
41
41
  description: Rubygoal
42
42
  email:
43
43
  - jorge@wyeworks.com
@@ -46,32 +46,17 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
+ - LICENSE
49
50
  - README.md
50
- - MIT-LICENSE
51
51
  - bin/rubygoal
52
- - lib/rubygoal/ball.rb
53
- - lib/rubygoal/coach.rb
54
- - lib/rubygoal/coach_loader.rb
55
- - lib/rubygoal/coaches/coach_away.rb
56
- - lib/rubygoal/coaches/coach_home.rb
57
- - lib/rubygoal/coaches/template.rb
58
- - lib/rubygoal/config.rb
59
- - lib/rubygoal/config_definitions.rb
60
- - lib/rubygoal/coordinate.rb
61
- - lib/rubygoal/field.rb
62
- - lib/rubygoal/field_metrics.rb
63
- - lib/rubygoal/formation.rb
64
- - lib/rubygoal/game.rb
65
- - lib/rubygoal/goal.rb
66
- - lib/rubygoal/match.rb
67
- - lib/rubygoal/moveable.rb
68
- - lib/rubygoal/player.rb
69
- - lib/rubygoal/players/average.rb
70
- - lib/rubygoal/players/captain.rb
71
- - lib/rubygoal/players/fast.rb
72
- - lib/rubygoal/team.rb
73
- - lib/rubygoal/version.rb
74
52
  - lib/rubygoal.rb
53
+ - lib/rubygoal/gui.rb
54
+ - lib/rubygoal/gui/ball.rb
55
+ - lib/rubygoal/gui/field.rb
56
+ - lib/rubygoal/gui/game.rb
57
+ - lib/rubygoal/gui/goal.rb
58
+ - lib/rubygoal/gui/players.rb
59
+ - lib/rubygoal/gui/version.rb
75
60
  - media/average_away.png
76
61
  - media/average_home.png
77
62
  - media/background.png
@@ -81,13 +66,9 @@ files:
81
66
  - media/fast_away.png
82
67
  - media/fast_home.png
83
68
  - media/goal.png
84
- - test/formation_test.rb
85
- - test/random.txt
86
- - test/record.txt
87
- - test/test.rb
88
69
  homepage: https://github.com/wyeworks/rubygoal
89
70
  licenses:
90
- - MIT
71
+ - Apache License 2.0
91
72
  metadata: {}
92
73
  post_install_message:
93
74
  rdoc_options: []
@@ -95,22 +76,18 @@ require_paths:
95
76
  - lib
96
77
  required_ruby_version: !ruby/object:Gem::Requirement
97
78
  requirements:
98
- - - '>='
79
+ - - ">="
99
80
  - !ruby/object:Gem::Version
100
- version: 1.9.3
81
+ version: 2.2.2
101
82
  required_rubygems_version: !ruby/object:Gem::Requirement
102
83
  requirements:
103
- - - '>='
84
+ - - ">="
104
85
  - !ruby/object:Gem::Version
105
86
  version: '0'
106
87
  requirements: []
107
88
  rubyforge_project:
108
- rubygems_version: 2.0.14
89
+ rubygems_version: 2.4.5
109
90
  signing_key:
110
91
  specification_version: 4
111
- summary: Rubygoal
112
- test_files:
113
- - test/formation_test.rb
114
- - test/random.txt
115
- - test/record.txt
116
- - test/test.rb
92
+ summary: Rubygoal Game - Soccer game for Rubysts
93
+ test_files: []
data/MIT-LICENSE DELETED
@@ -1,24 +0,0 @@
1
- Copyright (c) 2014 Jorge Bejar
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
-
22
- ---
23
-
24
- This does not apply to files under the "media/" folder.
data/lib/rubygoal/ball.rb DELETED
@@ -1,41 +0,0 @@
1
- require 'gosu'
2
-
3
- require 'rubygoal/field_metrics'
4
- require 'rubygoal/moveable'
5
-
6
- module Rubygoal
7
- class Ball
8
- include Moveable
9
-
10
- def initialize(window, position)
11
- super()
12
- @position = position
13
- @image = Gosu::Image.new(window, Config.ball.image_file, false)
14
- end
15
-
16
- def goal?
17
- FieldMetrics.goal?(position)
18
- end
19
-
20
- def draw
21
- image.draw(position.x - Config.ball.width / 2, position.y - Config.ball.height / 2, 1)
22
- end
23
-
24
- def update
25
- super
26
- if FieldMetrics.out_of_bounds_width?(position)
27
- velocity.x *= -1
28
- end
29
- if FieldMetrics.out_of_bounds_height?(position)
30
- velocity.y *= -1
31
- end
32
-
33
- velocity.x *= 0.95
34
- velocity.y *= 0.95
35
- end
36
-
37
- private
38
-
39
- attr_reader :image
40
- end
41
- end