Class: DXOpal::Sprite::CollisionArea::Point

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

Instance Attribute Summary

Attributes inherited from Base

#sprite

Instance Method Summary collapse

Methods inherited from Base

#aabb, #absolute, #absolute1, #transback, #transback1

Constructor Details

#initialize(sprite, x, y) ⇒ Point

Returns a new instance of Point.



89
90
91
92
# File 'lib/dxopal/sprite/collision_area.rb', line 89

def initialize(sprite, x, y)
  @sprite, @x, @y = sprite, x, y
  super()
end

Instance Method Details

#absolute_posObject

Return [x, y]



117
118
119
# File 'lib/dxopal/sprite/collision_area.rb', line 117

def absolute_pos
  absolute1([@x, @y])
end

#collides?(other) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/dxopal/sprite/collision_area.rb', line 96

def collides?(other)
  case other.type
  when :Point
    self.absolute_pos == other.absolute_pos
  when :Circle
    x, y = *transback1(self.absolute_pos, other.sprite)
    cx, cy = *other.absolute_norot_pos
    `Opal.DXOpal.CCk.check_point_circle(x, y, cx, cy, #{other.r})`
  when :Rect
    x, y = *transback1(self.absolute_pos, other.sprite)
    ((x1, y1), (x2, y2)) = *other.absolute_norot_poss
    `Opal.DXOpal.CCk.check_point_straight_rect(x, y, x1, y1, x2, y2)`
  when :Triangle
    x, y = *absolute_pos
    (x1, y1), (x2, y2), (x3, y3) = *other.absolute_poss
    `Opal.DXOpal.CCk.check_point_triangle(x, y, x1, y1, x2, y2, x3, y3)`
  else raise
  end
end

#typeObject



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

def type; :Point; end