Module: Chingu::Traits::BoundingCircle
- Defined in:
- lib/chingu/traits/bounding_circle.rb
Overview
Providing a bounding circle in the form of 2 attributes, self.radius and self.diameter It creates these 2 attributes from reading image.height, image.width, factor_x and factor_y
…this usually only makes sense with rotation_center = :center
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#collidable ⇒ Object
Returns the value of attribute collidable.
Instance Method Summary collapse
- #cache_bounding_circle ⇒ Object
- #circle_bottom ⇒ Object
-
#circle_left ⇒ Object
def update_trait cache_bounding_circle if trait_options[:cache] && !@cached_radius super end.
- #circle_right ⇒ Object
- #circle_top ⇒ Object
- #collision_at?(x, y) ⇒ Boolean
- #diameter ⇒ Object
-
#draw_debug ⇒ Object
Visualises the bounding circle as a red circle.
- #draw_trait ⇒ Object
- #radius ⇒ Object
- #setup_trait(options) ⇒ Object
Instance Attribute Details
#collidable ⇒ Object
Returns the value of attribute collidable.
31 32 33 |
# File 'lib/chingu/traits/bounding_circle.rb', line 31 def collidable @collidable end |
Instance Method Details
#cache_bounding_circle ⇒ Object
60 61 62 |
# File 'lib/chingu/traits/bounding_circle.rb', line 60 def cache_bounding_circle @cached_radius = self.radius end |
#circle_bottom ⇒ Object
72 |
# File 'lib/chingu/traits/bounding_circle.rb', line 72 def circle_bottom; self.y + self.radius; end |
#circle_left ⇒ Object
def update_trait
cache_bounding_circle if [:bounding_circle][:cache] && !@cached_radius
super
end
69 |
# File 'lib/chingu/traits/bounding_circle.rb', line 69 def circle_left; self.x - self.radius; end |
#circle_right ⇒ Object
70 |
# File 'lib/chingu/traits/bounding_circle.rb', line 70 def circle_right; self.x + self.radius; end |
#circle_top ⇒ Object
71 |
# File 'lib/chingu/traits/bounding_circle.rb', line 71 def circle_top; self.y - self.radius; end |
#collision_at?(x, y) ⇒ Boolean
45 46 47 |
# File 'lib/chingu/traits/bounding_circle.rb', line 45 def collision_at?(x, y) Gosu.distance(self.x, self.y, x, y) < radius end |
#diameter ⇒ Object
56 57 58 |
# File 'lib/chingu/traits/bounding_circle.rb', line 56 def diameter radius * 2 end |
#draw_debug ⇒ Object
Visualises the bounding circle as a red circle.
82 83 84 |
# File 'lib/chingu/traits/bounding_circle.rb', line 82 def draw_debug $window.draw_circle(self.x, self.y, self.radius, Chingu::DEBUG_COLOR) end |
#draw_trait ⇒ Object
74 75 76 77 |
# File 'lib/chingu/traits/bounding_circle.rb', line 74 def draw_trait draw_debug if [:bounding_circle][:debug] super end |
#radius ⇒ Object
49 50 51 52 53 54 |
# File 'lib/chingu/traits/bounding_circle.rb', line 49 def radius return @cached_radius if @cached_radius radius = (self.width + self.height) / 4 radius = radius * [:bounding_circle][:scale] if [:bounding_circle][:scale] return radius end |
#setup_trait(options) ⇒ Object
39 40 41 42 43 |
# File 'lib/chingu/traits/bounding_circle.rb', line 39 def setup_trait() @cached_radius = nil @collidable = true super end |