Class: GamesAndRpgParadise::Tetris::Block
- Inherits:
-
Object
- Object
- GamesAndRpgParadise::Tetris::Block
- Defined in:
- lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb
Overview
GamesAndRpgParadise::Tetris::Block
Constant Summary collapse
- BLOCK_IMAGE =
#
BLOCK_IMAGE
The image is loaded only once for all blocks.
#
Gosu::Image.new( FILE_BLOCK, tileable: false )
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#falling ⇒ Object
Returns the value of attribute falling.
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
-
.image? ⇒ Boolean
# === Block.image? ========================================================================= #.
Instance Method Summary collapse
-
#collide(block) ⇒ Object
# === collide ========================================================================= #.
-
#collide_with_other_blocks ⇒ Object
# === collide_with_other_blocks ========================================================================= #.
-
#draw ⇒ Object
# === draw ========================================================================= #.
-
#initialize(game) ⇒ Block
constructor
# === initialize ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#set_game(i) ⇒ Object
# === set_game ========================================================================= #.
Constructor Details
#initialize(game) ⇒ Block
#
initialize
#
43 44 45 46 47 48 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 43 def initialize(game) @width = BLOCK_IMAGE.width @height = BLOCK_IMAGE.height set_game(game) reset end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
22 23 24 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 22 def color @color end |
#falling ⇒ Object
Returns the value of attribute falling.
17 18 19 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 17 def falling @falling end |
#height ⇒ Object
Returns the value of attribute height.
21 22 23 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 21 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
20 21 22 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 20 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
18 19 20 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 18 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
19 20 21 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 19 def y @y end |
Class Method Details
.image? ⇒ Boolean
#
Block.image?
#
36 37 38 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 36 def self.image? BLOCK_IMAGE end |
Instance Method Details
#collide(block) ⇒ Object
#
collide
#
76 77 78 79 80 81 82 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 76 def collide(block) # ======================================================================= # # Two blocks collide only when they are at the same # position, since the game-map is an exclusive grid. # ======================================================================= # return (block.x == @x && block.y == @y) end |
#collide_with_other_blocks ⇒ Object
#
collide_with_other_blocks
#
87 88 89 90 91 92 93 94 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 87 def collide_with_other_blocks @game.blocks.each { |block| if collide(block) return block end } nil end |
#draw ⇒ Object
#
draw
#
69 70 71 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 69 def draw BLOCK_IMAGE.draw(@x, @y, 0, 1, 1, @color) end |
#reset ⇒ Object
#
reset (reset tag)
#
53 54 55 56 57 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 53 def reset @x = 0 @y = 0 @color = 0xffffffff end |
#set_game(i) ⇒ Object
#
set_game
#
62 63 64 |
# File 'lib/games_and_rpg_paradise/gui/gosu/tetris/block.rb', line 62 def set_game(i) @game = i end |