Class: GamesAndRpgParadise::Tetris::GameWindow
Overview
#
This is the actual game-window.
#
Constant Summary
collapse
- BLOCK_WIDTH =
32
- BLOCK_HEIGHT =
32
- WIDTH =
400
- HEIGHT =
700
FILE_BLOCK, FILE_TETRIS_THEME, STATE_GAMEOVER, STATE_PLAY
Instance Attribute Summary collapse
Instance Method Summary
collapse
#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
52
53
54
55
56
57
58
59
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 52
def initialize
super(WIDTH, HEIGHT, false)
reset
spawn_next_shape
self.caption = "Tetris : #{@lines_cleared} lines"
do_initialize_the_main_tetris_theme
do_start_playing_the_main_song
end
|
Instance Attribute Details
#block_height ⇒ Object
Returns the value of attribute block_height.
27
28
29
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 27
def block_height
@block_height
end
|
#blocks ⇒ Object
Returns the value of attribute blocks.
25
26
27
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 25
def blocks
@blocks
end
|
Instance Method Details
#block_width? ⇒ Boolean
Also known as:
block_width
256
257
258
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 256
def block_width?
@block_width
end
|
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 305
def button_down(id)
case id
when Gosu::KbH
@show_the_help_menu = true
when Gosu::KbSpace
unless @falling_shape.nil?
@falling_shape.rotation += 1
if @falling_shape.collide
@falling_shape.rotation -= 1
end
end
end
end
|
#
This is the button-release action.
#
292
293
294
295
296
297
298
299
300
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 292
def button_up(id)
case id
when Gosu::KbH
@show_the_help_menu = false
end
end
|
#check_whether_the_song_should_be_paused_or_not ⇒ Object
#
check_whether_the_song_should_be_paused_or_not
The “P” button can be used to silence audio-output from this game, or re-establish it again.
#
162
163
164
165
166
167
168
169
170
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 162
def check_whether_the_song_should_be_paused_or_not
if button_down?(Gosu::KbP)
if @song.paused?
@song.play(true)
else
@song.pause
end
end
end
|
#check_whether_we_should_quit ⇒ Object
#
check_whether_we_should_quit
#
175
176
177
178
179
180
181
182
183
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 175
def check_whether_we_should_quit
if button_down?(Gosu::KbEscape)
close
elsif button_down?(Gosu::KbBackspace)
close
elsif button_down?(Gosu::KbQ)
close
end
end
|
#consider_drawing_the_help_screen(x = 25, y = 250) ⇒ Object
#
consider_drawing_the_help_screen (help tag)
This method will draw the on-game-map help screen.
#
333
334
335
336
337
338
339
340
341
342
343
344
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 333
def consider_drawing_the_help_screen(
x = 25,
y = 250
)
return unless @show_the_help_menu
@help_font.red_text('ESC: quit the application', x, y )
@help_font.red_text('P: silence the audio ', x, y + 20)
@help_font.red_text(' (or re-instate audio)', x, y + 40)
@help_font.red_text('SPACE: turns the tetris-block', x, y + 60)
@help_font.red_text('↓: accelerate this tetris-block', x, y + 80)
@help_font.red_text('Q: quits the application as well', x, y + 100)
end
|
#delete_lines_of(shape) ⇒ Object
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 229
def delete_lines_of(shape)
deleted_lines = []
shape.get_blocks.each { |block|
if line_complete(block.y)
deleted_lines.push(block.y)
@blocks = @blocks.delete_if { |item| item.y == block.y }
end
}
@lines_cleared += deleted_lines.length
@blocks.each { |block|
i = deleted_lines.count{ |y| y > block.y }
block.y += i*block_height
}
end
|
#do_initialize_the_main_tetris_theme ⇒ Object
#
do_initialize_the_main_tetris_theme
#
#do_start_playing_the_main_song ⇒ Object
#
do_start_playing_the_main_song
#
108
109
110
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 108
def do_start_playing_the_main_song
@song.play(true)
end
|
#draw ⇒ Object
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 263
def draw
consider_drawing_the_help_screen
@blocks.each { |block| block.draw }
@falling_shape.draw
case @state
when STATE_GAMEOVER
text = Gosu::Image.from_text('Game Over', 40, font: 'Arial')
text.draw(width/2 - 90, height/2 - 20, 0, 1, 1)
@song.stop end
end
|
#falling_shape? ⇒ Boolean
Also known as:
falling_shape
283
284
285
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 283
def falling_shape?
@falling_shape
end
|
#level? ⇒ Boolean
Also known as:
level
122
123
124
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 122
def level?
@level
end
|
#line_complete(y) ⇒ Object
216
217
218
219
220
221
222
223
224
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 216
def line_complete(y)
i = @blocks.count {|item| item.y == y}
if ( i == width / block_width )
return true
end
return false
end
|
#reset ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 64
def reset
@falling_shape = nil
@blocks = []
@state = STATE_PLAY
@block_width = BLOCK_WIDTH
@block_height = BLOCK_HEIGHT
@lines_cleared = 0
@help_font = return_font(:hack_18) @level = 0
@show_the_help_menu = false
end
|
#spawn_next_shape ⇒ Object
#
spawn_next_shape
This method will spawn a random shape and add the current falling shape’ blocks to the “static” blocks list.
In other words: this is the method that will generate a new shape.
#
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 193
def spawn_next_shape
unless @falling_shape.nil?
@blocks += @falling_shape.get_blocks
end
shapes = [
ShapeI.new(self),
ShapeL.new(self),
ShapeJ.new(self),
ShapeCube.new(self),
ShapeZ.new(self),
ShapeT.new(self),
ShapeS.new(self)
]
sample = shapes.sample
@falling_shape = sample
end
|
#update ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/game_window.rb', line 129
def update
case @state
when STATE_PLAY
if @falling_shape
if @falling_shape.collide
@state = STATE_GAMEOVER else
@falling_shape.update
end
end
@level = @lines_cleared / 10
self.caption = "Tetris : #{@lines_cleared} lines"
else
if button_down?(Gosu::KbSpace)
@blocks = []
@falling_shape = nil
@level = 0
@lines_cleared = 0
spawn_next_shape
@state = STATE_PLAY
end
end
check_whether_we_should_quit
check_whether_the_song_should_be_paused_or_not
end
|