Game Development Reference
In-Depth Information
56 x1 = $window . width - WIDTH - PADDING
57 x2 = $window . width - PADDING
58 y1 = $window . height - HEIGHT - PADDING
59 y2 = $window . height - PADDING
60 [ x1, x2, y1, y2 ]
61 end
62 end
Radar , like Camera , also has a target. It uses ObjectPool to query nearby objects and
filters out instances of alive Tank . Then it draws a transparent black background and small
dots for each tank, green for target, red for the rest.
To avoid querying ObjectPool too often, Radar updates itself only once every second.
It is initialized, updated and drawn in PlayState , right after Camera :
class PlayState < GameState
# ...
def initialize
# ...
@camera . target = @tank
@radar = Radar . new( @object_pool , @tank )
# ...
end
# ...
def update
# ...
@camera . update
@radar . update
# ...
end
# ...
def draw
# ...
@camera . draw_crosshair
@radar . draw
end
# ...
end
Time to enjoy the results.
Search WWH ::




Custom Search