Class: DXOpal::Sprite::CollisionArea::Circle

Inherits:
Base
  • Object
show all
Defined in:
lib/dxopal/sprite/collision_area.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#sprite

Instance Method Summary collapse

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

#rObject (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_posObject



159
160
161
# File 'lib/dxopal/sprite/collision_area.rb', line 159

def absolute_norot_pos
  [@x + @sprite.x, @y + @sprite.y]
end

#absolute_posObject

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

Returns:

  • (Boolean)


132
133
134
# File 'lib/dxopal/sprite/collision_area.rb', line 132

def circle?
  @sprite.scale_x == @sprite.scale_y
end

#collides?(other) ⇒ Boolean

Returns:

  • (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

#typeObject



129
# File 'lib/dxopal/sprite/collision_area.rb', line 129

def type; :Circle; end