Class: GameScene

Inherits:
Scene show all
Defined in:
lib/scene.rb

Constant Summary collapse

WIDTH =
10
HEIGHT =
20
BLOCK_SIZE =

pixels

20

Instance Attribute Summary

Attributes inherited from Scene

#window

Instance Method Summary collapse

Constructor Details

#initialize(window, difficulty) ⇒ GameScene

Returns a new instance of GameScene.



111
112
113
114
115
# File 'lib/scene.rb', line 111

def initialize(window, difficulty)
  super(window)
  @game = Game.new(window,10, 50, HEIGHT, WIDTH, BLOCK_SIZE, difficulty)
  @ticks = 0
end

Instance Method Details

#button_down(id) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/scene.rb', line 121

def button_down(id)

  case id
  when Gosu::KB_ESCAPE
    @window.menu
  when Gosu::KB_LEFT
    @game.move(-1, 0)
  when Gosu::KB_RIGHT
    @game.move(1, 0)
  when Gosu::KB_UP
    @game.rotate
  when Gosu::KB_DOWN
    @game.move(0, 1)
  when Gosu::KB_SPACE
    @game.fast_move
  end
end

#drawObject



143
144
145
146
147
# File 'lib/scene.rb', line 143

def draw
  @window.font.draw_text("Score: #{@game.score}", 10, 10, ZOrder::UI, 1.0, 1.0, Gosu::Color::YELLOW)
  @window.font.draw_text("Speed: #{@game.current_difficulty}", 250, 10, ZOrder::UI, 1.0, 1.0, Gosu::Color::YELLOW)
  @game.draw(@window)
end

#game_running?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/scene.rb', line 139

def game_running?
  !@game.game_over
end

#updateObject



117
118
119
# File 'lib/scene.rb', line 117

def update
  @game.update
end