bricks_meet_balls 0.0.3 → 0.0.4
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/NEWS.md +9 -0
- data/examples/groonga/main.rb +7 -16
- data/lib/bricks_meet_balls/ball.rb +8 -6
- data/lib/bricks_meet_balls/brick.rb +1 -1
- data/lib/bricks_meet_balls/util.rb +0 -4
- data/lib/bricks_meet_balls/version.rb +1 -1
- data/lib/bricks_meet_balls/window.rb +51 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee70b072f09da8e76ac9e454478f74982d793263
|
4
|
+
data.tar.gz: 566f87cfcb7bfe04cfc8af03b3d44a12bba06367
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9efc35b6670c0461466abe68119f1af435594851daa8bbbbc1f3d9d6d6e8aaaf3837bb99a6304cdeb1bf8255c10331c3d7a82d4c84072bd65076db75d3ddf2f7
|
7
|
+
data.tar.gz: 95186a489f53d33c0711e677606f9b62472778a6584dc4773998ba095aec6c46fef255f4641dd6558dc71498319e604e8451a017618eb6108e236a0482d2c940
|
data/NEWS.md
CHANGED
data/examples/groonga/main.rb
CHANGED
@@ -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(
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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 =
|
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
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
126
|
-
|
147
|
+
width,
|
148
|
+
height)
|
127
149
|
end
|
128
150
|
|
129
151
|
def create_bricks(num_of_columns, num_of_rows)
|
130
|
-
|
131
|
-
|
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
|
-
|
141
|
-
|
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.
|
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-
|
11
|
+
date: 2014-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|