Game Development Reference
In-Depth Information
21 music . stop
22 $window . mouse_x, $window . mouse_y = @mouse_coords
23 end
24
25 def music
26
@@music ||= Gosu :: Song . new(
$window , Utils . media_path( 'menu_music.mp3' ))
27
28 end
29
30 def draw
31 @play_state . draw
32 @message . draw(
33 $window . width / 2 - @message . width / 2 ,
34 $window . height / 4 - @message . height,
35 1000 )
36 @score_display . draw
37 end
38
39 def button_down ( id )
40 $window . close if id == Gosu :: KbQ
41 if id == Gosu :: KbC && @play_state
42 GameState . switch( @play_state )
43 end
44 if id == Gosu :: KbEscape
45 GameState . switch( @play_state )
46 end
47 end
48 end
You will notice that PauseState invokes PlayState#draw , but without
PlayState#update this will be a still image. We make sure we hide the crosshair
and restore previous mouse location when resuming play state. That way player would
not be able to cheat by pausing the game, targeting the tank while nothing moves and
then unpausing ready to deal damage. Our HUD had attr_accessor :active
exactly for this reason, but we need to switch it on and off in PlayState#enter and
PlayState#leave .
class PlayState < GameState
# ...
def button_down ( id )
# ...
if id == Gosu :: KbEscape
pause = PauseState . instance
pause . play_state = self
Search WWH ::




Custom Search