collision functional (enough)
This commit is contained in:
parent
571db77fb1
commit
c0ee4124a1
Binary file not shown.
@ -43,6 +43,9 @@ namespace JustTheBasics
|
|||||||
private float maxY;
|
private float maxY;
|
||||||
private float minY;
|
private float minY;
|
||||||
|
|
||||||
|
private float xWidth;
|
||||||
|
private float yWidth;
|
||||||
|
|
||||||
//indicates if object has been spawned
|
//indicates if object has been spawned
|
||||||
private bool isSpawned = false;
|
private bool isSpawned = false;
|
||||||
|
|
||||||
@ -118,6 +121,10 @@ namespace JustTheBasics
|
|||||||
minY = spawnCoords[i].Y;
|
minY = spawnCoords[i].Y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//calculates objects width on both axis
|
||||||
|
xWidth = maxX - minX;
|
||||||
|
yWidth = maxY - minY;
|
||||||
|
|
||||||
//checks if collision is set and intersects with any existing object (with 0 movement)
|
//checks if collision is set and intersects with any existing object (with 0 movement)
|
||||||
if (col && intersects(0f, "l", temp))
|
if (col && intersects(0f, "l", temp))
|
||||||
{
|
{
|
||||||
@ -367,24 +374,30 @@ namespace JustTheBasics
|
|||||||
|
|
||||||
//bool ret = false;
|
//bool ret = false;
|
||||||
|
|
||||||
//change this to use the thinnest object in the relative direction
|
// finds least width in collision bounds, initializing to this object's width on respective axis
|
||||||
//or calculate object with smallest width that collision is possible with, prolly parallel for
|
float minWidth = dir.Equals("r") || dir.Equals("l") ? xWidth : yWidth;
|
||||||
float width;
|
|
||||||
|
|
||||||
if (dir.Equals("r") || dir.Equals("l"))
|
foreach (GameObject o in collision)
|
||||||
{
|
{
|
||||||
width = maxX - minX;
|
//checks if possible to pass over object on movement and finds min width in range
|
||||||
}
|
//maybe you should change normal calcs to this, slightly more efficient
|
||||||
else
|
if ((dir.Equals("r") && minX < o.getMaxX() && maxX + tspeed > o.getMinX() && o.getXWidth() < minWidth) ||
|
||||||
{
|
(dir.Equals("l") && maxX > o.getMinX() && minX - tspeed < o.getMaxX() && o.getXWidth() < minWidth))
|
||||||
width = maxY - minY;
|
{
|
||||||
|
minWidth = o.getXWidth();
|
||||||
|
}
|
||||||
|
if ((dir.Equals("u") && minY < o.getMaxY() && maxY + tspeed > o.getMinY() && o.getYWidth() < minWidth) ||
|
||||||
|
(dir.Equals("d") && maxY > o.getMinY() && minY - tspeed < o.getMaxY() && o.getYWidth() < minWidth))
|
||||||
|
{
|
||||||
|
minWidth = o.getYWidth();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float ospeed = 0;
|
float ospeed = 0;
|
||||||
|
|
||||||
//change to parallel for loop
|
|
||||||
for (float i = 1; ospeed < tspeed; i++)
|
for (float i = 1; ospeed < tspeed; i++)
|
||||||
{
|
{
|
||||||
if ((ospeed = i*width - 1) > tspeed)
|
if ((ospeed = i*minWidth - 1) > tspeed)
|
||||||
{
|
{
|
||||||
ospeed = tspeed;
|
ospeed = tspeed;
|
||||||
}
|
}
|
||||||
@ -412,6 +425,8 @@ namespace JustTheBasics
|
|||||||
foreach (Segment l in o.getSegments())
|
foreach (Segment l in o.getSegments())
|
||||||
{
|
{
|
||||||
//chacks if intersect
|
//chacks if intersect
|
||||||
|
//backup, flawed
|
||||||
|
//if ((s.getM() == 0 && l.getM() == 0 && s.getHY() > l.getHY() && s.getHY() - ospeed <= l.getHY())
|
||||||
if (s.intersect(l, false))
|
if (s.intersect(l, false))
|
||||||
{
|
{
|
||||||
//reverts segment
|
//reverts segment
|
||||||
@ -435,6 +450,7 @@ namespace JustTheBasics
|
|||||||
s.move(ospeed, "d");
|
s.move(ospeed, "d");
|
||||||
foreach (Segment l in o.getSegments())
|
foreach (Segment l in o.getSegments())
|
||||||
{
|
{
|
||||||
|
//if ((s.getM() == 0 && l.getM() == 0 && s.getHY() < l.getHY() && s.getHY() + ospeed >= l.getHY())
|
||||||
if (s.intersect(l, false))
|
if (s.intersect(l, false))
|
||||||
{
|
{
|
||||||
s.move(ospeed, "u");
|
s.move(ospeed, "u");
|
||||||
@ -455,6 +471,7 @@ namespace JustTheBasics
|
|||||||
s.move(ospeed, "l");
|
s.move(ospeed, "l");
|
||||||
foreach (Segment l in o.getSegments())
|
foreach (Segment l in o.getSegments())
|
||||||
{
|
{
|
||||||
|
//if ((Single.IsPositiveInfinity(s.getM()) && Single.IsPositiveInfinity(l.getM()) && s.getHX() < l.getHX() && s.getHX() + ospeed >= l.getHX())
|
||||||
if (s.intersect(l, true))
|
if (s.intersect(l, true))
|
||||||
{
|
{
|
||||||
s.move(ospeed, "r");
|
s.move(ospeed, "r");
|
||||||
@ -475,6 +492,7 @@ namespace JustTheBasics
|
|||||||
s.move(ospeed, "r");
|
s.move(ospeed, "r");
|
||||||
foreach (Segment l in o.getSegments())
|
foreach (Segment l in o.getSegments())
|
||||||
{
|
{
|
||||||
|
//if ((Single.IsPositiveInfinity(s.getM()) && Single.IsPositiveInfinity(l.getM()) && s.getHX() > l.getHX() && s.getHX() - ospeed <= l.getHX())
|
||||||
if (s.intersect(l, true))
|
if (s.intersect(l, true))
|
||||||
{
|
{
|
||||||
s.move(ospeed, "l");
|
s.move(ospeed, "l");
|
||||||
@ -611,6 +629,16 @@ namespace JustTheBasics
|
|||||||
return minY;
|
return minY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getYWidth()
|
||||||
|
{
|
||||||
|
return yWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getXWidth()
|
||||||
|
{
|
||||||
|
return xWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool spawned()
|
public bool spawned()
|
||||||
{
|
{
|
||||||
|
@ -49,8 +49,8 @@ namespace JustTheBasics
|
|||||||
//else indicates vertical line
|
//else indicates vertical line
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m = (float)Double.PositiveInfinity;
|
m = Single.PositiveInfinity;
|
||||||
b = (float)Double.PositiveInfinity;
|
b = Single.PositiveInfinity;
|
||||||
vert = true;
|
vert = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,12 +171,12 @@ namespace JustTheBasics
|
|||||||
}
|
}
|
||||||
|
|
||||||
//checks if segments intersect on given interval
|
//checks if segments intersect on given interval
|
||||||
//axis indicates axis of movemnt, true being x, flase being y
|
//xaxis indicates direction of movement respective to x axis
|
||||||
public bool intersect(Segment inter, bool xaxis)
|
public bool intersect(Segment inter, bool xaxis)
|
||||||
{
|
{
|
||||||
float interX;
|
float interX;
|
||||||
//returns false if lines are parallel
|
//returns false if lines are parallel
|
||||||
if (inter.getM() == m && inter.getB() == b)
|
if ((inter.getM() == m && inter.getB() == b) || (Single.IsPositiveInfinity(inter.getM()) && Single.IsPositiveInfinity(m)))
|
||||||
{
|
{
|
||||||
if((m == 0 && xaxis) && (lY == inter.getLY() && (startX < inter.getHX() && startX > inter.getLX())))
|
if((m == 0 && xaxis) && (lY == inter.getLY() && (startX < inter.getHX() && startX > inter.getLX())))
|
||||||
{
|
{
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user