
1.制作障碍系统 (1.制作几种类型的障碍物的预制体 ((*.编写障碍物基类,以下几种均继承自基类,含碰撞体,RememberY(生成障碍物时该有多大的Y) ((1.矮障碍,仅碰撞体 ((2.高障碍,仅碰撞体 ((3.可冲破障碍 (((1.除基本碰撞体外,额外包含一个触发器,比碰撞体先检测到马,同时获取马的x速度,大于阈值则给障碍做破碎,用马的力度决定破碎力,关闭碎块和马的碰撞 (((*.导入某2D破碎插件 ((4.人马分离障碍 (((WAIT,需要等待人马分离系统先搭建 (2.编写障碍物生成系统 ((1.每若干时间,生成一个随机一种障碍,若干的范围可控 (((1.设计协程,从预制体列表中随机出一种,并在计算好的位置实例化,随后等待范围内的若干时间,然后检查马的存活情况,若马仍存活,重新调用本协程 ((2.生成的位置:x在相机右侧若干不变距离,y根据障碍物的不同而不同,需要计算保存。 (3.编写障碍物消亡系统 ((1.每个障碍物和碎片都会在离开镜头后被删除
125 lines
3.8 KiB
C#
125 lines
3.8 KiB
C#
using Delaunay.LR;
|
|
using Delaunay.Utils;
|
|
using System.Collections.Generic;
|
|
|
|
/** This class is horrible, and ought to be nuked from orbit. But the library is
|
|
heavily dependent upon it in undocumented ways.
|
|
|
|
It's viciously complicated, and is used all over the library in odd places where it
|
|
shouldn't be used, with no explanation - but with a hard dependency in that it
|
|
doesn't merely "re-order" edges (as the name suggests!) but often "generates" them
|
|
too.
|
|
|
|
It feels like it was intended to be semi-optimized (in the original AS3? probably),
|
|
but in a modern language like C#, there are far far better ways of doing this.
|
|
|
|
Currently: in my own projects, I am DELETING the output of this class, it's far
|
|
too dangerous to use in production. I recommend you do the same: write an
|
|
equivalent class (or better: set of classes) that are C#-friendly and do what they
|
|
say, and no more and no less. Hopefully one day someone will re-write this thing
|
|
and REMOVE IT from the rest of the library (all the places where it shouldn't be used)
|
|
*/
|
|
namespace Delaunay
|
|
{
|
|
public enum VertexOrSite
|
|
{
|
|
VERTEX,
|
|
SITE
|
|
}
|
|
|
|
sealed class EdgeReorderer: Utils.IDisposable
|
|
{
|
|
private List<Edge> _edges;
|
|
private List<Side> _edgeOrientations;
|
|
public List<Edge> edges {
|
|
get { return _edges;}
|
|
}
|
|
public List<Side> edgeOrientations {
|
|
get{ return _edgeOrientations;}
|
|
}
|
|
|
|
public EdgeReorderer (List<Edge> origEdges, VertexOrSite criterion)
|
|
{
|
|
_edges = new List<Edge> ();
|
|
_edgeOrientations = new List<Side> ();
|
|
if (origEdges.Count > 0) {
|
|
_edges = ReorderEdges (origEdges, criterion);
|
|
}
|
|
}
|
|
|
|
public void Dispose ()
|
|
{
|
|
_edges = null;
|
|
_edgeOrientations = null;
|
|
}
|
|
|
|
private List<Edge> ReorderEdges (List<Edge> origEdges, VertexOrSite criterion)
|
|
{
|
|
int i;
|
|
int n = origEdges.Count;
|
|
Edge edge;
|
|
// we're going to reorder the edges in order of traversal
|
|
bool[] done = new bool[n];
|
|
int nDone = 0;
|
|
for (int j=0; j<n; j++) {
|
|
done [j] = false;
|
|
}
|
|
List<Edge> newEdges = new List<Edge> (); // TODO: Switch to Deque if performance is a concern
|
|
|
|
i = 0;
|
|
edge = origEdges [i];
|
|
newEdges.Add (edge);
|
|
_edgeOrientations.Add (Side.LEFT);
|
|
ICoord firstPoint = (criterion == VertexOrSite.VERTEX) ? (ICoord)edge.leftVertex : (ICoord)edge.leftSite;
|
|
ICoord lastPoint = (criterion == VertexOrSite.VERTEX) ? (ICoord)edge.rightVertex : (ICoord)edge.rightSite;
|
|
|
|
if (firstPoint == Vertex.VERTEX_AT_INFINITY || lastPoint == Vertex.VERTEX_AT_INFINITY) {
|
|
return new List<Edge> ();
|
|
}
|
|
|
|
done [i] = true;
|
|
++nDone;
|
|
|
|
while (nDone < n) {
|
|
for (i = 1; i < n; ++i) {
|
|
if (done [i]) {
|
|
continue;
|
|
}
|
|
edge = origEdges [i];
|
|
ICoord leftPoint = (criterion == VertexOrSite.VERTEX) ? (ICoord)edge.leftVertex : (ICoord)edge.leftSite;
|
|
ICoord rightPoint = (criterion == VertexOrSite.VERTEX) ? (ICoord)edge.rightVertex : (ICoord)edge.rightSite;
|
|
if (leftPoint == Vertex.VERTEX_AT_INFINITY || rightPoint == Vertex.VERTEX_AT_INFINITY) {
|
|
return new List<Edge> ();
|
|
}
|
|
if (leftPoint == lastPoint) {
|
|
lastPoint = rightPoint;
|
|
_edgeOrientations.Add (Side.LEFT);
|
|
newEdges.Add (edge);
|
|
done [i] = true;
|
|
} else if (rightPoint == firstPoint) {
|
|
firstPoint = leftPoint;
|
|
_edgeOrientations.Insert (0, Side.LEFT); // TODO: Change datastructure if this is slow
|
|
newEdges.Insert (0, edge);
|
|
done [i] = true;
|
|
} else if (leftPoint == firstPoint) {
|
|
firstPoint = rightPoint;
|
|
_edgeOrientations.Insert (0, Side.RIGHT);
|
|
newEdges.Insert (0, edge);
|
|
done [i] = true;
|
|
} else if (rightPoint == lastPoint) {
|
|
lastPoint = leftPoint;
|
|
_edgeOrientations.Add (Side.RIGHT);
|
|
newEdges.Add (edge);
|
|
done [i] = true;
|
|
}
|
|
if (done [i]) {
|
|
++nDone;
|
|
}
|
|
}
|
|
}
|
|
|
|
return newEdges;
|
|
}
|
|
|
|
}
|
|
} |