Class: RubySketch::Shape

Inherits:
Object
  • Object
show all
Includes:
Xot::Inspectable
Defined in:
lib/rubysketch/shape.rb

Overview

Shape class for physics calculations.

Direct Known Subclasses

Circle

Instance Method Summary collapse

Instance Method Details

#contact(&block) ⇒ nil

Defines contact block.

Examples:

Score increases when the shape touches a coin

shape.contact do |o|
  score += 1 if o.coin?
end

Returns:

  • (nil)

    nil



61
62
63
64
65
66
# File 'lib/rubysketch/shape.rb', line 61

def contact(&block)
  @shape.contact_begin do |other|
    block.call other.instance_variable_get :@owner__ if block
  end
  nil
end

#contact_end(&block) ⇒ nil

Defines contact_end block.

Examples:

Call jumping() when the shape leaves the ground sprite

shape.contact_end do |o|
  jumping if o == groundSprite
end

Returns:

  • (nil)

    nil



77
78
79
80
81
82
# File 'lib/rubysketch/shape.rb', line 77

def contact_end(&block)
  @shape.contact_end do |other|
    block.call other.instance_variable_get :@owner__ if block
  end
  nil
end

#heightNumeric Also known as: h

Returns the height of the shape.

Returns:

  • (Numeric)

    height



28
29
30
# File 'lib/rubysketch/shape.rb', line 28

def height()
  @shape.height
end

#sensor=(state) ⇒ Boolean

Set this shape as a sensor object. Sensor object receives contact events, but no collisions.

Returns:

  • (Boolean)

    sensor or not



40
41
42
# File 'lib/rubysketch/shape.rb', line 40

def sensor=(state)
  @shape.sensor = state
end

#sensor?Boolean

Returns whether the shape is a sensor or not.

Returns:

  • (Boolean)

    sensor or not



48
49
50
# File 'lib/rubysketch/shape.rb', line 48

def sensor?()
  @shape.sensor?
end

#widthNumeric Also known as: w

Returns the width of the shape.

Returns:

  • (Numeric)

    width



20
21
22
# File 'lib/rubysketch/shape.rb', line 20

def width()
  @shape.width
end