예제 #1
0
 public static void SetFVec2(this Hashtable ht, string key, FVec2 v)
 {
     float[] al = new float[2];
     al[0]   = ( float )v.x;
     al[1]   = ( float )v.y;
     ht[key] = al;
 }
예제 #2
0
 public void Identity()
 {
     this.x.x = Fix64.One;
     this.x.y = Fix64.Zero;
     this.y.x = Fix64.Zero;
     this.y.y = Fix64.One;
 }
예제 #3
0
        private void CreatePlayers(BattleParams.Player[] players)
        {
            FVec3 worldOffset =
                this._maze.LocalPointToGlobalPoint(new FVec3(this._maze.startPointPlace[0] * Fix64.Half, Fix64.Zero,
                                                             this._maze.startPointPlace[1] * Fix64.Half));
            FVec3 center = this._maze.centerOfStartRange;
            int   count  = players.Length;

            for (int i = 0; i < count; i++)
            {
                BattleParams.Player player = players[i];
                FVec2       rndCircle      = this._random.onUnitCircle;
                EntityParam entityParam    = new EntityParam
                {
                    rid      = player.cid + "@" + player.id,
                    uid      = player.id,
                    skin     = player.skin,
                    team     = player.team,
                    position = new FVec3(this._random.NextFix64(center.x - worldOffset.x, center.x + worldOffset.x),
                                         center.y,
                                         this._random.NextFix64(center.z - worldOffset.z, center.z + worldOffset.z)),
                    direction = new FVec3(rndCircle.x, Fix64.Zero, rndCircle.y)
                };
                Champion champion = this._entityManager.Create <Champion>(entityParam);
                champion.position = this.maze.RestrictInBounds(champion, true);
            }
        }
예제 #4
0
        public override void DecodeSnapshot(ulong rid, bool isNew, CodedInputStream reader)
        {
            base.DecodeSnapshot(rid, isNew, reader);
            this.team             = reader.ReadInt32();
            this.name             = reader.ReadString();
            this.hp               = reader.ReadInt32();
            this.mhp              = reader.ReadInt32();
            this.mp               = ( Fix64 )reader.ReadDouble();
            this.mmp              = reader.ReadInt32();
            this.mpRecover        = reader.ReadInt32();
            this.atk              = reader.ReadInt32();
            this.def              = reader.ReadInt32();
            this.disableMove      = reader.ReadInt32();
            this.disableTurn      = reader.ReadInt32();
            this.disableSkill     = reader.ReadInt32();
            this.disableCollision = reader.ReadInt32();
            this.supperArmor      = reader.ReadInt32();
            this.invulnerAbility  = reader.ReadInt32();
            this.moveDirection    = new FVec2(( Fix64 )reader.ReadDouble(), ( Fix64 )reader.ReadDouble());
            this.intersectVector  = new FVec2(( Fix64 )reader.ReadDouble(), ( Fix64 )reader.ReadDouble());
            this.phyxSpeed        = new FVec2(( Fix64 )reader.ReadDouble(), ( Fix64 )reader.ReadDouble());
            this.velocity         = ( Fix64 )reader.ReadDouble();
            this.isDead           = reader.ReadBool();
            this.t_hp_add         = reader.ReadInt32();
            this.t_mp_add         = reader.ReadInt32();
            this.t_atk_add        = reader.ReadInt32();
            this.t_def_add        = reader.ReadInt32();
            this.t_speed_add      = reader.ReadInt32();

            this.fsm.DecodeSnapshot(reader);
            reader.ReadBytes();
        }
예제 #5
0
 public FVec2 Transform(FVec2 v)
 {
     return(new FVec2
            (
                v.x * this.x.x + v.y * this.y.x,
                v.x * this.x.y + v.y * this.y.y
            ));
 }
예제 #6
0
        public void Transpose()
        {
            Fix64 m00 = this.x.x;
            Fix64 m01 = this.y.x;
            Fix64 m10 = this.x.y;
            Fix64 m11 = this.y.y;

            this.x.x = m00;
            this.x.y = m01;
            this.y.x = m10;
            this.y.y = m11;
        }
예제 #7
0
        public void Invert()
        {
            Fix64 determinant = Fix64.One / (this.x.x * this.y.y - this.x.y * this.y.x);
            Fix64 m00         = this.y.y * determinant;
            Fix64 m01         = -this.x.y * determinant;
            Fix64 m10         = -this.y.x * determinant;
            Fix64 m11         = this.x.x * determinant;

            this.x.x = m00;
            this.x.y = m01;
            this.y.x = m10;
            this.y.y = m11;
        }
예제 #8
0
 /// <summary>
 /// 解码快照
 /// </summary>
 public virtual void DecodeSnapshot(ulong rid, bool isNew, CodedInputStream reader)
 {
     this.rid = rid;
     this.id  = reader.ReadInt32();
     if (isNew)
     {
         this.LoadDefs();
         this.OnInit();
     }
     this.markToDestroy = reader.ReadBool();
     this.position      = new FVec2(( Fix64 )reader.ReadDouble(), ( Fix64 )reader.ReadDouble());
     this.direction     = new FVec2(( Fix64 )reader.ReadDouble(), ( Fix64 )reader.ReadDouble());
 }
예제 #9
0
        public void SupplyItems()
        {
            int count = this._battle.maxItemCount - this._items.Count;

            for (int i = 0; i < count; i++)
            {
                string id        = this._battle.items[this._battle.random.Next(0, this._battle.items.Length)];
                FVec3  position  = this._battle.maze.GetRandomPointInWalkables(this._battle.random);
                FVec2  rndCircle = this._battle.random.onUnitCircle;
                Item   item      = this._battle.CreateItem(this._battle.random.IdHash(id), position,
                                                           new FVec3(rndCircle.x, Fix64.Zero, rndCircle.y));
                this._items.Add(item);
            }
            this._itemRefreshTime = this._battle.time +
                                    this._battle.random.NextFix64(this._battle.itemUpdateInterval[0],
                                                                  this._battle.itemUpdateInterval[1]);
        }
예제 #10
0
 public FMat2(FVec2 x, FVec2 y)
 {
     this.x = x;
     this.y = y;
 }
예제 #11
0
 public static FMat2 FromCross(FVec2 xVector)
 {
     return(new FMat2(xVector, new FVec2(-xVector.y, xVector.x)));
 }
예제 #12
0
파일: FLine2.cs 프로젝트: niuniuzhu/KOW
 public FLine2(FVec2 point1, FVec2 point2)
 {
     this.point1 = point1;
     this.point2 = point2;
 }
예제 #13
0
        public Maze(FPseudoRandom random,
                    FVec3 scale, FVec3 offset, int row, int col,
                    int startIndex, int endIndex, FVec2 startPointPlace)
        {
            this.startPointPlace = startPointPlace;
            if (this.row < ( int )this.startPointPlace.y + 3 ||
                this.col < ( int )this.startPointPlace.x + 3)
            {
                throw new Exception("The row or col invaild");
            }

            this.scale  = scale;
            this.offset = offset;
            this.row    = row;
            this.col    = col;

            this._localToWorld = FMat4.FromTRS(this.offset, FQuat.identity, this.scale);
            this._worldToLocal = FMat4.NonhomogeneousInverse(this._localToWorld);

            //创建二维图
            Graph2D graph2 = this.CreateFullDigraph(random);

            //创建格子
            this.CreateTiles(graph2);

            //是否随机起点和终点
            this.startIndex = startIndex < 0 ? this.RandomIndexWithinBorder(random) : startIndex;
            if (endIndex < 0)
            {
                int[] candidate = new int[5];
                for (int i = 0; i < 5; i++)
                {
                    candidate[i] = this.RandomIndexWithinBorder(random);
                }
                endIndex = this.GetFarthestToStartIndex(this.startIndex, candidate);
            }
            this.endIndex = endIndex;

            //初始化起点范围
            HashSet <int> walkablesHs = new HashSet <int>();

            this.SetStart(graph2, this.startIndex, walkablesHs);

            //创建起点和终点
            int[]            coord       = graph2.IndexToCoord(this.startIndex);
            Delaunay.DVertex startVertex = new Delaunay.DVertex(coord[0], coord[1]);
            coord = graph2.IndexToCoord(this.endIndex);
            Delaunay.DVertex endVertex = new Delaunay.DVertex(coord[0], coord[1]);
            //创建外圆周附近的顶点
            List <Delaunay.DVertex> vertices1 = this.GenVertices(24, 1f, 0.8f, 24, random);
            //创建内圆周附近的顶点
            List <Delaunay.DVertex> vertices2 = this.GenVertices(12, 0.2f, 0.6f, 12, random);
            //合并所有顶点
            List <Delaunay.DVertex> vertices = new List <Delaunay.DVertex> {
                startVertex, endVertex
            };

            vertices.AddRange(vertices1);
            vertices.AddRange(vertices2);

            //点集合的三角化
            List <Delaunay.DTriangle> triangles = Delaunay.Triangulate(vertices);

            //从三角形集合创建图
            GraphBase graph = Tools.TrianglesToGraph(triangles, random.NextFloat);
            //Prim算法创建最小生成树
            List <GraphEdge> edges = GraphSearcher.PrimSearch(graph, triangles[0].v0);

            //每条边用A*算法生成路径
            int count = edges.Count;

            for (int i = 0; i < count; i++)
            {
                GraphEdge        edge = edges[i];
                Delaunay.DVertex v0   = vertices[edge.from];
                Delaunay.DVertex v1   = vertices[edge.to];
                int[]            path = GraphSearcher.AStarSearch(graph2, graph2.CoordToIndex(( int )v0.x, ( int )v0.y),
                                                                  graph2.CoordToIndex(( int )v1.x, ( int )v1.y));
                this.SetPathWalkable(path, walkablesHs);

                //把顶点扩展成房间
                if (i == 0)
                {
                    this.SetIndexToWalkable(graph2, ( int )v0.x, ( int )v0.y, random.Next(1, 3), random.Next(1, 3), walkablesHs);
                }
                this.SetIndexToWalkable(graph2, ( int )v1.x, ( int )v1.y, random.Next(1, 3), random.Next(1, 3), walkablesHs);
            }

            this.walkables = walkablesHs.ToArray();
        }
예제 #14
0
 public static Vector2 ToVector2(this FVec2 v)
 {
     return(new Vector2(( float )v.x, ( float )v.y));
 }