forked from MagicBane/Server
FatBoy-DOTC
11 months ago
6 changed files with 234 additions and 0 deletions
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
package engine.collision; |
||||
|
||||
import java.awt.geom.Line2D; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
public class Mesh { |
||||
public ArrayList<Triangle> triangles; |
||||
public ArrayList<Line2D> BoundingLines; |
||||
public float meshHeight; |
||||
|
||||
public boolean BoundsCollides(Line2D line){ |
||||
for(Line2D side : BoundingLines) |
||||
if(side.intersectsLine(line)) |
||||
return true; |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public boolean MeshCollides(Line2D line, float charHeight){ |
||||
|
||||
//movement path does not intersect this mesh
|
||||
if(!this.BoundsCollides(line)) |
||||
return false; |
||||
|
||||
//character moving is higher than the max Y of this mesh
|
||||
if(charHeight < this.meshHeight) |
||||
return false; |
||||
|
||||
for(Triangle tri : triangles) |
||||
if(tri.collides(line)) |
||||
return true; |
||||
|
||||
//characters movement path did not intersect this triangle
|
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
package engine.collision; |
||||
|
||||
import java.awt.geom.Line2D; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
public class Triangle { |
||||
public ArrayList<Line2D> sides; |
||||
public boolean collides(Line2D line) |
||||
{ |
||||
for(Line2D side : sides) |
||||
if(side.intersectsLine(line)) |
||||
return true; |
||||
|
||||
return false; |
||||
} |
||||
} |
Loading…
Reference in new issue