Class: Block
- Inherits:
-
Object
- Object
- Block
- Defined in:
- lib/block.rb
Overview
One block - each shape is formed by multiple blocks
Constant Summary collapse
- @@image =
nil
- @@width =
32
- @@height =
32
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #collides_with_blocks? ⇒ Boolean
- #draw ⇒ Object
-
#initialize(game, x = 0, y = 0) ⇒ Block
constructor
A new instance of Block.
Constructor Details
#initialize(game, x = 0, y = 0) ⇒ Block
Returns a new instance of Block.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/block.rb', line 20 def initialize(game, x = 0, y = 0) @@image = Gosu::Image.new(game, '../media/block.png', false) if @@image.nil? @@width = @@image.width unless @@image.nil? @@height = @@image.height unless @@image.nil? @x = x @y = y @game = game # AA RR GG BB @color = 0xFFFF0000 end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
6 7 8 |
# File 'lib/block.rb', line 6 def color @color end |
#x ⇒ Object
Returns the value of attribute x.
6 7 8 |
# File 'lib/block.rb', line 6 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
6 7 8 |
# File 'lib/block.rb', line 6 def y @y end |
Class Method Details
.height ⇒ Object
16 17 18 |
# File 'lib/block.rb', line 16 def self.height @@height end |
.width ⇒ Object
12 13 14 |
# File 'lib/block.rb', line 12 def self.width @@width end |
Instance Method Details
#collides_with_blocks? ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'lib/block.rb', line 38 def collides_with_blocks? @game.blocks.each do |block| return true if block.x == @x && block.y == @y end false end |
#draw ⇒ Object
33 34 35 36 |
# File 'lib/block.rb', line 33 def draw # x, y, z, factor_z, factor_y, color, mode (= :default) @@image.draw(@x, @y, 0, 1, 1, @color) end |