Skip to content

Commit

Permalink
feat(collision): overlapping region as a config option
Browse files Browse the repository at this point in the history
  • Loading branch information
vieron committed Mar 5, 2014
1 parent 967984f commit 720d487
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/jquery.collision.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
;(function($, window, document, undefined){

var defaults = {
colliders_context: document.body
colliders_context: document.body,
overlapping_region: 'C'
// ,on_overlap: function(collider_data){},
// on_overlap_start : function(collider_data){},
// on_overlap_stop : function(collider_data){}
Expand All @@ -27,6 +28,9 @@
* of HTMLElements or an Array of Coords instances.
* @param {Object} [options] An Object with all options you want to
* overwrite:
* @param {String} [options.overlapping_region] Determines when collision
* is valid, depending on the overlapped area. Values can be: 'N', 'S',
* 'W', 'E', 'C' or 'all'. Default is 'C'.
* @param {Function} [options.on_overlap_start] Executes a function the first
* time each `collider ` is overlapped.
* @param {Function} [options.on_overlap_stop] Executes a function when a
Expand Down Expand Up @@ -126,6 +130,7 @@

fn.find_collisions = function(player_data_coords){
var self = this;
var overlapping_region = this.options.overlapping_region;
var colliders_coords = [];
var colliders_data = [];
var $colliders = (this.colliders || this.$colliders);
Expand All @@ -149,7 +154,8 @@
player_coords, collider_coords);

//todo: make this an option
if (region === 'C'){
if (region === overlapping_region || overlapping_region === 'all') {

var area_coords = self.calculate_overlapped_area_coords(
player_coords, collider_coords);
var area = self.calculate_overlapped_area(area_coords);
Expand Down

0 comments on commit 720d487

Please sign in to comment.