Class: Game
- Inherits:
-
Object
- Object
- Game
- Defined in:
- lib/game.rb
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #draw ⇒ Object
-
#initialize(window, opts = {}) ⇒ Game
constructor
A new instance of Game.
- #map ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(window, opts = {}) ⇒ Game
Returns a new instance of Game.
2 3 4 5 6 7 8 9 |
# File 'lib/game.rb', line 2 def initialize(window, opts={}) @window = window @players_hit = {:player_0 => [], :player_1 => []} @finish_game = false @song = Gosu::Song.new(@window, BLAST_SND_PATH + 'battle.mp3') @song.volume = 0.3 @song.play(true) end |
Instance Method Details
#button_down(id) ⇒ Object
41 42 43 44 45 |
# File 'lib/game.rb', line 41 def (id) Processor.close if id == Gosu::KbEscape @song.volume -= 0.1 if id == Gosu::KbNumpadSubtract @song.volume += 0.1 if id == Gosu::KbNumpadAdd end |
#draw ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/game.rb', line 11 def draw map.draw(0, 0) Processor.players.each do |player| player.draw player.bombs.each(&:draw) player.explosions.each(&:draw) end end |
#map ⇒ Object
37 38 39 |
# File 'lib/game.rb', line 37 def map @map ||= Map.new(BLAST_MAP_PATH + 'basic.txt') end |
#update ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/game.rb', line 20 def update Processor.players.each_with_index do |player, index| player.update player.explosions.each do |explosion| Processor.all_bombs.each do |bomb| bomb.time_counter = 1 if explosion.at?(bomb.top_x, bomb.top_y) end players_hit?(explosion, index) end end if @finish_game && Processor.players.map(&:explosions).flatten.empty? @song.stop Processor.game_over(@players_hit) end end |