Game Development Reference
In-Depth Information
9 name = @names . sample
10 @names . delete( name )
11 name
12 end
13 end
Then we need to place those names somewhere. We could assign them to tanks, but think
ahead - if our player and AI enemies will respawn, we should give names to inputs, because
Tank is replaceable, driver is not. Well, it is, but let's not get too deep into it.
For now we just add name parameter to PlayerInput and AiInput initializers, save
it in @name instance variable, and then add draw(viewport) method to make it render
below the tank:
# 09-polishing/entities/components/player_input.rb
class PlayerInput < Component
# Dark green
NAME_COLOR = Gosu :: Color . argb( 0xee084408 )
def initialize ( name , camera)
super ( nil )
@name = name
@camera = camera
end
# ...
def draw (viewport)
@name_image ||= Gosu :: Image . from_text(
$window , @name , Gosu . default_font_name, 20 )
@name_image . draw(
x - @name_image . width / 2 - 1 ,
y + object . graphics . height / 2 , 100 ,
1 , 1 , Gosu :: Color :: WHITE )
@name_image . draw(
x - @name_image . width / 2 ,
y + object . graphics . height / 2 , 100 ,
1 , 1 , NAME_COLOR )
end
# ...
end
# 09-polishing/entities/components/ai_input.rb
class AiInput < Component
# Dark red
NAME_COLOR = Gosu :: Color . argb( 0xeeb10000 )
Search WWH ::




Custom Search