Class: Pongo::Composite
- Inherits:
-
AbstractCollection
- Object
- AbstractItem
- AbstractCollection
- Pongo::Composite
- Defined in:
- lib/pongo/composite.rb
Overview
The Composite class can contain Particles, and Constraints. Composites can be added to a parent Group, along with Particles and Constraints. Members of a Composite are not checked for collision with one another, internally.
Instance Attribute Summary collapse
-
#delta ⇒ Object
Returns the value of attribute delta.
Attributes inherited from AbstractCollection
#constraints, #is_parented, #particles, #sprite
Attributes inherited from AbstractItem
#always_repaint, #display_object, #display_object_offset, #display_object_rotation, #fill_alpha, #fill_color, #line_alpha, #line_color, #line_thickness, #renderer, #solid, #user_data, #visible
Instance Method Summary collapse
- #fixed=(b) ⇒ Object
-
#fixed? ⇒ Boolean
(also: #fixed)
The fixed state of the Composite.
-
#initialize ⇒ Composite
constructor
A new instance of Composite.
- #relative_angle(center, p) ⇒ Object (also: #get_relative_angle)
-
#rotate_by_angle(angle_degrees, center) ⇒ Object
Rotates the Composite to an angle specified in degrees, around a given center.
-
#rotate_by_radian(angle_radians, center) ⇒ Object
Rotates the Composite to an angle specified in radians, around a given center.
Methods inherited from AbstractCollection
#<<, #add_constraint, #add_particle, #all, #check_collisions_vs_collection, #check_internal_collisions, #cleanup, #collidable_constraints, #collidable_particles, #draw, #init, #integrate, #parented?, #remove_constraint, #remove_particle, #satisfy_constraints
Methods inherited from AbstractItem
#add_event_listener, #always_redraw!, #always_redraw=, #always_redraw?, #cleanup, #dispatch_event, #draw, #has_event_listener, #init, #set_fill, #set_line, #set_style, #visible!, #visible?
Constructor Details
#initialize ⇒ Composite
Returns a new instance of Composite.
11 12 13 14 |
# File 'lib/pongo/composite.rb', line 11 def initialize super @delta = Vector.new end |
Instance Attribute Details
#delta ⇒ Object
Returns the value of attribute delta.
9 10 11 |
# File 'lib/pongo/composite.rb', line 9 def delta @delta end |
Instance Method Details
#fixed=(b) ⇒ Object
42 43 44 |
# File 'lib/pongo/composite.rb', line 42 def fixed=(b) particles.each {|p| p.fixed = b} end |
#fixed? ⇒ Boolean Also known as: fixed
The fixed state of the Composite. Setting this value to true or false will set all of this Composite’s component particles to that value. Getting this value will return false if any of the component particles are not fixed.
34 35 36 37 38 39 |
# File 'lib/pongo/composite.rb', line 34 def fixed? particles.each do |p| return false unless p.fixed? end true end |
#relative_angle(center, p) ⇒ Object Also known as: get_relative_angle
46 47 48 49 |
# File 'lib/pongo/composite.rb', line 46 def relative_angle(center, p) @delta.set_to(p.x - center.x, p.y - center.y) Math.atan2(@delta.y, @delta.x) end |
#rotate_by_angle(angle_degrees, center) ⇒ Object
Rotates the Composite to an angle specified in degrees, around a given center
27 28 29 |
# File 'lib/pongo/composite.rb', line 27 def rotate_by_angle(angle_degrees, center) rotate_by_radian(angle_degrees * Numeric::PI_OVER_ONE_EIGHTY, center) end |
#rotate_by_radian(angle_radians, center) ⇒ Object
Rotates the Composite to an angle specified in radians, around a given center
17 18 19 20 21 22 23 24 |
# File 'lib/pongo/composite.rb', line 17 def rotate_by_radian(angle_radians, center) particles.each do |p| radius = p.center.distance(center) angle = relative_angle(center, p.center) + angle_radians p.px = (Math.cos(angle) * radius) + center.x p.py = (Math.sin(angle) * radius) + center.y end end |