Class: PlayState

Inherits:
GameState show all
Defined in:
lib/gamestates/play_state.rb

Overview

class PlayState

Instance Method Summary collapse

Methods inherited from GameState

#enter, #leave, #needs_redraw?, switch

Constructor Details

#initialize(two_players = false) ⇒ PlayState

Returns a new instance of PlayState.



5
6
7
8
9
# File 'lib/gamestates/play_state.rb', line 5

def initialize(two_players = false)
  @game_over = Gosu::Image.from_text($window, "Game\nover", $window.mediamanager.font, 40)
  @map = Map.new(two_players, 1)
  @upgrade_prob = 0.0001
end

Instance Method Details

#button_down(id) ⇒ Object



11
12
13
# File 'lib/gamestates/play_state.rb', line 11

def button_down(id)
  GameState.switch(MenuState.instance) if id == Gosu::KbEscape
end

#drawObject



26
27
28
29
30
# File 'lib/gamestates/play_state.rb', line 26

def draw
  @game_over.draw($window.width / 2 - @game_over.width / 2, $window.height / 2 - @game_over.height / 2 - 10,
                  11, 1, 1, 0xffff0000) if @map.game_over?
  @map.draw
end

#update(keymap) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/gamestates/play_state.rb', line 15

def update(keymap)
  return if @map.game_over?
  if rand < @upgrade_prob
    @map.upgrade_create
    @upgrade_prob = 0.0001
  else
    @upgrade_prob += 0.00001 if @map.upgrades_size == 0
  end
  @map.update(keymap)
end