Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Edge and ball collision event
- with other
- {
- var _x = (bbox_left + bbox_right) * 0.5, _y = (bbox_top + bbox_bottom) * 0.5,
- _w = sprite_width * 0.5, _h = sprite_height * 0.5,
- _cos = dcos(image_angle), _sin = -dsin(image_angle),
- _wcos = _w * _cos, _wsin = _w * _sin,
- _hcos = _h * _cos, _hsin = _h * _sin,
- _x1 = _x - _wcos + _hsin,
- _y1 = _y - _wsin - _hcos,
- _x2 = _x + _wcos + _hsin,
- _y2 = _y + _wsin - _hcos;
- }
- var _vx = _x2 - _x1,
- _vy = _y2 - _y1,
- _dot = _vx*_vx + _vy*_vy,
- _proj_x = x - _x1,
- _proj_y = y - _y1,
- _t = max(0, min(_dot, _vx * _proj_x + _vy * _proj_y)) / _dot,
- _collision_x = _x1 + _t * _vx,
- _collision_y = _y1 + _t * _vy,
- _vx = x - _collision_x,
- _vy = y - _collision_y,
- _dist = sqrt(_vx * _vx + _vy * _vy),
- _radius = sprite_width * 0.5;
- if (_dist < _radius)
- {
- _vx /= _dist;
- _vy /= _dist;
- x = _collision_x + _vx * _radius;
- y = _collision_y + _vy * _radius;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement