Game Development Reference
In-Depth Information
68 self , UNIT_FILE , :precise )
69 @tank = Tank . new( self ,
70 @units . frame( 'tank1_body.png' ),
71 @units . frame( 'tank1_body_shadow.png' ),
72 @units . frame( 'tank1_dualgun.png' ))
73 @x = @y = 0
74 @first_render = true
75 @buttons_down = 0
76 end
77
78 def needs_cursor?
79 true
80 end
81
82 def button_down ( id )
83 close if id == Gosu :: KbEscape
84 @buttons_down += 1
85 end
86
87 def button_up ( id )
88 @buttons_down -= 1
89 end
90
91 def update
92
@x -= SPEED if button_down?( Gosu :: KbA )
@x += SPEED if button_down?( Gosu :: KbD )
93
@y -= SPEED if button_down?( Gosu :: KbW )
94
@y += SPEED if button_down?( Gosu :: KbS )
95
@tank . update
96
self . caption = " #{ Gosu . fps } FPS. " <<
97
'Use WASD and mouse to control tank'
98
99 end
100
101 def draw
102 @first_render = false
103 @map . draw( @x , @y )
104 @tank . draw()
105 end
106 end
107
108 GameWindow . new . show
Tank sprite is rendered in the middle of screen. It consists of three layers, body shadow,
body and gun. Body and it's shadow are always rendered in same angle, one on top of
another. The angle is determined by keys that are pressed. It supports 8 directions.
Search WWH ::




Custom Search