Class: DXOpal::Sprite::CollisionArea::Circle
- Defined in:
- lib/dxopal/sprite/collision_area.rb
Instance Attribute Summary collapse
-
#r ⇒ Object
readonly
Returns the value of attribute r.
Attributes inherited from Base
Instance Method Summary collapse
- #absolute_norot_pos ⇒ Object
-
#absolute_pos ⇒ Object
Return [x, y].
-
#circle? ⇒ Boolean
Return true if this is not an ellipsis.
- #collides?(other) ⇒ Boolean
-
#initialize(sprite, x, y, r) ⇒ Circle
constructor
A new instance of Circle.
- #type ⇒ Object
Methods inherited from Base
#aabb, #absolute, #absolute1, #transback, #transback1
Constructor Details
#initialize(sprite, x, y, r) ⇒ Circle
Returns a new instance of Circle.
123 124 125 126 |
# File 'lib/dxopal/sprite/collision_area.rb', line 123 def initialize(sprite, x, y, r) @sprite, @x, @y, @r = sprite, x, y, r super() end |
Instance Attribute Details
#r ⇒ Object (readonly)
Returns the value of attribute r.
127 128 129 |
# File 'lib/dxopal/sprite/collision_area.rb', line 127 def r @r end |
Instance Method Details
#absolute_norot_pos ⇒ Object
159 160 161 |
# File 'lib/dxopal/sprite/collision_area.rb', line 159 def absolute_norot_pos [@x + @sprite.x, @y + @sprite.y] end |
#absolute_pos ⇒ Object
Return [x, y]
155 156 157 |
# File 'lib/dxopal/sprite/collision_area.rb', line 155 def absolute_pos absolute1([@x, @y]) end |
#circle? ⇒ Boolean
Return true if this is not an ellipsis
132 133 134 |
# File 'lib/dxopal/sprite/collision_area.rb', line 132 def circle? @sprite.scale_x == @sprite.scale_y end |
#collides?(other) ⇒ Boolean
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/dxopal/sprite/collision_area.rb', line 136 def collides?(other) case other.type when :Point other.collides?(self) when :Circle collides_circle?(other) when :Rect cx, cy = *self.absolute_norot_pos (x1, y1), (x2, y2), (x3, y3), (x4, y4) = *transback(other.absolute_poss, @sprite) `Opal.DXOpal.CCk.check_circle_tilted_rect(cx, cy, #{@r}, x1, y1, x2, y2, x3, y3, x4, y4)` when :Triangle cx, cy = *self.absolute_norot_pos (x1, y1), (x2, y2), (x3, y3) = *transback(other.absolute_poss, @sprite) `Opal.DXOpal.CCk.check_circle_triangle(cx, cy, #{@r}, x1, y1, x2, y2, x3, y3)` else raise end end |
#type ⇒ Object
129 |
# File 'lib/dxopal/sprite/collision_area.rb', line 129 def type; :Circle; end |