
1.制作障碍系统 (1.制作几种类型的障碍物的预制体 ((*.编写障碍物基类,以下几种均继承自基类,含碰撞体,RememberY(生成障碍物时该有多大的Y) ((1.矮障碍,仅碰撞体 ((2.高障碍,仅碰撞体 ((3.可冲破障碍 (((1.除基本碰撞体外,额外包含一个触发器,比碰撞体先检测到马,同时获取马的x速度,大于阈值则给障碍做破碎,用马的力度决定破碎力,关闭碎块和马的碰撞 (((*.导入某2D破碎插件 ((4.人马分离障碍 (((WAIT,需要等待人马分离系统先搭建 (2.编写障碍物生成系统 ((1.每若干时间,生成一个随机一种障碍,若干的范围可控 (((1.设计协程,从预制体列表中随机出一种,并在计算好的位置实例化,随后等待范围内的若干时间,然后检查马的存活情况,若马仍存活,重新调用本协程 ((2.生成的位置:x在相机右侧若干不变距离,y根据障碍物的不同而不同,需要计算保存。 (3.编写障碍物消亡系统 ((1.每个障碍物和碎片都会在离开镜头后被删除
121 lines
2.5 KiB
C#
121 lines
2.5 KiB
C#
using UnityEngine;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Delaunay.LR;
|
|
|
|
namespace Delaunay
|
|
{
|
|
|
|
public sealed class Vertex: ICoord
|
|
{
|
|
public static readonly Vertex VERTEX_AT_INFINITY = new Vertex (float.NaN, float.NaN);
|
|
|
|
private static Stack<Vertex> _pool = new Stack<Vertex> ();
|
|
private static Vertex Create (float x, float y)
|
|
{
|
|
if (float.IsNaN (x) || float.IsNaN (y)) {
|
|
return VERTEX_AT_INFINITY;
|
|
}
|
|
if (_pool.Count > 0) {
|
|
return _pool.Pop ().Init (x, y);
|
|
} else {
|
|
return new Vertex (x, y);
|
|
}
|
|
}
|
|
|
|
|
|
private static int _nvertices = 0;
|
|
|
|
private Vector2 _coord;
|
|
public Vector2 Coord {
|
|
get { return _coord;}
|
|
}
|
|
private int _vertexIndex;
|
|
public int vertexIndex {
|
|
get { return _vertexIndex;}
|
|
}
|
|
|
|
public Vertex (float x, float y)
|
|
{
|
|
Init (x, y);
|
|
}
|
|
|
|
private Vertex Init (float x, float y)
|
|
{
|
|
_coord = new Vector2 (x, y);
|
|
return this;
|
|
}
|
|
|
|
public void Dispose ()
|
|
{
|
|
_pool.Push (this);
|
|
}
|
|
|
|
public void SetIndex ()
|
|
{
|
|
_vertexIndex = _nvertices++;
|
|
}
|
|
|
|
public override string ToString ()
|
|
{
|
|
return "Vertex (" + _vertexIndex + ")";
|
|
}
|
|
|
|
/**
|
|
* This is the only way to make a Vertex
|
|
*
|
|
* @param halfedge0
|
|
* @param halfedge1
|
|
* @return
|
|
*
|
|
*/
|
|
public static Vertex Intersect (Halfedge halfedge0, Halfedge halfedge1)
|
|
{
|
|
Edge edge0, edge1, edge;
|
|
Halfedge halfedge;
|
|
float determinant, intersectionX, intersectionY;
|
|
bool rightOfSite;
|
|
|
|
edge0 = halfedge0.edge;
|
|
edge1 = halfedge1.edge;
|
|
if (edge0 == null || edge1 == null) {
|
|
return null;
|
|
}
|
|
if (edge0.rightSite == edge1.rightSite) {
|
|
return null;
|
|
}
|
|
|
|
determinant = edge0.a * edge1.b - edge0.b * edge1.a;
|
|
if (-1.0e-10 < determinant && determinant < 1.0e-10) {
|
|
// the edges are parallel
|
|
return null;
|
|
}
|
|
|
|
intersectionX = (edge0.c * edge1.b - edge1.c * edge0.b) / determinant;
|
|
intersectionY = (edge1.c * edge0.a - edge0.c * edge1.a) / determinant;
|
|
|
|
if (Voronoi.CompareByYThenX (edge0.rightSite, edge1.rightSite) < 0) {
|
|
halfedge = halfedge0;
|
|
edge = edge0;
|
|
} else {
|
|
halfedge = halfedge1;
|
|
edge = edge1;
|
|
}
|
|
rightOfSite = intersectionX >= edge.rightSite.x;
|
|
if ((rightOfSite && halfedge.leftRight == Side.LEFT)
|
|
|| (!rightOfSite && halfedge.leftRight == Side.RIGHT)) {
|
|
return null;
|
|
}
|
|
|
|
return Vertex.Create (intersectionX, intersectionY);
|
|
}
|
|
|
|
public float x {
|
|
get { return _coord.x;}
|
|
}
|
|
public float y {
|
|
get{ return _coord.y;}
|
|
}
|
|
|
|
}
|
|
} |