Class: GamesAndRpgParadise::Tetris::Block

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#colorObject

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

#fallingObject

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

#heightObject

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

#widthObject

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

#xObject

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

#yObject

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?

#

Returns:

  • (Boolean)


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_blocksObject

#

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

#drawObject

#

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

#resetObject

#

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