Added Oversimplified.GameObjectsAtPoint() to return a list of all objects overlapping with a point, altered Oversimplified.CollisionAtPoint() to use Oversimpified.GameObjectsAtPoint() to reduce code.

This commit is contained in:
Robbie Antenesse 2016-04-08 07:33:11 -06:00
parent 9ad26265d1
commit fbfa3faa53
1 changed files with 37 additions and 22 deletions

View File

@ -889,8 +889,7 @@ Oversimplified.GameObject.prototype.IsOverlapping = function (doSimple) {
Oversimplified.GameObject.prototype.IfOverlappingThenMove = function (doSimple) {
var overlappingObject = this.IsOverlapping(doSimple);
if (overlappingObject != false)
{
if (overlappingObject != false) {
if (this.x < overlappingObject.x)
this.x--;
if (this.x >= overlappingObject.x)
@ -899,6 +898,10 @@ Oversimplified.GameObject.prototype.IfOverlappingThenMove = function (doSimple)
this.y--;
if (this.y >= overlappingObject.y)
this.y++;
return true;
} else {
return false;
}
}
@ -987,12 +990,10 @@ Oversimplified.GameObject.prototype.Destroy = function () {
// Check if the point (x, y) lies inside the bounds of ANY object in the room.
// If yes and if that object is flagged as solid, then there is a collision.
Oversimplified.CollisionAtPoint = function (x, y) {
var currentRoom = Oversimplified.R[Oversimplified.R.currentRoom];
Oversimplified.GameObjectsAtPoint = function (x, y) {
var objectsAtPoint = [];
for (var obj in Oversimplified.O) {
var object = Oversimplified.O[obj];
if (object != this) {
for (var i = 0; i < 2 * object.xBound; i++) {
for (var j = 0; j < 2 * object.yBound; j++) {
var xToCheck = (object.x - object.xBound) + i;
@ -1000,15 +1001,29 @@ Oversimplified.CollisionAtPoint = function (x, y) {
if (xToCheck == x && yToCheck == y)
{
if (object.solid) {
return true;
}
}
objectsAtPoint.push(object);
}
}
}
}
if (objectsAtPoint.length > 0) {
return objectsAtPoint;
} else {
return false;
}
}
// Check if the point (x, y) lies inside the bounds of ANY object in the room.
// If yes and if that object is flagged as solid, then there is a collision.
Oversimplified.CollisionAtPoint = function (x, y) {
var objectsAtPoint = Oversimplified.GameObjectsAtPoint(x, y);
for (var i = 0; i < objectsAtPoint.length; i++) {
if (objectsAtPoint[i].solid == true) {
return true;
}
}
return false;
}