Class: GamesAndRpgParadise::GameWindow

Inherits:
Gosu::Window show all
Defined in:
lib/games_and_rpg_paradise/gui/gosu/battle_city/window.rb,
lib/games_and_rpg_paradise/games/flappy_bird/gosu/flappy.rb

Constant Summary collapse

TITLE =
#

TITLE

#
'Battle City'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Gosu::Window

#gosu_button_down?, #image, #image10?, #image1?, #image2?, #image3?, #image4?, #image5?, #image6?, #image7?, #image8?, #image9?, #on_left_arrow_pressed?, #on_right_arrow_pressed?, #q_means_quit, #set_font, #set_title, #sqrt, #tab_key?, #write_this_text

Constructor Details

#initializeGameWindow

#

initialize

Initialize the game

#


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/window.rb', line 19

def initialize
  super(800, 710, false)
  self.caption  = TITLE
  @text_display = Gosu::Font.new(self, 'FUTURA', 50)
  @theme_music  = Gosu::Song.new("media/magic_space.mp3")
  @theme_music.play(true)
  @theme_music.volume = 0.2
  @game_over_music = Gosu::Song.new("media/game_over.wav")
  @game_over_music.volume = 0.2
  @player = Player.new(self)
  @game_running = true
  @game_win_music = Gosu::Song.new("media/game_win.mp3")
  @game_win_music.volume = 0.2
end

Instance Attribute Details

#deltaObject

Returns the value of attribute delta.



19
20
21
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/flappy.rb', line 19

def delta
  @delta
end

#entitiesObject

Returns the value of attribute entities.



17
18
19
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/flappy.rb', line 17

def entities
  @entities
end

#game_runningObject

Returns the value of attribute game_running.



9
10
11
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/window.rb', line 9

def game_running
  @game_running
end

#wallsObject

Returns the value of attribute walls.



18
19
20
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/flappy.rb', line 18

def walls
  @walls
end

Instance Method Details

#button_down(id) ⇒ Object

#

button_down

#


44
45
46
47
48
49
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/window.rb', line 44

def button_down(id)
  case id
  when Gosu::KB_ESCAPE
    close
  end
end

#drawObject

#

draw

Draw entities of games - this is a standard gosu method.

#


73
74
75
76
77
78
79
80
81
82
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/window.rb', line 73

def draw
  @player.draw     
  unless @game_running
    if @player.win
      @text_display.draw_text("YOU WON!", 300, 305, 3, 1, 1, Gosu::Color::CYAN)
    else
      @text_display.draw_text("GAME OVER", 296, 305, 3, 1, 1, Gosu::Color::CYAN)
    end
  end 
end

#ground_heightinteger

#

ground_height

Return the height of ground

#

Returns:

  • (integer)


131
132
133
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/flappy.rb', line 131

def ground_height
  @ground.height
end

#ground_yObject

#

ground_y

Return ground y position

#


142
143
144
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/flappy.rb', line 142

def ground_y
  @ground.y
end

#resetObject

#

reset

Reset all elements

#


37
38
39
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/window.rb', line 37

def reset
  @game_over_music_played = false
end

#sky_heightinteger

#

sky_height

Compute height of sky

#

Returns:

  • (integer)

    the height of sky



121
122
123
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/flappy.rb', line 121

def sky_height
  @background_image.height - self.ground_height
end

#updateObject

Update game for each loop occurence - standard gosu method



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/window.rb', line 54

def update
  if @game_running
    @player.update
  else
    @theme_music.pause
    if @player.win
      @game_win_music.play
    else      
      unless @game_over_music_played 
        @game_over_music.play 
        @game_over_music_played = true
      end
    end     
  end
end

#update_deltaObject

update_delta

Update delta param



68
69
70
71
72
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/flappy.rb', line 68

def update_delta
  current_time = ::Gosu.milliseconds / 1000.0
  @delta = [current_time - @last_time, 0.25].min
  @last_time = current_time
end