Skip to content

Commit 720d487

Browse files
committed
feat(collision): overlapping region as a config option
1 parent 967984f commit 720d487

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/jquery.collision.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
;(function($, window, document, undefined){
1010

1111
var defaults = {
12-
colliders_context: document.body
12+
colliders_context: document.body,
13+
overlapping_region: 'C'
1314
// ,on_overlap: function(collider_data){},
1415
// on_overlap_start : function(collider_data){},
1516
// on_overlap_stop : function(collider_data){}
@@ -27,6 +28,9 @@
2728
* of HTMLElements or an Array of Coords instances.
2829
* @param {Object} [options] An Object with all options you want to
2930
* overwrite:
31+
* @param {String} [options.overlapping_region] Determines when collision
32+
* is valid, depending on the overlapped area. Values can be: 'N', 'S',
33+
* 'W', 'E', 'C' or 'all'. Default is 'C'.
3034
* @param {Function} [options.on_overlap_start] Executes a function the first
3135
* time each `collider ` is overlapped.
3236
* @param {Function} [options.on_overlap_stop] Executes a function when a
@@ -126,6 +130,7 @@
126130

127131
fn.find_collisions = function(player_data_coords){
128132
var self = this;
133+
var overlapping_region = this.options.overlapping_region;
129134
var colliders_coords = [];
130135
var colliders_data = [];
131136
var $colliders = (this.colliders || this.$colliders);
@@ -149,7 +154,8 @@
149154
player_coords, collider_coords);
150155

151156
//todo: make this an option
152-
if (region === 'C'){
157+
if (region === overlapping_region || overlapping_region === 'all') {
158+
153159
var area_coords = self.calculate_overlapped_area_coords(
154160
player_coords, collider_coords);
155161
var area = self.calculate_overlapped_area(area_coords);

0 commit comments

Comments
 (0)