Game Development Reference
In-Depth Information
# ...
def
generate_boxes
boxes
= 0
target_boxes
=
rand
(
10.
.
30
)
while
boxes
<
target_boxes
do
x
=
rand
(
0.
.
MAP_WIDTH
*
TILE_SIZE
)
y
=
rand
(
0.
.
MAP_HEIGHT
*
TILE_SIZE
)
if
tile_at(x, y)
!=
@water
Box
.
new(
@object_pool
, x, y)
boxes
+= 1
end
end
end
# ...
end
Now give it a go. Beautiful, isn't it?
Boxes and barrels in the jungle
Implementing A Radar
With all the visual noise it is getting increasingly difficult to see enemy tanks. That's why
we will implement a
Radar
to help ourselves.
09-polishing/entities/radar.rb
1
class
Radar
2
UPDATE_FREQUENCY
= 1000
WIDTH
= 150
3
HEIGHT
= 100
4
PADDING
= 10
5
# Black with 33% transparency
6
BACKGROUND
=
Gosu
::
Color
.
new(
255 * 0.33
,
0
,
0
,
0
)
7
attr_accessor
:target
8
9