Class: Physicist::SimpleBody

Inherits:
Object
  • Object
show all
Defined in:
lib/physicist/simple_body.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position:, dimensions:) ⇒ SimpleBody

Returns a new instance of SimpleBody.



5
6
7
8
# File 'lib/physicist/simple_body.rb', line 5

def initialize(position:,dimensions:)
  @position = position
  @dimensions = dimensions
end

Instance Attribute Details

#dimensionsObject (readonly)

Returns the value of attribute dimensions.



3
4
5
# File 'lib/physicist/simple_body.rb', line 3

def dimensions
  @dimensions
end

#positionObject (readonly)

Returns the value of attribute position.



3
4
5
# File 'lib/physicist/simple_body.rb', line 3

def position
  @position
end

Class Method Details

.collection_from_tiles(tile_grid) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/physicist/simple_body.rb', line 10

def self.collection_from_tiles(tile_grid)
  simple_bodies = []

  tile_grid.each_with_index do |row, y|
    row.each_with_index do |cell, x|
      if cell
        simple_bodies << new(position: [x,y], dimensions: [1,1])
      end
    end
  end

  simple_bodies
end