Skip to content

Commit 62abd1d

Browse files
author
Lios
committed
Adds the BoundIntersectCollision Component.
1 parent fcda2ff commit 62abd1d

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Lynx Project
3+
* Started August 2013
4+
* ------------------------------------------------------
5+
* This file is covered under the LynxJS Game Library
6+
* License. Please read license.txt for more information
7+
* on usage of this library.
8+
* ------------------------------------------------------
9+
* Component Name: BoundIntersectCollision
10+
* Author: Cosrnos
11+
* Description: Collision detection using the bounds intersect method and a quadtree.
12+
*/
13+
14+
15+
(function(){
16+
var name = "BoundIntersectCollision";
17+
var auth = "Cosrnos";
18+
var desc = "Collision detection using the bounds intersect method and a quadtree.";
19+
20+
var build = function(){
21+
var _tree = new Lynx.Quadtree(0, 2, 4, new Lynx.Rect(0, 0, Lynx.Scene.Width, Lynx.Scene.Height));
22+
23+
this.On("Update", function(pEvent, pSender)
24+
{
25+
_tree.Clear();
26+
27+
for(var i = 0; i < Lynx.Scene.Entities.length; i++)
28+
_tree.Insert(Lynx.Scene.Entities[i]);
29+
30+
for(var x = 0; x < Lynx.Scene.Entities.length; x++)
31+
{
32+
var tObj = Lynx.Scene.Entities[x];
33+
var testArr = _tree.GetInRegion(tObj.Bounds);
34+
for(var y = 0; y < testArr.length; y++)
35+
{
36+
var sObj = testArr[y];
37+
if(!(sObj.X + sObj.Width < tObj.X || sObj.Y + sObj.Height < tObj.Y || sObj.Y > tObj.Y + tObj.Height || sObj.X > tObj.X + tObj.Width))
38+
{
39+
Lynx.Emit("Collision.Found", { T: tObj, S: sObj });
40+
}
41+
}
42+
}
43+
44+
return true;
45+
});
46+
};
47+
48+
Lynx.Component(name, auth, desc, build);
49+
})();

0 commit comments

Comments
 (0)