Class: Block

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

Class Method Summary collapse

Instance Method Summary collapse

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

#colorObject

Returns the value of attribute color.



6
7
8
# File 'lib/block.rb', line 6

def color
  @color
end

#xObject

Returns the value of attribute x.



6
7
8
# File 'lib/block.rb', line 6

def x
  @x
end

#yObject

Returns the value of attribute y.



6
7
8
# File 'lib/block.rb', line 6

def y
  @y
end

Class Method Details

.heightObject



16
17
18
# File 'lib/block.rb', line 16

def self.height
  @@height
end

.widthObject



12
13
14
# File 'lib/block.rb', line 12

def self.width
  @@width
end

Instance Method Details

#collides_with_blocks?Boolean

Returns:

  • (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

#drawObject



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