bricks_meet_balls 0.0.3 → 0.0.4

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: 66706a65047376f0a85a62aed149e15f17608265
4
- data.tar.gz: 76c2a71feb7c8f7259df3cbbf8157e1c3cbee0d2
3
+ metadata.gz: ee70b072f09da8e76ac9e454478f74982d793263
4
+ data.tar.gz: 566f87cfcb7bfe04cfc8af03b3d44a12bba06367
5
5
  SHA512:
6
- metadata.gz: 0691572b829556820dc0e44220ce8e5f81e2e73ad7d4446964a9f884907f4c5160b4ed5c4b7e9022594d0abdc82e3dc59f4da1ed538e17299edfcf82bab556a2
7
- data.tar.gz: 77a05581f232059bf850be09d13ef1bbbad33f3b188314221c9a1e6f091b1b1f8699dc0b002c5ff6de55b94e2ba536d9ca29801360ba4375465b58134c881dd5
6
+ metadata.gz: 9efc35b6670c0461466abe68119f1af435594851daa8bbbbc1f3d9d6d6e8aaaf3837bb99a6304cdeb1bf8255c10331c3d7a82d4c84072bd65076db75d3ddf2f7
7
+ data.tar.gz: 95186a489f53d33c0711e677606f9b62472778a6584dc4773998ba095aec6c46fef255f4641dd6558dc71498319e604e8451a017618eb6108e236a0482d2c940
data/NEWS.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.0.4: 2014-03-27
4
+
5
+ ### Changes
6
+
7
+ * Improvements
8
+ * Added accessor methods
9
+ * Support for tiling an image on bricks
10
+ * Support friction for ball with bar
11
+
3
12
  ## 0.0.3: 2014-03-27
4
13
 
5
14
  ### Changes
@@ -34,13 +34,6 @@ BALL_IMAGES = [
34
34
  "droonga-icon-full-size.png",
35
35
  ]
36
36
 
37
- width = 640
38
- height = 480
39
- num_of_rows = 10
40
- num_of_columns = 8
41
- num_of_balls = 29
42
- endless = true
43
-
44
37
  base_dir = File.expand_path(File.dirname(__FILE__))
45
38
  ball_images = BALL_IMAGES.collect do |ball_image|
46
39
  File.join(base_dir, ball_image)
@@ -49,15 +42,13 @@ brick_images = BRICK_IMAGES.collect do |brick_image|
49
42
  File.join(base_dir, brick_image)
50
43
  end
51
44
 
52
- window = BricksMeetBalls::Window.new(width,
53
- height,
54
- num_of_rows,
55
- num_of_columns,
56
- num_of_balls,
57
- ball_images,
58
- brick_images,
59
- endless)
60
-
45
+ window = BricksMeetBalls::Window.new(640, 480)
46
+ window.num_of_rows = 10
47
+ window.num_of_columns = 8
48
+ window.num_of_balls = 29
49
+ window.ball_images = ball_images
50
+ window.brick_images = brick_images
51
+ window.endless = true
61
52
  window.set_background_image(brick_images.first)
62
53
 
63
54
  window.show
@@ -12,7 +12,7 @@ module BricksMeetBalls
12
12
  @window = window
13
13
  @x = @y = 0.0
14
14
  @ball_radius = @window.height * 0.01
15
- @angle = ([*30..85, *95..150].sample) - 90
15
+ @angle = [*30..85, *95..150].sample - 90
16
16
  @speed = @window.height * 0.005
17
17
  @moving = true
18
18
  if image_path
@@ -58,28 +58,30 @@ module BricksMeetBalls
58
58
  @moving = true
59
59
  end
60
60
 
61
- def reflect(target)
61
+ def reflect(target, friction=0)
62
62
  if target.hit_on_top_or_bottom?(@x, @y)
63
- reflect_x_axis
63
+ reflect_x_axis(friction)
64
64
  elsif target.hit_on_left_or_right?(@x, @y)
65
- reflect_y_axis
65
+ reflect_y_axis(friction)
66
66
  end
67
67
  end
68
68
 
69
- def reflect_x_axis
69
+ def reflect_x_axis(friction=0)
70
70
  if @angle <= 180
71
71
  @angle = 180 - @angle
72
72
  else
73
73
  @angle = 360 - (@angle - 180)
74
74
  end
75
+ @angle += friction
75
76
  end
76
77
 
77
- def reflect_y_axis
78
+ def reflect_y_axis(friction=0)
78
79
  if @angle <= 180
79
80
  @angle = 180 + (180 - @angle)
80
81
  else
81
82
  @angle = 360 - @angle
82
83
  end
84
+ @angle += friction
83
85
  end
84
86
  end
85
87
  end
@@ -34,7 +34,7 @@ module BricksMeetBalls
34
34
  @image.draw(@x1 + @border_width,
35
35
  @y1 + @border_width,
36
36
  ZOrder::Brick,
37
- (0.95* @width / @image.width),
37
+ (0.95 * @width / @image.width),
38
38
  (0.95 * @height / @image.height))
39
39
  end
40
40
  end
@@ -52,9 +52,5 @@ module BricksMeetBalls
52
52
  def drop?(y)
53
53
  y > @y2
54
54
  end
55
-
56
- def base_dir
57
- @base_dir ||= File.expand_path(File.dirname(__FILE__))
58
- end
59
55
  end
60
56
  end
@@ -1,3 +1,3 @@
1
1
  module BricksMeetBalls
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -10,6 +10,10 @@ module BricksMeetBalls
10
10
  class Window < Gosu::Window
11
11
  include Util
12
12
 
13
+ attr_accessor :num_of_rows, :num_of_columns, :num_of_balls
14
+ attr_accessor :ball_images, :brick_images
15
+ attr_accessor :endless
16
+
13
17
  def initialize(width=240, height=480,
14
18
  num_of_rows=2, num_of_columns=3, num_of_balls=1,
15
19
  ball_images=nil, brick_images=nil, endless=false)
@@ -29,19 +33,28 @@ module BricksMeetBalls
29
33
  @num_of_rows = num_of_rows
30
34
  @num_of_balls = num_of_balls
31
35
  @endless = endless
36
+ @background_image = nil
37
+ end
38
+
39
+ def show
40
+ @brick_width = self.width / @num_of_columns
41
+ @brick_height = @brick_width / 3
32
42
  create_bricks(@num_of_columns, @num_of_rows)
33
43
  create_balls(@num_of_balls)
34
- @background_image = nil
44
+ super
35
45
  end
36
46
 
37
47
  def update
48
+ friction = 0
38
49
  if button_down?(Gosu::KbLeft) ||
39
50
  button_down?(Gosu::MsLeft)
40
51
  @bar.move_left
52
+ friction -= 15
41
53
  end
42
54
  if button_down?(Gosu::KbRight) ||
43
55
  button_down?(Gosu::MsRight)
44
56
  @bar.move_right
57
+ friction += 15
45
58
  end
46
59
 
47
60
  @balls.each do |ball|
@@ -54,7 +67,7 @@ module BricksMeetBalls
54
67
  end
55
68
  end
56
69
  if @bar.hit?(ball.x, ball.y)
57
- ball.reflect(@bar)
70
+ ball.reflect(@bar, friction)
58
71
  end
59
72
  if self.out_from_left_or_right?(ball.x)
60
73
  ball.reflect_y_axis
@@ -85,6 +98,7 @@ module BricksMeetBalls
85
98
 
86
99
  def draw
87
100
  draw_area
101
+ draw_background_image if @background_image
88
102
  @bricks.each {|brick| brick.draw }
89
103
  @balls.each {|ball| ball.draw }
90
104
  @bar.draw
@@ -112,38 +126,66 @@ module BricksMeetBalls
112
126
  @background_image = Gosu::Image.new(self, image_path, false)
113
127
  end
114
128
 
129
+ def enable_tiling_an_image_on_bricks
130
+ @tiling_an_image_on_bricks = true
131
+ end
132
+
115
133
  private
116
134
  def draw_area
117
135
  draw_square(self,
118
136
  0, 0,
119
137
  self.width, self.height,
120
138
  Gosu::Color::WHITE, ZOrder::Background)
121
- return unless @background_image
139
+ end
140
+
141
+ def draw_background_image
142
+ width = 1.0 * self.width / @background_image.width
143
+ height = 1.0 * @brick_height * @num_of_rows / @background_image.height
122
144
  @background_image.draw(0,
123
145
  0,
124
146
  ZOrder::Background,
125
- 1.0 * self.width / @background_image.width,
126
- 0.5 * self.height / @background_image.height)
147
+ width,
148
+ height)
127
149
  end
128
150
 
129
151
  def create_bricks(num_of_columns, num_of_rows)
130
- 1.upto(num_of_columns) do |column|
131
- 1.upto(num_of_rows) do |row|
152
+ if @tiling_an_image_on_bricks
153
+ if @brick_images.is_a?(Array)
154
+ brick_image = @brick_images.sample
155
+ else
156
+ brick_image = @brick_images
157
+ end
158
+ tile_images = tiling(brick_image, num_of_columns, num_of_rows)
159
+ end
160
+ 1.upto(num_of_rows) do |row|
161
+ 1.upto(num_of_columns) do |column|
132
162
  if @brick_images.is_a?(Array)
133
163
  brick_image = @brick_images.sample
134
164
  else
135
165
  brick_image = @brick_images
136
166
  end
167
+ if @tiling_an_image_on_bricks
168
+ image_index = (column - 1) + (num_of_columns * (row - 1))
169
+ brick_image = tile_images[image_index]
170
+ end
137
171
  @bricks << Brick.new(self,
138
172
  column,
139
173
  row,
140
- self.width / num_of_columns,
141
- self.width / num_of_columns / 3,
174
+ @brick_width,
175
+ @brick_height,
142
176
  brick_image)
143
177
  end
144
178
  end
145
179
  end
146
180
 
181
+ def tiling(image_path, num_of_columns, num_of_rows)
182
+ Gosu::Image.load_tiles(self,
183
+ image_path,
184
+ -1 * num_of_columns,
185
+ -1 * num_of_rows,
186
+ false)
187
+ end
188
+
147
189
  def create_balls(n)
148
190
  n.times do
149
191
  create_ball
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bricks_meet_balls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masafumi Yokoyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-26 00:00:00.000000000 Z
11
+ date: 2014-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu